Skip to content

Commit

Permalink
Make name_changed an event property
Browse files Browse the repository at this point in the history
Whether the name changed or not is an event property and set at the end
of sinsp_parser::process_event(). It does this by checking the original
fd name and comparing it to the fd name that exists after parsing the
event.
  • Loading branch information
mstemm committed Feb 2, 2018
1 parent 58f4795 commit 6bb8ce6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions userspace/libsinsp/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ class SINSP_PUBLIC sinsp_evt
return m_fdinfo;
}

inline bool fdinfo_name_changed()
{
return m_fdinfo_name_changed;
}

inline void set_fdinfo_name_changed(bool changed)
{
m_fdinfo_name_changed = changed;
}

/*!
\brief Return the number of the FD associated with this event.
Expand Down Expand Up @@ -333,6 +343,7 @@ class SINSP_PUBLIC sinsp_evt
m_info = &(m_event_info_table[m_pevt->type]);
m_tinfo = NULL;
m_fdinfo = NULL;
m_fdinfo_name_changed = false;
m_iosize = 0;
m_poriginal_evt = NULL;
}
Expand All @@ -343,6 +354,7 @@ class SINSP_PUBLIC sinsp_evt
m_info = &(m_event_info_table[m_pevt->type]);
m_tinfo = NULL;
m_fdinfo = NULL;
m_fdinfo_name_changed = false;
m_iosize = 0;
m_cpuid = cpuid;
m_evtnum = 0;
Expand Down Expand Up @@ -396,6 +408,11 @@ VISIBILITY_PRIVATE

sinsp_threadinfo* m_tinfo;
sinsp_fdinfo_t* m_fdinfo;

// If true, then the associated fdinfo changed names as a part
// of parsing this event.
bool m_fdinfo_name_changed;

uint32_t m_iosize;
int32_t m_errorcode;
int32_t m_rawbuf_str_len;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/filterchecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ uint8_t* sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT uint32_t* len, bool
return NULL;
}

m_tbool = m_fdinfo->m_name != m_fdinfo->m_oldname;
m_tbool = evt->fdinfo_name_changed();

RETURN_EXTRACT_VAR(m_tbool);
}
Expand Down
8 changes: 8 additions & 0 deletions userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ void sinsp_parser::process_event(sinsp_evt *evt)
evt->m_filtered_out = true;
}
}

// Check to see if the name changed as a side-effect of
// parsing this event. Try to avoid the overhead of a string
// compare for every event.
if(evt->m_fdinfo)
{
evt->set_fdinfo_name_changed(evt->m_fdinfo->m_name != evt->m_fdinfo->m_oldname);
}
}

void sinsp_parser::event_cleanup(sinsp_evt *evt)
Expand Down

0 comments on commit 6bb8ce6

Please sign in to comment.