diff --git a/deps/oblib/src/lib/statistic_event/ob_stat_event.h b/deps/oblib/src/lib/statistic_event/ob_stat_event.h index 638cdd871e..e9ce879a40 100644 --- a/deps/oblib/src/lib/statistic_event/ob_stat_event.h +++ b/deps/oblib/src/lib/statistic_event/ob_stat_event.h @@ -147,11 +147,8 @@ STAT_EVENT_ADD_DEF(SQL_OPEN_CURSORS_CURRENT, "opened cursors current", ObStatCla STAT_EVENT_ADD_DEF(SQL_OPEN_CURSORS_CUMULATIVE, "opened cursors cumulative", ObStatClassIds::SQL, "opened cursors cumulative", 40031, true, true) STAT_EVENT_ADD_DEF(SQL_LOCAL_COUNT, "sql local count", ObStatClassIds::SQL, "sql local count", 40010, true, true) -//STAT_EVENT_ADD_DEF(SQL_LOCAL_TIME, "SQL_LOCAL_TIME", SQL, "SQL_LOCAL_TIME") STAT_EVENT_ADD_DEF(SQL_REMOTE_COUNT, "sql remote count", ObStatClassIds::SQL, "sql remote count", 40011, true, true) -//STAT_EVENT_ADD_DEF(SQL_REMOTE_TIME, "SQL_REMOTE_TIME", SQL, "SQL_REMOTE_TIME") STAT_EVENT_ADD_DEF(SQL_DISTRIBUTED_COUNT, "sql distributed count", ObStatClassIds::SQL, "sql distributed count", 40012, true, true) -//STAT_EVENT_ADD_DEF(SQL_DISTRIBUTED_TIME, "SQL_DISTRIBUTED_TIME", SQL, "SQL_DISTRIBUTED_TIME") STAT_EVENT_ADD_DEF(ACTIVE_SESSIONS, "active sessions", ObStatClassIds::SQL, "active sessions", 40013, false, true) STAT_EVENT_ADD_DEF(SQL_SINGLE_QUERY_COUNT, "single query count", ObStatClassIds::SQL, "single query count", 40014, true, true) STAT_EVENT_ADD_DEF(SQL_MULTI_QUERY_COUNT, "multiple query count", ObStatClassIds::SQL, "multiple query count", 40015, true, true) @@ -173,6 +170,10 @@ STAT_EVENT_ADD_DEF(SQL_USER_LOGONS_CUMULATIVE, "user logons cumulative", ObStatC STAT_EVENT_ADD_DEF(SQL_USER_LOGOUTS_CUMULATIVE, "user logouts cumulative", ObStatClassIds::SQL, "user logouts cumulative", 40113, true, true) STAT_EVENT_ADD_DEF(SQL_USER_LOGONS_FAILED_CUMULATIVE, "user logons failed cumulative", ObStatClassIds::SQL, "user logons failed cumulative", 40114, true, true) STAT_EVENT_ADD_DEF(SQL_USER_LOGONS_COST_TIME_CUMULATIVE, "user logons time cumulative", ObStatClassIds::SQL, "user logons time cumulative", 40115, true, true) +STAT_EVENT_ADD_DEF(SQL_LOCAL_TIME, "sql local execute time", ObStatClassIds::SQL, "sql local execute time", 40116, true, true) +STAT_EVENT_ADD_DEF(SQL_REMOTE_TIME, "sql remote execute time", ObStatClassIds::SQL, "sql remote execute time", 40117, true, true) +STAT_EVENT_ADD_DEF(SQL_DISTRIBUTED_TIME, "sql distributed execute time", ObStatClassIds::SQL, "sql distributed execute time", 40118, true, true) + // CACHE STAT_EVENT_ADD_DEF(ROW_CACHE_HIT, "row cache hit", ObStatClassIds::CACHE, "row cache hit", 50000, true, true) STAT_EVENT_ADD_DEF(ROW_CACHE_MISS, "row cache miss", ObStatClassIds::CACHE, "row cache miss", 50001, true, true) diff --git a/src/observer/mysql/obmp_query.cpp b/src/observer/mysql/obmp_query.cpp index bcb53684f7..6c0860fdb8 100644 --- a/src/observer/mysql/obmp_query.cpp +++ b/src/observer/mysql/obmp_query.cpp @@ -862,6 +862,11 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session, // even though sql audit disabled update_audit_info(total_wait_desc, audit_record); } + if (enable_perf_event && !THIS_THWORKER.need_retry() + && OB_NOT_NULL(result.get_physical_plan())) { + const int64_t time_cost = exec_end_timestamp_ - get_receive_timestamp(); + ObSQLUtils::record_execute_time(result.get_physical_plan()->get_plan_type(), time_cost); + } // 重试需要满足一下条件: // 1. rs.open 执行失败 // 2. 没有给客户端返回结果,本次执行没有副作用 diff --git a/src/observer/mysql/obmp_query.h b/src/observer/mysql/obmp_query.h index d914495506..8d7ff842d6 100644 --- a/src/observer/mysql/obmp_query.h +++ b/src/observer/mysql/obmp_query.h @@ -90,6 +90,7 @@ private: void record_stat(const sql::stmt::StmtType type, const int64_t end_time) const; + void record_execute_time(const sql::ObPhysicalPlan *plan, const int64_t end_time) const; void update_audit_info(const ObWaitEventStat &total_wait_desc, ObAuditRecordData &record); int fill_feedback_session_info(ObMySQLResultSet &result, diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index 1d36f3fe52..f0b14f556c 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -1190,6 +1190,11 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session, exec_end_timestamp_ = ObTimeUtility::current_time(); record_stat(result.get_stmt_type(), exec_end_timestamp_); } + if (enable_perf_event && !THIS_THWORKER.need_retry() + && OB_NOT_NULL(result.get_physical_plan())) { + const int64_t time_cost = exec_end_timestamp_ - get_receive_timestamp(); + ObSQLUtils::record_execute_time(result.get_physical_plan()->get_plan_type(), time_cost); + } if (enable_sql_audit) { audit_record.exec_record_.record_end(di); bool first_record = (1 == audit_record.try_cnt_); diff --git a/src/observer/mysql/obmp_stmt_execute.h b/src/observer/mysql/obmp_stmt_execute.h index e6cdbe8699..cb3bfecdb8 100644 --- a/src/observer/mysql/obmp_stmt_execute.h +++ b/src/observer/mysql/obmp_stmt_execute.h @@ -146,6 +146,7 @@ protected: sql::ObSqlCtx &get_ctx() { return ctx_; } ObQueryRetryCtrl &get_retry_ctrl() { return retry_ctrl_; } void record_stat(const sql::stmt::StmtType type, const int64_t end_time) const; + void record_execute_time(const sql::ObPhysicalPlan *plan, const int64_t end_time) const; int request_params(sql::ObSQLSessionInfo *session, const char* &pos, uint32_t ps_stmt_checksum, diff --git a/src/observer/ob_inner_sql_connection.cpp b/src/observer/ob_inner_sql_connection.cpp index 08c18a28a0..884729a899 100644 --- a/src/observer/ob_inner_sql_connection.cpp +++ b/src/observer/ob_inner_sql_connection.cpp @@ -584,6 +584,10 @@ int ObInnerSQLConnection::process_record(sql::ObResultSet &result_set, } record_stat(session, result_set.get_stmt_type(), is_from_pl); + if (lib::is_diagnose_info_enabled() && OB_NOT_NULL(result_set.get_physical_plan())) { + const int64_t time_cost = ObTimeUtility::current_time() - session.get_query_start_time(); + ObSQLUtils::record_execute_time(result_set.get_physical_plan()->get_plan_type(), time_cost); + } ObSQLUtils::handle_audit_record(false, sql::PSCursor == exec_timestamp.exec_type_ ? EXECUTE_PS_EXECUTE : (is_from_pl ? EXECUTE_PL_EXECUTE : EXECUTE_INNER), diff --git a/src/observer/ob_inner_sql_connection.h b/src/observer/ob_inner_sql_connection.h index 307f1d30c4..bf3714cac1 100644 --- a/src/observer/ob_inner_sql_connection.h +++ b/src/observer/ob_inner_sql_connection.h @@ -309,6 +309,9 @@ public: const bool is_oracle_mode, const bool is_ddl); + static void record_execute_time(sql::ObSQLSessionInfo& session, + const sql::ObPhysicalPlan *plan); + int64_t get_init_timestamp() const { return init_timestamp_; } public: diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index c2522186fa..ae91382f2e 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -3966,6 +3966,23 @@ int64_t ObSqlFatalErrExtraInfoGuard::to_string(char *buf, const int64_t buf_len) return pos; } +void ObSQLUtils::record_execute_time(const ObPhyPlanType type, + const int64_t time_cost) +{ + #define ADD_EXECUTE_TIME(type) \ + case OB_PHY_PLAN_##type: \ + EVENT_ADD(SQL_##type##_TIME, time_cost); \ + break + switch(type) + { + ADD_EXECUTE_TIME(LOCAL); + ADD_EXECUTE_TIME(REMOTE); + ADD_EXECUTE_TIME(DISTRIBUTED); + default: {} + } + #undef ADD_EXECUTE_TIME +} + int ObSQLUtils::handle_audit_record(bool need_retry, const ObExecuteMode exec_mode, ObSQLSessionInfo &session, diff --git a/src/sql/ob_sql_utils.h b/src/sql/ob_sql_utils.h index 0616f79a08..d976658388 100644 --- a/src/sql/ob_sql_utils.h +++ b/src/sql/ob_sql_utils.h @@ -495,6 +495,8 @@ public: common::ObCollationType connection_collation, const share::schema::ObViewSchema &view_schema, common::ObString &view_definition); + static void record_execute_time(const ObPhyPlanType type, + const int64_t time_cost); static int handle_audit_record(bool need_retry, const ObExecuteMode exec_mode, ObSQLSessionInfo &session,