From 4d04cad02cd27e53cb18f431361a4d031836bb75 Mon Sep 17 00:00:00 2001 From: Andrea Terzolo Date: Wed, 30 Oct 2024 11:48:04 +0100 Subject: [PATCH] cleanup: improve perf `populate_cmdline` Signed-off-by: Andrea Terzolo --- userspace/libsinsp/threadinfo.cpp | 20 +++++++++++++++----- userspace/libsinsp/threadinfo.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/userspace/libsinsp/threadinfo.cpp b/userspace/libsinsp/threadinfo.cpp index 6109c7a3a6..fffea17439 100644 --- a/userspace/libsinsp/threadinfo.cpp +++ b/userspace/libsinsp/threadinfo.cpp @@ -605,6 +605,13 @@ void sinsp_threadinfo::set_args(const char* args, size_t len) { void sinsp_threadinfo::set_args(const std::vector& args) { m_args = args; + m_cmd_line = get_comm(); + if(!m_cmd_line.empty()) { + for(const auto& arg : m_args) { + m_cmd_line += " "; + m_cmd_line += arg; + } + } } void sinsp_threadinfo::set_env(const char* env, size_t len) { @@ -1078,11 +1085,14 @@ void sinsp_threadinfo::assign_children_to_reaper(sinsp_threadinfo* reaper) { } void sinsp_threadinfo::populate_cmdline(std::string& cmdline, const sinsp_threadinfo* tinfo) { - cmdline = tinfo->get_comm(); - - for(const auto& arg : tinfo->m_args) { - cmdline += " "; - cmdline += arg; + if(tinfo->m_cmd_line.empty()) { + cmdline = tinfo->get_comm(); + for(const auto& arg : tinfo->m_args) { + cmdline += " "; + cmdline += arg; + } + } else { + cmdline = tinfo->m_cmd_line; } } diff --git a/userspace/libsinsp/threadinfo.h b/userspace/libsinsp/threadinfo.h index 267ceb9ab4..b046238f5d 100644 --- a/userspace/libsinsp/threadinfo.h +++ b/userspace/libsinsp/threadinfo.h @@ -482,6 +482,7 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry { std::shared_ptr m_tginfo; std::list> m_children; uint64_t m_not_expired_children; + std::string m_cmd_line; bool m_filtered_out; ///< True if this thread is filtered out by the inspector filter from ///< saving to a capture