Skip to content

Commit

Permalink
agg: split clearing of one aggregation into its own function
Browse files Browse the repository at this point in the history
The new dt_aggregate_clear_one() function is designed to allow it to be
passed to a callback function to the aggregation walk functions.  It
will be used in that manner in future patches.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Feb 26, 2023
1 parent f76ebb2 commit b05d268
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
72 changes: 37 additions & 35 deletions libdtrace/dt_aggregate.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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.
*/
Expand Down Expand Up @@ -438,6 +438,40 @@ dt_agg_one_agg(dt_ident_t *aid, dtrace_recdesc_t *rec, char *dst,
}
}

int
dt_aggregate_clear_one(const dtrace_aggdata_t *agd, void *arg)
{
dtrace_hdl_t *dtp = arg;
dtrace_aggdesc_t *agg = agd->dtada_desc;
dtrace_recdesc_t *rec = &agg->dtagd_drecs[DT_AGGDATA_RECORD];
int64_t *vals = (int64_t *)
&agd->dtada_data[rec->dtrd_offset];
int i, max_cpus = dtp->dt_conf.max_cpuid + 1;

switch (rec->dtrd_action) {
case DT_AGG_MIN:
*vals = INT64_MAX;
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
*((uint64_t*)agd->dtada_percpu[i]) = INT64_MAX;
break;
case DT_AGG_MAX:
*vals = INT64_MIN;
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
*((uint64_t*)agd->dtada_percpu[i]) = INT64_MIN;
break;
default:
memset(vals, 0, rec->dtrd_size);
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
memset(agd->dtada_percpu[i], 0, rec->dtrd_size);
break;
}

return 0;
}

static int
dt_aggregate_snap_one(dtrace_hdl_t *dtp, int aggid, int cpu, const char *key,
const char *data)
Expand Down Expand Up @@ -1695,41 +1729,9 @@ dtrace_aggregate_clear(dtrace_hdl_t *dtp)
dt_aggregate_t *agp = &dtp->dt_aggregate;
dt_ahash_t *hash = &agp->dtat_hash;
dt_ahashent_t *h;
int i, max_cpus = dtp->dt_conf.max_cpuid + 1;

for (h = hash->dtah_all; h != NULL; h = h->dtahe_nextall) {
dtrace_aggdesc_t *agg;
dtrace_aggdata_t *agd;
dtrace_recdesc_t *rec;
int64_t *vals;

agg = h->dtahe_data.dtada_desc;
agd = &h->dtahe_data;
rec = &agg->dtagd_drecs[DT_AGGDATA_RECORD];
vals = (int64_t *)&agd->dtada_data[rec->dtrd_offset];

switch (rec->dtrd_action) {
case DT_AGG_MIN:
*vals = INT64_MAX;
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
*((uint64_t*)agd->dtada_percpu[i]) = INT64_MAX;
break;
case DT_AGG_MAX:
*vals = INT64_MIN;
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
*((uint64_t*)agd->dtada_percpu[i]) = INT64_MIN;
break;
default:
memset(vals, 0, rec->dtrd_size);
if (agd->dtada_percpu)
for (i = 0; i < max_cpus; i++)
memset(agd->dtada_percpu[i], 0, rec->dtrd_size);
break;
}

}
for (h = hash->dtah_all; h != NULL; h = h->dtahe_nextall)
dt_aggregate_clear_one(&h->dtahe_data, dtp);
}

void
Expand Down
1 change: 1 addition & 0 deletions libdtrace/dt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ extern dtrace_difo_t *dt_difo_copy(dtrace_hdl_t *dtp, const dtrace_difo_t *odp);
extern int dt_aggregate_go(dtrace_hdl_t *);
extern int dt_aggregate_init(dtrace_hdl_t *);
extern void dt_aggregate_destroy(dtrace_hdl_t *);
extern int dt_aggregate_clear_one(const dtrace_aggdata_t *, void *);

extern int dt_consume_init(dtrace_hdl_t *);
extern void dt_consume_fini(dtrace_hdl_t *);
Expand Down

0 comments on commit b05d268

Please sign in to comment.