Skip to content

Commit dfe6c71

Browse files
deepskyblue86poiana
authored andcommitted
perf(sinsp): sinsp_threadinfo::get_container_id
Have the container_id accessor as an attribute, avoiding sinsp_thread_manager::get_field_accessor at each call. Signed-off-by: Angelo Puglisi <[email protected]>
1 parent 1aed1a6 commit dfe6c71

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

userspace/libsinsp/threadinfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ sinsp_threadinfo::sinsp_threadinfo(const std::shared_ptr<ctor_params>& params):
4444
m_main_fdtable(m_fdtable.table_ptr()),
4545
m_args_table_adapter("args", m_args),
4646
m_env_table_adapter("env", m_env),
47-
m_cgroups_table_adapter("cgroups", m_cgroups) {
47+
m_cgroups_table_adapter("cgroups", m_cgroups),
48+
m_container_id_accessor(params->thread_manager->get_field_accessor(
49+
sinsp_thread_manager::s_container_id_field_name)) {
4850
init();
4951
}
5052

@@ -408,13 +410,11 @@ std::string sinsp_threadinfo::get_exepath() const {
408410
}
409411

410412
std::string sinsp_threadinfo::get_container_id() {
411-
std::string container_id;
412-
413-
const auto accessor = m_params->thread_manager->get_field_accessor(
414-
sinsp_thread_manager::s_container_id_field_name);
415-
if(accessor) {
416-
get_dynamic_field(*accessor, container_id);
413+
if(!m_container_id_accessor) {
414+
return {};
417415
}
416+
std::string container_id;
417+
get_dynamic_field(*m_container_id_accessor, container_id);
418418
return container_id;
419419
}
420420

userspace/libsinsp/threadinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
671671
decltype(m_cgroups),
672672
libsinsp::state::pair_table_entry_adapter<std::string, std::string>>
673673
m_cgroups_table_adapter;
674+
675+
const libsinsp::state::dynamic_struct::field_accessor<std::string>* m_container_id_accessor;
674676
};
675677

676678
/*@}*/

0 commit comments

Comments
 (0)