Skip to content

Commit c2dc722

Browse files
author
Shane Snyder
committed
refactor code to match darshan-hpcgh-839
* move `log_get_bytes_bandwidth()` out of CFFI module to darshan/lib/accum.py * adopt LRU cache and other cleanup tweaks for log_get_derived_metrics()
1 parent 9b265ff commit c2dc722

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ def _log_get_heatmap_record(log):
633633
buf = ffi.new("void **")
634634
r = libdutil.darshan_log_get_record(log['handle'], modules[mod_name]['idx'], buf)
635635
if r < 1:
636-
libdutil.darshan_free(buf[0])
637636
return None
638637

639638
filerec = ffi.cast(mod_type, buf)
@@ -660,6 +659,7 @@ def _log_get_heatmap_record(log):
660659
return rec
661660

662661

662+
@functools.lru_cache()
663663
def log_get_derived_metrics(log_path: str, mod_name: str):
664664
"""
665665
Returns the darshan_derived_metrics struct from CFFI/C accumulator code.
@@ -716,24 +716,13 @@ def log_get_derived_metrics(log_path: str, mod_name: str):
716716
r = libdutil.darshan_accumulator_emit(darshan_accumulator[0],
717717
darshan_derived_metrics,
718718
rbuf[0])
719+
libdutil.darshan_free(buf[0])
720+
libdutil.darshan_accumulator_destroy(darshan_accumulator[0])
721+
log_close(log_handle)
719722
if r != 0:
720-
libdutil.darshan_free(buf[0])
721723
raise RuntimeError("A nonzero exit code was received from "
722724
"darshan_accumulator_emit() at the C level. "
723725
"It may be possible "
724726
"to retrieve additional information from the stderr "
725727
"stream.")
726-
libdutil.darshan_free(buf[0])
727728
return darshan_derived_metrics
728-
729-
730-
def log_get_bytes_bandwidth(log_path: str, mod_name: str) -> str:
731-
# get total bytes (in MiB) and bandwidth (in MiB/s) for
732-
# a given module -- this information was commonly reported
733-
# in the old perl-based summary reports
734-
darshan_derived_metrics = log_get_derived_metrics(log_path=log_path,
735-
mod_name=mod_name)
736-
total_mib = darshan_derived_metrics.total_bytes / 2 ** 20
737-
total_bw = darshan_derived_metrics.agg_perf_by_slowest
738-
ret_str = f"I/O performance estimate (at the {mod_name} layer): transferred {total_mib:.1f} MiB at {total_bw:.2f} MiB/s"
739-
return ret_str

darshan-util/pydarshan/darshan/lib/accum.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,58 @@
1111
import humanize
1212

1313

14+
def log_get_bytes_bandwidth(log_path: str, mod_name: str) -> str:
15+
"""
16+
Summarize I/O performance for a given darshan module.
17+
18+
Parameters
19+
----------
20+
log_path : str
21+
Path to the darshan binary log file.
22+
mod_name : str
23+
Name of the darshan module to summarize the I/O
24+
performance for.
25+
26+
Returns
27+
-------
28+
out: str
29+
A short string summarizing the performance of the given module
30+
in the provided log file, including bandwidth and total data
31+
transferred.
32+
33+
Raises
34+
------
35+
RuntimeError
36+
When a provided module name is not supported for the accumulator
37+
interface for provision of the summary data, or for any other
38+
error that occurs in the C/CFFI interface.
39+
ValueError
40+
When a provided module name does not exist in the log file.
41+
42+
Examples
43+
--------
44+
45+
>>> from darshan.log_utils import get_log_path
46+
>>> from darshan.lib.accum import log_get_bytes_bandwidth
47+
48+
>>> log_path = get_log_path("imbalanced-io.darshan")
49+
>>> log_get_bytes_bandwidth(log_path, "POSIX")
50+
I/O performance estimate (at the POSIX layer): transferred 101785.8 MiB at 164.99 MiB/s
51+
52+
>>> log_get_bytes_bandwidth(log_path, "MPI-IO")
53+
I/O performance estimate (at the MPI-IO layer): transferred 126326.8 MiB at 101.58 MiB/s
54+
"""
55+
# get total bytes (in MiB) and bandwidth (in MiB/s) for
56+
# a given module -- this information was commonly reported
57+
# in the old perl-based summary reports
58+
darshan_derived_metrics = log_get_derived_metrics(log_path=log_path,
59+
mod_name=mod_name)
60+
total_mib = darshan_derived_metrics.total_bytes / 2 ** 20
61+
total_bw = darshan_derived_metrics.agg_perf_by_slowest
62+
ret_str = f"I/O performance estimate (at the {mod_name} layer): transferred {total_mib:.1f} MiB at {total_bw:.2f} MiB/s"
63+
return ret_str
64+
65+
1466
def log_file_count_summary_table(log_path: str,
1567
module: str):
1668
# the darshan_file_category enum is not really

0 commit comments

Comments
 (0)