Skip to content

Commit 8b83e0e

Browse files
committed
WIP: Python derived/accum interface
* early draft of Python/CFFI interface to derived metrics/accumulators described in: - gh-642 - gh-677 * for now this definitely doesn't work, and feels like I'm basically reconstituting a C control flow in CFFI/Python instead of using a sensible exposure point between C and Python to pull out populated structs from a single entry point * perhaps folks can just help me sort out the current issues noted in the source changes rather than providing a convenient API, though once thorough regression tests are in place that might be something to consider in the future... (or even just maintaining it in `pandas`/Python someday if the perf is ~similar)
1 parent cb20d49 commit 8b83e0e

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

darshan-util/pydarshan/darshan/backend/api_def_c.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@
88

99

1010
header = """/* from darshan-logutils.h */
11+
12+
struct darshan_derived_metrics {
13+
int64_t total_bytes;
14+
double unique_io_total_time_by_slowest;
15+
double unique_rw_only_time_by_slowest;
16+
double unique_md_only_time_by_slowest;
17+
int unique_io_slowest_rank;
18+
double shared_io_total_time_by_slowest;
19+
double agg_perf_by_slowest;
20+
double agg_time_by_slowest;
21+
struct darshan_file_category_counters;
22+
};
23+
24+
25+
26+
struct darshan_accumulator {
27+
int64_t module_id;
28+
int64_t job_nprocs;
29+
void* agg_record;
30+
int num_records;
31+
void *file_hash_table;
32+
double shared_io_total_time_by_slowest;
33+
int64_t total_bytes;
34+
double *rank_cumul_io_total_time;
35+
double *rank_cumul_rw_only_time;
36+
double *rank_cumul_md_only_time;
37+
};
38+
1139
struct darshan_mnt_info
1240
{
1341
char mnt_type[3031];
@@ -23,6 +51,11 @@
2351
int partial_flag;
2452
};
2553
54+
int darshan_accumulator_emit(struct darshan_accumulator, struct darshan_derived_metrics*, void* aggregation_record);
55+
int darshan_accumulator_destroy(struct darshan_accumulator);
56+
int darshan_accumulator_create(enum darshan_module_id, int64_t, struct darshan_accumulator*);
57+
int darshan_accumulator_inject(struct darshan_accumulator, void*, int);
58+
2659
/* from darshan-log-format.h */
2760
typedef uint64_t darshan_record_id;
2861

darshan-util/pydarshan/darshan/backend/cffi_backend.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,28 @@ def _log_get_heatmap_record(log):
650650
libdutil.darshan_free(buf[0])
651651

652652
return rec
653+
654+
655+
def log_get_accumulator(log, mod_name: str):
656+
log = log_open(log)
657+
jobrec = ffi.new("struct darshan_job *")
658+
libdutil.darshan_log_get_job(log['handle'], jobrec)
659+
modules = log_get_modules(log)
660+
661+
if mod_name not in modules:
662+
return None
663+
mod_type = _structdefs[mod_name]
664+
665+
darshan_accumulator = ffi.new("struct darshan_accumulator *")
666+
buf = ffi.new("void **")
667+
r = libdutil.darshan_log_get_record(log['handle'], modules[mod_name]['idx'], buf)
668+
rbuf = ffi.cast(mod_type, buf)
669+
670+
libdutil.darshan_accumulator_create(modules[mod_name]['idx'],
671+
jobrec[0].nprocs,
672+
darshan_accumulator)
673+
674+
# TODO: fix the segfault on the inject call below
675+
r = libdutil.darshan_accumulator_inject(darshan_accumulator[0], rbuf[0], 1)
676+
# TODO: darshan_accumulator_emit and darshan_accumulator_destroy
677+
return darshan_accumulator

darshan-util/pydarshan/darshan/tests/test_cffi_misc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@ def test_log_get_generic_record(dtype):
159159
# make sure the returned key/column names agree
160160
assert actual_counter_names == expected_counter_names
161161
assert actual_fcounter_names == expected_fcounter_names
162+
163+
164+
@pytest.mark.parametrize("log_path", [
165+
"imbalanced-io.darshan",
166+
])
167+
def test_accumulator_emit(log_path):
168+
log_path = get_log_path(log_path)
169+
report = darshan.DarshanReport(log_path, read_all=True)
170+
for mod_name in report.modules:
171+
acc = backend.log_get_accumulator(log=log_path,
172+
mod_name=mod_name)
173+
# TODO: assert against values from i.e., perl reports

0 commit comments

Comments
 (0)