Skip to content

Commit

Permalink
update(gvisor): implement get_stats for gVisor
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
  • Loading branch information
loresuso committed Jul 7, 2022
1 parent db16140 commit 78fc499
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion userspace/libscap/engine/gvisor/gvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int32_t gvisor_configure(struct scap_engine_handle engine, enum scap_sett

static int32_t gvisor_get_stats(struct scap_engine_handle engine, scap_stats* stats)
{
return SCAP_SUCCESS;
return engine.m_handle->get_stats(stats);
}

static int32_t gvisor_get_n_tracepoint_hit(struct scap_engine_handle engine, long* ret)
Expand Down
13 changes: 13 additions & 0 deletions userspace/libscap/engine/gvisor/gvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct parse_result {
size_t size;
// pointers to each encoded event within the supplied output buffer
std::vector<scap_evt*> scap_events;
// number of events dropped by gVisor
uint32_t dropped_count;
};

struct procfs_result {
Expand Down Expand Up @@ -140,6 +142,7 @@ class engine {
uint32_t get_threadinfos(uint64_t *n, const scap_threadinfo **tinfos);
uint32_t get_fdinfos(const scap_threadinfo *tinfo, uint64_t *n, const scap_fdinfo **fdinfos);
uint32_t get_vxid(uint64_t pid);
int32_t get_stats(scap_stats *stats);
private:
int32_t process_message_from_fd(int fd);
void free_sandbox_buffers();
Expand Down Expand Up @@ -168,6 +171,16 @@ class engine {
std::string m_root_path;
std::string m_trace_session_path;

struct gvisor_stats
{
// total number of events received from gVisor
uint64_t n_evts;
// total number of drops due to parsig errors
uint64_t n_drops_parsing;
// total number of drops on gVisor side
uint64_t n_drops_gvisor;
} m_gvisor_stats;

};

} // namespace scap_gvisor
2 changes: 2 additions & 0 deletions userspace/libscap/engine/gvisor/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,8 @@ parse_result parse_gvisor_proto(scap_const_sized_buffer gvisor_buf, scap_sized_b
return ret;
}

// dropped count is the absolute number of events dropped from gVisor side
ret.dropped_count = hdr->dropped_count;
const char *proto = &buf[hdr->header_size];
ssize_t proto_size = gvisor_buf.size - hdr->header_size;

Expand Down
17 changes: 17 additions & 0 deletions userspace/libscap/engine/gvisor/scap_gvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ int32_t sandbox_entry::expand_buffer(size_t size)
engine::engine(char *lasterr)
{
m_lasterr = lasterr;
m_gvisor_stats.n_evts = 0;
m_gvisor_stats.n_drops_parsing = 0;
m_gvisor_stats.n_drops_gvisor = 0;
}

engine::~engine()
Expand Down Expand Up @@ -411,6 +414,15 @@ uint32_t engine::get_vxid(uint64_t xid)
return parsers::get_vxid(xid);
}

int32_t engine::get_stats(scap_stats *stats)
{
stats->n_drops = m_gvisor_stats.n_drops_parsing + m_gvisor_stats.n_drops_gvisor;
stats->n_drops_bug = m_gvisor_stats.n_drops_parsing;
stats->n_drops_buffer = m_gvisor_stats.n_drops_gvisor;
stats->n_evts = m_gvisor_stats.n_evts;
return SCAP_SUCCESS;
}

// Reads one gvisor message from the specified fd, stores the resulting events overwriting m_buffers and adds pointers to m_event_queue.
// Returns:
// * SCAP_SUCCESS in case of success
Expand Down Expand Up @@ -461,6 +473,8 @@ int32_t engine::process_message_from_fd(int fd)
return SCAP_ILLEGAL_INPUT;
}

m_gvisor_stats.n_drops_gvisor = parse_result.dropped_count;

for(scap_evt *evt : parse_result.scap_events)
{
m_event_queue.push_back(evt);
Expand All @@ -479,6 +493,7 @@ int32_t engine::next(scap_evt **pevent, uint16_t *pcpuid)
{
*pevent = m_event_queue.front();
m_event_queue.pop_front();
m_gvisor_stats.n_evts++;
return SCAP_SUCCESS;
}

Expand Down Expand Up @@ -526,6 +541,7 @@ int32_t engine::next(scap_evt **pevent, uint16_t *pcpuid)

// ignore parsing errors, we will simply discard the message
if (status == SCAP_ILLEGAL_INPUT) {
m_gvisor_stats.n_drops_parsing++;
continue;
}
}
Expand All @@ -552,6 +568,7 @@ int32_t engine::next(scap_evt **pevent, uint16_t *pcpuid)
{
*pevent = m_event_queue.front();
m_event_queue.pop_front();
m_gvisor_stats.n_evts++;
return SCAP_SUCCESS;
}

Expand Down

0 comments on commit 78fc499

Please sign in to comment.