Skip to content

Commit

Permalink
cxl: add a helper to go through all current events and parse them
Browse files Browse the repository at this point in the history
Add a common function to iterate through and extract the events in the
current trace buffer. The function uses tracefs_iterate_raw_events() from
libtracefs to go through all the events loaded into a tep_handle. A
callback is provided to the API call in order to parse the event. For cxl
monitor, the "system" or category of trace event, in this case "cxl",
is provided in order to filter for the CXL events.

Tested-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/166803885992.145141.11751557821515668416.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
  • Loading branch information
davejiang authored and stellarhopper committed Feb 3, 2023
1 parent 8dedc6c commit 7b237bc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cxl/event_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ccan/list/list.h>
#include <uuid/uuid.h>
#include <traceevent/event-parse.h>
#include <tracefs/tracefs.h>
#include "event_trace.h"

#define _GNU_SOURCE
Expand Down Expand Up @@ -191,3 +192,39 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record,
free(jnode);
return rc;
}

static int cxl_event_parse(struct tep_event *event, struct tep_record *record,
int cpu, void *ctx)
{
struct event_ctx *event_ctx = (struct event_ctx *)ctx;

/* Filter out all the events that the caller isn't interested in. */
if (strcmp(event->system, event_ctx->system) != 0)
return 0;

if (event_ctx->event_name) {
if (strcmp(event->name, event_ctx->event_name) != 0)
return 0;
}

if (event_ctx->parse_event)
return event_ctx->parse_event(event, record,
&event_ctx->jlist_head);

return cxl_event_to_json(event, record, &event_ctx->jlist_head);
}

int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx)
{
struct tep_handle *tep;
int rc;

tep = tracefs_local_events(NULL);
if (!tep)
return -ENOMEM;

rc = tracefs_iterate_raw_events(tep, inst, NULL, 0, cxl_event_parse,
ectx);
tep_free(tep);
return rc;
}
10 changes: 10 additions & 0 deletions cxl/event_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ struct jlist_node {
struct list_node list;
};

struct event_ctx {
const char *system;
struct list_head jlist_head;
const char *event_name; /* optional */
int (*parse_event)(struct tep_event *event, struct tep_record *record,
struct list_head *jlist_head); /* optional */
};

int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx);

#endif
1 change: 1 addition & 0 deletions cxl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cxl_tool = executable('cxl',
json,
versiondep,
traceevent,
tracefs,
],
install : true,
install_dir : rootbindir,
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ libudev = dependency('libudev')
uuid = dependency('uuid')
json = dependency('json-c')
traceevent = dependency('libtraceevent')
tracefs = dependency('libtracefs')

if get_option('docs').enabled()
if get_option('asciidoctor').enabled()
asciidoc = find_program('asciidoctor', required : true)
Expand Down

0 comments on commit 7b237bc

Please sign in to comment.