@@ -652,26 +652,68 @@ def _log_get_heatmap_record(log):
652
652
return rec
653
653
654
654
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 )
657
670
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 )
660
673
661
674
if mod_name not in modules :
662
675
return None
663
676
mod_type = _structdefs [mod_name ]
664
677
665
678
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 )
667
680
rbuf = ffi .cast (mod_type , buf )
668
681
669
682
darshan_accumulator = ffi .new ("darshan_accumulator *" )
683
+ print ("before create" )
670
684
r = libdutil .darshan_accumulator_create (modules [mod_name ]['idx' ],
671
685
jobrec [0 ].nprocs ,
672
686
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" )
675
698
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
0 commit comments