sql_monitor change time expression from cpu_cycle to time_us

This commit is contained in:
obdev 2023-04-04 03:11:24 +00:00 committed by ob-robot
parent ba4460ca3f
commit 4708d356a7
5 changed files with 97 additions and 7 deletions

View File

@ -154,6 +154,7 @@ ObServer::ObServer()
bandwidth_throttle_(),
sys_bkgd_net_percentage_(0),
ethernet_speed_(0),
cpu_frequency_(DEFAULT_CPU_FREQUENCY),
session_mgr_(),
root_service_monitor_(root_service_, rs_mgr_),
ob_service_(gctx_),
@ -171,6 +172,7 @@ ObServer::ObServer()
ctas_clean_up_task_(),
refresh_active_time_task_(),
refresh_network_speed_task_(),
refresh_cpu_frequency_task_(),
schema_status_proxy_(sql_proxy_),
is_log_dir_empty_(false),
conn_res_mgr_(),
@ -373,6 +375,8 @@ int ObServer::init(const ObServerOptions &opts, const ObPLogWriterCfg &log_cfg)
LOG_ERROR("init refresh active time task failed", KR(ret));
} else if (OB_FAIL(init_refresh_network_speed_task())) {
LOG_ERROR("init refresh network speed task failed", KR(ret));
} else if (OB_FAIL(init_refresh_cpu_frequency())) {
LOG_ERROR("init refresh cpu frequency failed", KR(ret));
} else if (OB_FAIL(init_collect_info_gc_task())) {
LOG_ERROR("init collect info gc task failed", KR(ret));
} else if (OB_FAIL(ObOptStatManager::get_instance().init(
@ -2787,6 +2791,63 @@ void ObServer::ObRefreshNetworkSpeedTask::runTimerTask()
}
}
ObServer::ObRefreshCpuFreqTimeTask::ObRefreshCpuFreqTimeTask()
: obs_(nullptr), is_inited_(false)
{}
int ObServer::ObRefreshCpuFreqTimeTask::init(ObServer *obs, int tg_id)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_ERROR("ObRefreshCpuFreqTimeTask has already been inited", KR(ret));
} else if (OB_ISNULL(obs)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("ObRefreshCpuFreqTimeTask init with null ptr", KR(ret), K(obs));
} else {
obs_ = obs;
is_inited_ = true;
if (OB_FAIL(TG_SCHEDULE(tg_id, *this, REFRESH_INTERVAL, true /*schedule repeatly*/))) {
LOG_ERROR("fail to schedule task ObRefreshCpuFreqTimeTask", KR(ret));
}
}
return ret;
}
void ObServer::ObRefreshCpuFreqTimeTask::destroy()
{
is_inited_ = false;
obs_ = nullptr;
}
void ObServer::ObRefreshCpuFreqTimeTask::runTimerTask()
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(!is_inited_)) {
ret = OB_NOT_INIT;
LOG_ERROR("ObRefreshCpuFreqTimeTask has not been inited", KR(ret));
} else if (OB_ISNULL(obs_)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("ObRefreshCpuFreqTimeTask task got null ptr", KR(ret));
} else if (OB_FAIL(obs_->refresh_cpu_frequency())) {
LOG_ERROR("ObRefreshCpuFreqTimeTask task failed", KR(ret));
}
}
int ObServer::refresh_cpu_frequency()
{
int ret = OB_SUCCESS;
uint64_t cpu_frequency = get_cpufreq_khz();
cpu_frequency = cpu_frequency < 1 ? 1 : cpu_frequency;
if (cpu_frequency != cpu_frequency_) {
LOG_INFO("Cpu frequency changed", "from", cpu_frequency_, "to", cpu_frequency);
cpu_frequency_ = cpu_frequency;
}
return ret;
}
void ObServer::ObCollectInfoGCTask::runTimerTask()
{
int ret = OB_SUCCESS;
@ -2867,6 +2928,15 @@ int ObServer::init_refresh_network_speed_task()
return ret;
}
int ObServer::init_refresh_cpu_frequency()
{
int ret = OB_SUCCESS;
if (OB_FAIL(refresh_cpu_frequency_task_.init(this, lib::TGDefIDs::ServerGTimer))) {
LOG_ERROR("fail to init refresh cpu frequency task", KR(ret));
}
return ret;
}
int ObServer::init_collect_info_gc_task()
{
int ret = OB_SUCCESS;

View File

@ -99,6 +99,7 @@ class ObServer
public:
static const int64_t DEFAULT_ETHERNET_SPEED = 1000 / 8 * 1024 * 1024; // default 125m/s 1000Mbit
static const int64_t DISK_USAGE_REPORT_INTERVAL = 1000L * 1000L * 10L; // 60s
static const uint64_t DEFAULT_CPU_FREQUENCY = 2500 * 1000; // 2500 * 1000 khz
static ObServer &get_instance();
public:
@ -158,6 +159,20 @@ public:
bool is_inited_;
};
class ObRefreshCpuFreqTimeTask: public common::ObTimerTask
{
public:
ObRefreshCpuFreqTimeTask();
virtual ~ObRefreshCpuFreqTimeTask() {}
int init(ObServer *observer, int tg_id);
void destroy();
virtual void runTimerTask() override;
private:
const static int64_t REFRESH_INTERVAL = 10 * 1000L * 1000L;//10s
ObServer *obs_;
bool is_inited_;
};
class ObCollectInfoGCTask : public common::ObTimerTask
{
public:
@ -208,6 +223,7 @@ public:
};
share::schema::ObMultiVersionSchemaService &get_schema_service() { return schema_service_; }
ObInOutBandwidthThrottle &get_bandwidth_throttle() { return bandwidth_throttle_; }
uint64_t get_cpu_frequency_khz() { return cpu_frequency_; }
const common::ObAddr &get_self() const { return self_addr_; }
const ObGlobalContext &get_gctx() const { return gctx_; }
ObGlobalContext &get_gctx() { return gctx_; }
@ -267,6 +283,7 @@ private:
int get_network_speed_from_sysfs(int64_t &network_speed);
int get_network_speed_from_config_file(int64_t &network_speed);
int refresh_network_speed();
int refresh_cpu_frequency();
int clean_up_invalid_tables();
int clean_up_invalid_tables_by_tenant(const uint64_t tenant_id);
int init_ctas_clean_up_task(); //Regularly clean up the residuals related to querying and building tables and temporary tables
@ -275,6 +292,7 @@ private:
int refresh_temp_table_sess_active_time();
int init_refresh_active_time_task(); //Regularly update the sess_active_time of the temporary table created by the proxy connection sess
int init_refresh_network_speed_task();
int init_refresh_cpu_frequency();
int init_collect_info_gc_task();
int set_running_mode();
int check_server_can_start_service();
@ -366,6 +384,7 @@ private:
common::ObInOutBandwidthThrottle bandwidth_throttle_;
int64_t sys_bkgd_net_percentage_;
int64_t ethernet_speed_;
uint64_t cpu_frequency_;
// sql session_mgr
sql::ObSQLSessionMgr session_mgr_;
@ -414,6 +433,7 @@ private:
ObRedefTableHeartBeatTask redef_table_heart_beat_task_;
ObRefreshTimeTask refresh_active_time_task_; // repeat & no retry
ObRefreshNetworkSpeedTask refresh_network_speed_task_; // repeat & no retry
ObRefreshCpuFreqTimeTask refresh_cpu_frequency_task_;
ObCollectInfoGCTask collect_info_gc_task_;
blocksstable::ObStorageEnv storage_env_;
share::ObSchemaStatusProxy schema_status_proxy_;

View File

@ -18,6 +18,7 @@
#include "sql/engine/ob_exec_context.h"
#include "common/ob_smart_call.h"
#include "sql/monitor/ob_sql_plan_manager.h"
#include "observer/ob_server.h"
namespace oceanbase
{
@ -937,7 +938,10 @@ int ObOperator::submit_op_monitor_node()
}
}
// exclude io time cost
op_monitor_info_.db_time_ = db_time;
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
op_monitor_info_.db_time_ = 1000 * db_time / cpu_khz;
op_monitor_info_.block_time_ = 1000 * op_monitor_info_.block_time_ / cpu_khz;
IGNORE_RETURN list->submit_node(op_monitor_info_);
LOG_DEBUG("debug monitor", K(spec_.id_));
}

View File

@ -575,7 +575,6 @@ int ObPxTransmitOp::send_rows_one_by_one(ObSliceIdxCalc &slice_calc)
} else if (OB_FAIL(send_eof_row())) { // overwrite err code
LOG_WARN("fail send eof rows to channels", K(ret));
}
op_monitor_info_.db_time_ += (rdtsc() - begin_cpu_time);
break;
}
}
@ -604,7 +603,6 @@ int ObPxTransmitOp::send_rows_one_by_one(ObSliceIdxCalc &slice_calc)
}
}
}
op_monitor_info_.db_time_ += (rdtsc() - begin_cpu_time);
}
if (OB_ITER_END == ret) {
ret = OB_SUCCESS;
@ -721,11 +719,9 @@ int ObPxTransmitOp::send_rows_in_batch(ObSliceIdxCalc &slice_calc)
} else if (OB_FAIL(send_eof_row())) {
LOG_WARN("fail send eof rows to channels", K(ret));
}
op_monitor_info_.db_time_ += (rdtsc() - begin_cpu_time);
break;
}
// for those break out ops
op_monitor_info_.db_time_ += (rdtsc() - begin_cpu_time);
}
LOG_TRACE("Transmit time record", K(row_count), K(ret));
return ret;

View File

@ -14,6 +14,7 @@
#include "lib/ob_running_mode.h"
#include "util/easy_time.h"
#include "lib/rc/ob_rc.h"
#include "observer/ob_server.h"
namespace oceanbase
{
@ -132,8 +133,7 @@ int ObPlanRealInfoMgr::handle_plan_info(int64_t id,
SERVER_LOG(WARN, "alloc mem failed", K(total_size), K(ret));
}
} else {
uint64_t cpu_khz = get_cpufreq_khz();
cpu_khz = cpu_khz < 1 ? 1 : cpu_khz;
uint64_t cpu_khz = OBSERVER.get_cpu_frequency_khz();
int64_t row_count = plan_info.output_row_count_;
int64_t cpu_time = plan_info.db_time_*1000 / cpu_khz;
int64_t io_time = plan_info.block_time_*1000 / cpu_khz;