Skip to content

Commit

Permalink
Add function to log thread state loops (once)
Browse files Browse the repository at this point in the history
Add sinsp_threadinfo::note_parent_state_loop(), which logs that a loop
in parent state was found. It only does so once, though, using
m_parent_loop_detected to only log the first occurence.

The *logic* for detecting a loop is outside this function, though.
  • Loading branch information
mstemm committed Feb 13, 2017
1 parent 355a184 commit 42c5601
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void sinsp_threadinfo::init()
m_program_hash = 0;
m_program_hash_falco = 0;
m_lastevent_data = NULL;
m_parent_loop_detected = false;
}

sinsp_threadinfo::~sinsp_threadinfo()
Expand Down Expand Up @@ -767,6 +768,20 @@ uint64_t sinsp_threadinfo::get_fd_limit()
return get_main_thread()->m_fdlimit;
}

void sinsp_threadinfo::note_parent_state_loop()
{
// In debug mode, we trigger an assertion.
ASSERT(false);

// Note we only log a loop once for a given main thread, to avoid flooding logs.
if(!m_parent_loop_detected)
{
g_logger.log(string("Loop in parent thread state detected for pid ") +
std::to_string(m_pid), sinsp_logger::SEV_WARNING);
m_parent_loop_detected = true;
}
}

sinsp_threadinfo* sinsp_threadinfo::lookup_thread()
{
return m_inspector->get_thread(m_pid, true, true);
Expand Down
6 changes: 6 additions & 0 deletions userspace/libsinsp/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class SINSP_PUBLIC sinsp_threadinfo
*/
uint64_t get_fd_limit();

//
// Note that this thread has a loop in parent state, and possibly log the loop.
//
void note_parent_state_loop();

//
// Core state
//
Expand Down Expand Up @@ -325,6 +330,7 @@ VISIBILITY_PRIVATE
uint16_t m_lastevent_type;
uint16_t m_lastevent_cpuid;
sinsp_evt::category m_lastevent_category;
bool m_parent_loop_detected;

friend class sinsp;
friend class sinsp_parser;
Expand Down

0 comments on commit 42c5601

Please sign in to comment.