profile: redo eventname handling

The eventname handling code was splattered all over the place.
Collect it in a single source file and use C++ idioms to avoid
nasty memory management. Provide a C-only interface, however.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-02-12 15:51:39 +01:00 committed by Dirk Hohndel
parent ab7b9329c0
commit 0d3c9954f4
10 changed files with 94 additions and 70 deletions

View file

@ -99,38 +99,3 @@ bool same_event(const struct event *a, const struct event *b)
return 0;
return !strcmp(a->name, b->name);
}
/* collect all event names and whether we display them */
struct ev_select *ev_namelist = NULL;
int evn_used = 0;
static int evn_allocated = 0;
void clear_events(void)
{
for (int i = 0; i < evn_used; i++)
free(ev_namelist[i].ev_name);
evn_used = 0;
}
void remember_event(const char *eventname)
{
int i = 0, len;
if (!eventname || (len = strlen(eventname)) == 0)
return;
while (i < evn_used) {
if (!strncmp(eventname, ev_namelist[i].ev_name, len))
return;
i++;
}
if (evn_used == evn_allocated) {
evn_allocated += 10;
ev_namelist = realloc(ev_namelist, evn_allocated * sizeof(struct ev_select));
if (!ev_namelist)
/* we are screwed, but let's just bail out */
return;
}
ev_namelist[evn_used].ev_name = strdup(eventname);
ev_namelist[evn_used].plot_ev = true;
evn_used++;
}