Skip to content

Commit aecb8af

Browse files
committed
cleanup(userspace/libsinsp): completely drop m_program_hash and m_program_hashscript fields from threadinfo.
They are unused and can be eventually directly implemented by consumers, if needed. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
1 parent 490e7f7 commit aecb8af

File tree

3 files changed

+2
-87
lines changed

3 files changed

+2
-87
lines changed

userspace/libsinsp/parsers.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,6 @@ void sinsp_parser::parse_execve_exit(sinsp_evt *evt) {
22332233
//
22342234
evt->get_tinfo()->m_flags |= PPM_CL_NAME_CHANGED;
22352235

2236-
//
2237-
// Recompute the program hash
2238-
//
2239-
evt->get_tinfo()->compute_program_hash();
2240-
22412236
//
22422237
// If there's a listener, add a callback to later invoke it.
22432238
//

userspace/libsinsp/threadinfo.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ libsinsp::state::static_struct::field_infos sinsp_threadinfo::static_fields() co
100100
define_static_field(ret, this, m_pgid, "pgid");
101101
define_static_field(ret, this, m_pidns_init_start_ts, "pidns_init_start_ts");
102102
define_static_field(ret, this, m_root, "root");
103-
// m_program_hash
104-
// m_program_hash_scripts
105103
define_static_field(ret, this, m_tty, "tty");
106104
// m_category
107105
// m_clone_ts
@@ -145,8 +143,6 @@ void sinsp_threadinfo::init() {
145143
m_lastevent_fd = 0;
146144
m_last_latency_entertime = 0;
147145
m_latency = 0;
148-
m_program_hash = 0;
149-
m_program_hash_scripts = 0;
150146
m_lastevent_data = NULL;
151147
m_parent_loop_detected = false;
152148
m_tty = 0;
@@ -203,57 +199,6 @@ void sinsp_threadinfo::fix_sockets_coming_from_proc() {
203199
});
204200
}
205201

206-
#define STR_AS_NUM_JAVA 0x6176616a
207-
#define STR_AS_NUM_RUBY 0x79627572
208-
#define STR_AS_NUM_PERL 0x6c726570
209-
#define STR_AS_NUM_NODE 0x65646f6e
210-
211-
#define MAX_PROG_HASH_LEN 1024
212-
213-
void sinsp_threadinfo::compute_program_hash() {
214-
auto curr_hash = std::hash<std::string>()(m_exe);
215-
hash_combine(curr_hash, m_container_id);
216-
auto rem_len = MAX_PROG_HASH_LEN - (m_exe.size() + m_container_id.size());
217-
218-
//
219-
// By default, the scripts hash is just exe+container
220-
//
221-
m_program_hash_scripts = curr_hash;
222-
223-
//
224-
// The program hash includes the arguments as well
225-
//
226-
for(auto arg = m_args.begin(); arg != m_args.end() && rem_len > 0; ++arg) {
227-
if(arg->size() >= rem_len) {
228-
auto partial_str = arg->substr(0, rem_len);
229-
hash_combine(curr_hash, partial_str);
230-
break;
231-
}
232-
233-
hash_combine(curr_hash, *arg);
234-
rem_len -= arg->size();
235-
}
236-
m_program_hash = curr_hash;
237-
238-
//
239-
// For some specific processes (essentially the scripting languages)
240-
// we include the arguments in the scripts hash as well
241-
//
242-
if(m_comm.size() == 4) {
243-
uint32_t ncomm;
244-
memcpy(&ncomm, m_comm.c_str(), 4);
245-
246-
if(ncomm == STR_AS_NUM_JAVA || ncomm == STR_AS_NUM_RUBY || ncomm == STR_AS_NUM_PERL ||
247-
ncomm == STR_AS_NUM_NODE) {
248-
m_program_hash_scripts = m_program_hash;
249-
}
250-
} else if(m_comm.size() >= 6) {
251-
if(m_comm.substr(0, 6) == "python") {
252-
m_program_hash_scripts = m_program_hash;
253-
}
254-
}
255-
}
256-
257202
void sinsp_threadinfo::add_fd_from_scap(scap_fdinfo* fdi) {
258203
auto newfdi = m_inspector->build_fdinfo();
259204
bool do_add = true;
@@ -1477,7 +1422,6 @@ const std::shared_ptr<sinsp_threadinfo>& sinsp_thread_manager::add_thread(
14771422
"adding entry with incompatible dynamic defs to of file descriptor sub-table");
14781423
}
14791424

1480-
tinfo_shared_ptr->compute_program_hash();
14811425
if(m_sinsp_stats_v2 != nullptr) {
14821426
m_sinsp_stats_v2->m_n_added_threads++;
14831427
}

userspace/libsinsp/threadinfo.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,8 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
434434
int64_t m_pgid; // Process group id, as seen from the host pid namespace
435435
uint64_t m_pidns_init_start_ts; ///< The pid_namespace init task (child_reaper) start_time ts.
436436
std::string m_root;
437-
size_t m_program_hash; ///< Unique hash of the current program
438-
size_t m_program_hash_scripts; ///< Unique hash of the current program, including arguments for
439-
///< scripting programs (like python or ruby)
440-
uint32_t m_tty; ///< Number of controlling terminal
437+
438+
uint32_t m_tty; ///< Number of controlling terminal
441439
std::shared_ptr<thread_group_info> m_tginfo;
442440
std::list<std::weak_ptr<sinsp_threadinfo>> m_children;
443441
uint64_t m_not_expired_children;
@@ -497,27 +495,6 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
497495
//
498496
sinsp* m_inspector;
499497

500-
struct hasher {
501-
size_t operator()(sinsp_threadinfo* tinfo) const {
502-
auto main_thread = tinfo->get_main_thread();
503-
if(main_thread == nullptr) {
504-
return 0;
505-
}
506-
return main_thread->m_program_hash;
507-
}
508-
};
509-
510-
struct comparer {
511-
size_t operator()(sinsp_threadinfo* lhs, sinsp_threadinfo* rhs) const {
512-
auto lhs_main_thread = lhs->get_main_thread();
513-
auto rhs_main_thread = rhs->get_main_thread();
514-
if(lhs_main_thread == nullptr || rhs_main_thread == nullptr) {
515-
return 0;
516-
}
517-
return lhs_main_thread->m_program_hash == rhs_main_thread->m_program_hash;
518-
}
519-
};
520-
521498
/* Note that `fd_table` should be shared with the main thread only if `PPM_CL_CLONE_FILES`
522499
* is specified. Today we always specify `PPM_CL_CLONE_FILES` for all threads.
523500
*/
@@ -556,7 +533,6 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
556533
m_lastevent_cpuid = (uint16_t)-1;
557534
}
558535
}
559-
void compute_program_hash();
560536

561537
inline const uint8_t* get_last_event_data() const { return m_lastevent_data; }
562538

0 commit comments

Comments
 (0)