fix cpu time issues
This commit is contained in:
parent
420c5641ba
commit
872c05073f
4
deps/oblib/src/lib/thread/thread.cpp
vendored
4
deps/oblib/src/lib/thread/thread.cpp
vendored
@ -157,9 +157,9 @@ void Thread::run()
|
||||
{
|
||||
IRunWrapper *run_wrapper_ = threads_->get_run_wrapper();
|
||||
if (OB_NOT_NULL(run_wrapper_)) {
|
||||
run_wrapper_->pre_run(this);
|
||||
run_wrapper_->pre_run();
|
||||
threads_->run(idx_);
|
||||
run_wrapper_->end_run(this);
|
||||
run_wrapper_->end_run();
|
||||
} else {
|
||||
threads_->run(idx_);
|
||||
}
|
||||
|
4
deps/oblib/src/lib/thread/thread.h
vendored
4
deps/oblib/src/lib/thread/thread.h
vendored
@ -28,12 +28,12 @@ class IRunWrapper
|
||||
{
|
||||
public:
|
||||
virtual ~IRunWrapper() {}
|
||||
virtual int pre_run(Thread*)
|
||||
virtual int pre_run()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
virtual int end_run(Thread*)
|
||||
virtual int end_run()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
return ret;
|
||||
|
@ -233,10 +233,14 @@ int ObAllVirtualSysStat::update_all_stats_(const int64_t tenant_id, ObStatEventS
|
||||
stat_events.get(ObStatEventIds::OBSERVER_PARTITION_TABLE_UPATER_CORE_QUEUE_SIZE - ObStatEventIds::STAT_EVENT_ADD_END -1)->stat_value_
|
||||
= 0;
|
||||
}
|
||||
|
||||
int64_t cpu_time = 0;
|
||||
GCTX.omt_->get_tenant_cpu_time(tenant_id, cpu_time);
|
||||
stat_events.get(ObStatEventIds::CPU_TIME - ObStatEventIds::STAT_EVENT_ADD_END -1)->stat_value_
|
||||
= cpu_time;
|
||||
if (OB_SUCC(GCTX.omt_->get_tenant_cpu_time(tenant_id, cpu_time))) {
|
||||
stat_events.get(ObStatEventIds::CPU_TIME - ObStatEventIds::STAT_EVENT_ADD_END - 1)->stat_value_
|
||||
= cpu_time;
|
||||
} else {
|
||||
// it is ok to not have any records
|
||||
}
|
||||
ret = ret_bk;
|
||||
}
|
||||
return ret;
|
||||
|
@ -242,6 +242,7 @@ void ObTenantBase::destroy()
|
||||
}
|
||||
tg_set_.destroy();
|
||||
thread_dynamic_factor_map_.destroy();
|
||||
OB_ASSERT(thread_list_.get_size() == 0);
|
||||
inited_ = false;
|
||||
}
|
||||
|
||||
@ -290,7 +291,7 @@ ObCgroupCtrl *ObTenantBase::get_cgroup()
|
||||
return cgroup_ctrl;
|
||||
}
|
||||
|
||||
int ObTenantBase::pre_run(lib::Thread* thread)
|
||||
int ObTenantBase::pre_run()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObTenantEnv::set_tenant(this);
|
||||
@ -299,22 +300,19 @@ int ObTenantBase::pre_run(lib::Thread* thread)
|
||||
ret = cgroup_ctrl->add_self_to_cgroup(id_);
|
||||
}
|
||||
{
|
||||
ThreadListNode *node = thread->get_thread_list_node();
|
||||
ThreadListNode *node = lib::Thread::current().get_thread_list_node();
|
||||
lib::ObMutexGuard guard(thread_list_lock_);
|
||||
if (OB_ISNULL(node)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_ERROR("Fail to allocate memory", K(ret));
|
||||
} else if (!thread_list_.add_last(node)) {
|
||||
if (!thread_list_.add_last(node)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("add to thread list fail", K(ret));
|
||||
}
|
||||
}
|
||||
ATOMIC_INC(&thread_count_);
|
||||
LOG_INFO("tenant thread pre_run", K(MTL_ID()), K(ret), K(thread_count_), KP(thread));
|
||||
LOG_INFO("tenant thread pre_run", K(MTL_ID()), K(ret), K(thread_count_));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObTenantBase::end_run(lib::Thread* thread)
|
||||
int ObTenantBase::end_run()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObTenantEnv::set_tenant(nullptr);
|
||||
@ -323,7 +321,7 @@ int ObTenantBase::end_run(lib::Thread* thread)
|
||||
ret = cgroup_ctrl->remove_self_from_cgroup(id_);
|
||||
}
|
||||
{
|
||||
ThreadListNode *node = (ThreadListNode *) thread->get_thread_list_node();
|
||||
ThreadListNode *node = lib::Thread::current().get_thread_list_node();
|
||||
lib::ObMutexGuard guard(thread_list_lock_);
|
||||
thread_list_.remove(node);
|
||||
}
|
||||
|
@ -403,8 +403,8 @@ template<class T> struct Identity {};
|
||||
|
||||
public:
|
||||
// TGHelper need
|
||||
virtual int pre_run(lib::Thread*) override;
|
||||
virtual int end_run(lib::Thread*) override;
|
||||
virtual int pre_run() override;
|
||||
virtual int end_run() override;
|
||||
virtual void tg_create_cb(int tg_id) override;
|
||||
virtual void tg_destroy_cb(int tg_id) override;
|
||||
|
||||
|
@ -668,17 +668,20 @@ int ObCgroupCtrl::get_cpu_usage(const uint64_t tenant_id, int32_t &cpu_usage)
|
||||
int ObCgroupCtrl::get_cpu_time(const uint64_t tenant_id, int64_t &cpu_time)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
char usage_path[PATH_BUFSIZE];
|
||||
char usage_value[VALUE_BUFSIZE + 1];
|
||||
snprintf(usage_path, PATH_BUFSIZE, "%s/tenant_%04lu/cpuacct.usage", root_cgroup_, tenant_id);
|
||||
MEMSET(usage_value, 0, VALUE_BUFSIZE);
|
||||
if(OB_FAIL(get_string_from_file_(usage_path, usage_value))) {
|
||||
LOG_WARN("get cpu usage failed",
|
||||
K(ret), K(usage_path), K(usage_value), K(tenant_id));
|
||||
char tenant_path[PATH_BUFSIZE];
|
||||
if (OB_FAIL(get_group_path(tenant_path, PATH_BUFSIZE, tenant_id))) {
|
||||
LOG_WARN("fail get group path", K(tenant_id), K(ret));
|
||||
} else {
|
||||
usage_value[VALUE_BUFSIZE] = '\0';
|
||||
cpu_time = std::stoull(usage_value) / 1000;
|
||||
char usage_path[PATH_BUFSIZE];
|
||||
char usage_value[VALUE_BUFSIZE + 1];
|
||||
snprintf(usage_path, PATH_BUFSIZE, "%s/cpuacct.usage", tenant_path);
|
||||
if(OB_FAIL(get_string_from_file_(usage_path, usage_value))) {
|
||||
LOG_WARN("get cpu usage failed",
|
||||
K(ret), K(usage_path), K(usage_value), K(tenant_id));
|
||||
} else {
|
||||
usage_value[VALUE_BUFSIZE] = '\0';
|
||||
cpu_time = std::stoull(usage_value) / 1000;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user