Skip to content

Commit 4d04cad

Browse files
Andreagit97poiana
authored andcommitted
cleanup: improve perf populate_cmdline
Signed-off-by: Andrea Terzolo <[email protected]>
1 parent 15e24ae commit 4d04cad

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

userspace/libsinsp/threadinfo.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,13 @@ void sinsp_threadinfo::set_args(const char* args, size_t len) {
605605

606606
void sinsp_threadinfo::set_args(const std::vector<std::string>& args) {
607607
m_args = args;
608+
m_cmd_line = get_comm();
609+
if(!m_cmd_line.empty()) {
610+
for(const auto& arg : m_args) {
611+
m_cmd_line += " ";
612+
m_cmd_line += arg;
613+
}
614+
}
608615
}
609616

610617
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) {
10781085
}
10791086

10801087
void sinsp_threadinfo::populate_cmdline(std::string& cmdline, const sinsp_threadinfo* tinfo) {
1081-
cmdline = tinfo->get_comm();
1082-
1083-
for(const auto& arg : tinfo->m_args) {
1084-
cmdline += " ";
1085-
cmdline += arg;
1088+
if(tinfo->m_cmd_line.empty()) {
1089+
cmdline = tinfo->get_comm();
1090+
for(const auto& arg : tinfo->m_args) {
1091+
cmdline += " ";
1092+
cmdline += arg;
1093+
}
1094+
} else {
1095+
cmdline = tinfo->m_cmd_line;
10861096
}
10871097
}
10881098

userspace/libsinsp/threadinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
482482
std::shared_ptr<thread_group_info> m_tginfo;
483483
std::list<std::weak_ptr<sinsp_threadinfo>> m_children;
484484
uint64_t m_not_expired_children;
485+
std::string m_cmd_line;
485486
bool m_filtered_out; ///< True if this thread is filtered out by the inspector filter from
486487
///< saving to a capture
487488

0 commit comments

Comments
 (0)