Skip to content

Commit ae5b0c1

Browse files
committed
MAINT: PR 839 revisions
* needed to expose `darshan_file_category_counters` so that its size is available for usage in `darshan_derived_metrics` struct * some improvements to the renamed `log_get_derived_metrics()` function, including first draft of error handling; the renamed `test_derived_metrics_basic` test was also adjusted to expect an error for `LUSTRE` module
1 parent 6206d0e commit ae5b0c1

File tree

3 files changed

+81
-12
lines changed

3 files changed

+81
-12
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
header = """/* from darshan-logutils.h */
1111
12+
struct darshan_file_category_counters {
13+
int64_t count; /* number of files in this category */
14+
int64_t total_read_volume_bytes; /* total read traffic volume */
15+
int64_t total_write_volume_bytes;/* total write traffic volume */
16+
int64_t max_read_volume_bytes; /* maximum read traffic volume to 1 file */
17+
int64_t max_write_volume_bytes; /* maximum write traffic volume to 1 file */
18+
int64_t total_max_offset_bytes; /* summation of max_offsets */
19+
int64_t max_offset_bytes; /* largest max_offset */
20+
int64_t nprocs; /* how many procs accessed (-1 for "all") */
21+
};
22+
1223
struct darshan_derived_metrics {
1324
int64_t total_bytes;
1425
double unique_io_total_time_by_slowest;

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

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,26 +652,68 @@ def _log_get_heatmap_record(log):
652652
return rec
653653

654654

655-
def log_get_accumulator(log, mod_name: str):
656-
log = log_open(log)
655+
def log_get_derived_metrics(log_path: str, mod_name: str):
656+
"""
657+
Returns the darshan_derived_metrics struct from CFFI/C accumulator code.
658+
659+
Parameters:
660+
log_path: Path to the darshan log file
661+
mod_name: The name of the module to retrieve derived metrics for
662+
663+
Returns:
664+
darshan_derived_metrics struct (cdata object)
665+
"""
666+
# TODO: eventually add support for i.e., a regex filter on the records
667+
# the user wants to get derived metrics for--like filtering to records
668+
# with a single filename involved before accumulating the data?
669+
log_handle = log_open(log_path)
657670
jobrec = ffi.new("struct darshan_job *")
658-
libdutil.darshan_log_get_job(log['handle'], jobrec)
659-
modules = log_get_modules(log)
671+
libdutil.darshan_log_get_job(log_handle['handle'], jobrec)
672+
modules = log_get_modules(log_handle)
660673

661674
if mod_name not in modules:
662675
return None
663676
mod_type = _structdefs[mod_name]
664677

665678
buf = ffi.new("void **")
666-
r = libdutil.darshan_log_get_record(log['handle'], modules[mod_name]['idx'], buf)
679+
r = libdutil.darshan_log_get_record(log_handle['handle'], modules[mod_name]['idx'], buf)
667680
rbuf = ffi.cast(mod_type, buf)
668681

669682
darshan_accumulator = ffi.new("darshan_accumulator *")
683+
print("before create")
670684
r = libdutil.darshan_accumulator_create(modules[mod_name]['idx'],
671685
jobrec[0].nprocs,
672686
darshan_accumulator)
673-
674-
# TODO: fix the segfault on the inject call below
687+
if r != 0:
688+
raise RuntimeError("A nonzero exit code was received from "
689+
"darshan_accumulator_create() at the C level. "
690+
f"This could mean that the {mod_name} module does not "
691+
"support derived metric calculation, or that "
692+
"another kind of error occurred. It may be possible "
693+
"to retrieve additional information from the stderr "
694+
"stream.")
695+
print("after create")
696+
697+
print("before inject")
675698
r = libdutil.darshan_accumulator_inject(darshan_accumulator[0], rbuf[0], 1)
676-
# TODO: darshan_accumulator_emit and darshan_accumulator_destroy
677-
return darshan_accumulator
699+
if r != 0:
700+
raise RuntimeError("A nonzero exit code was received from "
701+
"darshan_accumulator_inject() at the C level. "
702+
"It may be possible "
703+
"to retrieve additional information from the stderr "
704+
"stream.")
705+
print("after inject")
706+
darshan_derived_metrics = ffi.new("struct darshan_derived_metrics *")
707+
print("before emit")
708+
r = libdutil.darshan_accumulator_emit(darshan_accumulator[0],
709+
darshan_derived_metrics,
710+
rbuf[0])
711+
if r != 0:
712+
raise RuntimeError("A nonzero exit code was received from "
713+
"darshan_accumulator_emit() at the C level. "
714+
"It may be possible "
715+
"to retrieve additional information from the stderr "
716+
"stream.")
717+
print("after emit")
718+
#libdutil.darshan_accumulator_destroy(darshan_accumulator)
719+
return darshan_derived_metrics

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,26 @@ def test_log_get_generic_record(dtype):
164164
@pytest.mark.parametrize("log_path", [
165165
"imbalanced-io.darshan",
166166
])
167-
def test_accumulator_emit(log_path):
167+
def test_derived_metrics_basic(log_path):
168+
# test the basic scenario of retrieving
169+
# the derived metrics from all records for a given
170+
# module; the situation where you'd like to
171+
# retrieve derived metrics for a subset of records (i.e.,
172+
# a particular filename) is not tested here
168173
log_path = get_log_path(log_path)
169174
report = darshan.DarshanReport(log_path, read_all=True)
170175
for mod_name in report.modules:
171-
acc = backend.log_get_accumulator(log=log_path,
172-
mod_name=mod_name)
176+
# if support is added for accumulator work on these
177+
# modules later on, the test will fail to raise an error,
178+
# causing the test to ultimately fail; that is good, it will
179+
# force us to acknowledge that the support was added intentionally
180+
# under the hood
181+
print("testing mod_name:", mod_name)
182+
if mod_name in {"LUSTRE"}:
183+
with pytest.raises(RuntimeError):
184+
derived_metrics = backend.log_get_derived_metrics(log_path=log_path,
185+
mod_name=mod_name)
186+
else:
187+
derived_metrics = backend.log_get_derived_metrics(log_path=log_path,
188+
mod_name=mod_name)
173189
# TODO: assert against values from i.e., perl reports

0 commit comments

Comments
 (0)