Skip to content

Commit

Permalink
session: Introduce session_find_filter()
Browse files Browse the repository at this point in the history
It first searches the main filter tree and check dlopen libraries.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Nov 29, 2024
1 parent 621f6ab commit a0ed165
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions uftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ void session_add_dlopen(struct uftrace_session *sess, uint64_t timestamp, unsign
const char *libname, bool needs_srcline);
struct uftrace_symbol *session_find_dlsym(struct uftrace_session *sess, uint64_t timestamp,
unsigned long addr);
struct uftrace_filter *session_find_filter(struct uftrace_session *sess, struct uftrace_record *rec,
struct uftrace_trigger *tr);
void delete_sessions(struct uftrace_session_link *sess);

struct uftrace_record;
Expand Down
2 changes: 1 addition & 1 deletion utils/fstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ int read_task_args(struct uftrace_task_reader *task, struct uftrace_record *rsta
return -1;
}

fl = uftrace_match_filter(rstack->addr, &sess->filters, &tr);
fl = session_find_filter(sess, rstack, &tr);
if (fl == NULL) {
pr_dbg("cannot find filter: %lx\n", rstack->addr);
return -1;
Expand Down
38 changes: 38 additions & 0 deletions utils/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,27 @@ struct uftrace_symbol *session_find_dlsym(struct uftrace_session *sess, uint64_t
return NULL;
}

static struct uftrace_dlopen_list *session_find_dlopen(struct uftrace_session *sess,
uint64_t timestamp, unsigned long addr)
{
struct uftrace_dlopen_list *pos;
struct uftrace_symbol *sym;

list_for_each_entry_reverse(pos, &sess->dlopen_libs, list) {
if (pos->time > timestamp)
continue;

if (pos->mod == NULL)
continue;

sym = find_sym(&pos->mod->symtab, addr - pos->base);
if (sym)
return pos;
}

return NULL;
}

void delete_session(struct uftrace_session *sess)
{
struct uftrace_dlopen_list *udl, *tmp;
Expand Down Expand Up @@ -789,6 +810,23 @@ struct uftrace_dbg_loc *task_find_loc_addr(struct uftrace_session_link *sessions
return NULL;
}

struct uftrace_filter *session_find_filter(struct uftrace_session *sess, struct uftrace_record *rec,
struct uftrace_trigger *tr)
{
struct uftrace_filter *ret;
struct uftrace_dlopen_list *dl;

ret = uftrace_match_filter(rec->addr, &sess->filters, tr);
if (ret)
return ret;

dl = session_find_dlopen(sess, rec->time, rec->addr);
if (dl == NULL)
return NULL;

return uftrace_match_filter(rec->addr, &dl->filters, tr);
}

#ifdef UNIT_TEST

static struct uftrace_session_link test_sessions;
Expand Down

0 comments on commit a0ed165

Please sign in to comment.