Skip to content

Commit

Permalink
fix(libsinsp): max proc lookup number logging
Browse files Browse the repository at this point in the history
m_n_proc_lookups was incremented before doing the proc lookup, causing
<Reached max process lookup number, duration=0ms> logs when max is
configured to 1.

Signed-off-by: Angelo Puglisi <[email protected]>
  • Loading branch information
deepskyblue86 authored and poiana committed Nov 19, 2024
1 parent facfcc3 commit 512f9b7
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,30 +1963,14 @@ const threadinfo_map_t::ptr_t& sinsp_thread_manager::get_thread_ref(int64_t tid,
// unfortunately, sinsp owns the threade factory
auto newti = m_inspector->build_threadinfo();

m_n_proc_lookups++;

if(main_thread) {
m_n_main_thread_lookups++;
}

if(m_n_proc_lookups == m_max_n_proc_lookups) {
libsinsp_logger()->format(sinsp_logger::SEV_INFO,
"Reached max process lookup number, duration=%" PRIu64 "ms",
m_n_proc_lookups_duration_ns / 1000000);
}

if(m_max_n_proc_lookups < 0 || m_n_proc_lookups <= m_max_n_proc_lookups) {
if(m_max_n_proc_lookups < 0 || m_n_proc_lookups < m_max_n_proc_lookups) {
bool scan_sockets = false;

if(m_max_n_proc_socket_lookups < 0 || m_n_proc_lookups <= m_max_n_proc_socket_lookups) {
if(m_max_n_proc_socket_lookups < 0 || m_n_proc_lookups < m_max_n_proc_socket_lookups) {
scan_sockets = true;
if(m_n_proc_lookups == m_max_n_proc_socket_lookups) {
libsinsp_logger()->format(sinsp_logger::SEV_INFO,
"Reached max socket lookup number, tid=%" PRIu64
", duration=%" PRIu64 "ms",
tid,
m_n_proc_lookups_duration_ns / 1000000);
}
}

uint64_t ts = sinsp_utils::get_current_time_ns();
Expand All @@ -1995,6 +1979,22 @@ const threadinfo_map_t::ptr_t& sinsp_thread_manager::get_thread_ref(int64_t tid,
have_scap_proc = true;
}
m_n_proc_lookups_duration_ns += sinsp_utils::get_current_time_ns() - ts;

m_n_proc_lookups++;

if(m_n_proc_lookups == m_max_n_proc_lookups) {
libsinsp_logger()->format(sinsp_logger::SEV_INFO,
"Reached max process lookup number, duration=%" PRIu64
"ms",
m_n_proc_lookups_duration_ns / 1000000);
}
if(scan_sockets && m_n_proc_lookups == m_max_n_proc_socket_lookups) {
libsinsp_logger()->format(sinsp_logger::SEV_INFO,
"Reached max socket lookup number, tid=%" PRIu64
", duration=%" PRIu64 "ms",
tid,
m_n_proc_lookups_duration_ns / 1000000);
}
}

if(have_scap_proc) {
Expand Down

0 comments on commit 512f9b7

Please sign in to comment.