libdtrace: use module address index for aggregation
PATCH 13/20 libdtrace: use module address index for aggregation
Share dt_module_by_addr() with dt_aggregate_mod() to avoid scanning every module when normalizing aggregation keys. Preserve the representative module address and reuse the indexed lookup, including overlap precedence and its allocation-failure fallback.
--- libdtrace/dt_aggregate.c | 38 ++++++++++---------------------------- libdtrace/dt_module.c | 2 +- libdtrace/dt_module.h | 1 + 3 files changed, 12 insertions(+), 29 deletions(-)
libdtrace/dt_aggregate.c +10 -28
@@ -1,6 +1,6 @@/* * Oracle Linux DTrace. -* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2008, 2026, Oracle and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at * http://oss.oracle.com/licenses/upl. */
@@ -18,6 +18,7 @@#include <port.h> #include <dt_aggregate.h> #include <dt_bpf.h> +#include <dt_module.h> typedef struct dt_ahashent { struct dt_ahashent *dtahe_prev; /* prev on hash chain */
@@ -394,34 +395,15 @@ dt_aggregate_mod(dtrace_hdl_t *dtp, uint64_t *addr)return ; } -for (dmp =dt_list_next (&dtp->dt_modlist); dmp !=NULL ; - dmp =dt_list_next (dmp)) { -/* -* Check text and data ranges for match. If there is a range -* that covers the given address, normalize it. -*/ -if (dmp->dm_text_addrs !=NULL && -bsearch (addr, dmp->dm_text_addrs, dmp->dm_text_addrs_size, -sizeof (struct dtrace_addr_range ), - dtrace_addr_range_cmp) !=NULL ) { - - *addr = dmp->dm_text_addrs[0 ].dar_va; -return ; - } - -if (dmp->dm_data_addrs !=NULL && -bsearch (addr, dmp->dm_data_addrs, dmp->dm_data_addrs_size, -sizeof (struct dtrace_addr_range ), - dtrace_addr_range_cmp) !=NULL ) { - -if (dmp->dm_text_addrs !=NULL ) - *addr = dmp->dm_text_addrs[0 ].dar_va; -else - *addr = dmp->dm_data_addrs[0 ].dar_va; + dmp =dt_module_by_addr (dtp, *addr); +if (dmp ==NULL ) +return ; -return ; - } - } +/* Normalize text and data addresses to the same module address. */ +if (dmp->dm_text_addrs !=NULL ) + *addr = dmp->dm_text_addrs[0 ].dar_va; +else + *addr = dmp->dm_data_addrs[0 ].dar_va; } static dtrace_aggid_t
libdtrace/dt_module.c +1 -1
@@ -2421,7 +2421,7 @@ dt_module_ranges_build(dtrace_hdl_t *dtp)return 0 ; } -static dt_module_t * +dt_module_t *dt_module_by_addr (dtrace_hdl_t *dtp,GElf_Addr addr) {dt_module_range_t *index;
libdtrace/dt_module.h +1 -0
@@ -20,6 +20,7 @@ extern void dt_user_path_destroy(dtrace_hdl_t *);extern dt_module_t *dt_module_lookup_by_name (dtrace_hdl_t *,const char *);extern dt_module_t *dt_module_lookup_by_ctf (dtrace_hdl_t *,ctf_file_t *); +extern dt_module_t *dt_module_by_addr (dtrace_hdl_t *,GElf_Addr );extern int dt_module_sym_iter (const dt_module_t *,proc_sym_f *,void *);extern ctf_file_t *dt_module_shared_ctf (dtrace_hdl_t *);
Signature · 1 line
2.52.0
Quoted 4 lines · Kris Van Hees
Share
dt_module_by_addr()withdt_aggregate_mod()to avoid scanning every module when normalizing aggregation keys. Preserve the representative module address and reuse the indexed lookup, including overlap precedence and its allocation-failure fallback.
Nice code duplication reduction.
Reviewed-by Nick Alcock <[email protected]>
Signature · 1 line
NULL && (void)