Skip to content

Commit d659d4d

Browse files
committed
fix prv fail on empty state, event
1 parent 1bae7d1 commit d659d4d

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

pypop/prv.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434

3535
# Event states - hopefully these will not change(!)
3636
K_STATE_RUNNING = "1"
37-
K_EVENT_OMP_PARALLEL = "60000001"
38-
K_EVENT_OMP_LOOP_FUNCTION = "60000018"
39-
K_EVENT_OMP_TASK_FUNCTION = "60000023"
40-
K_EVENT_OMP_LOOP_FILE_AND_LINE = "60000118"
41-
K_EVENT_OMP_TASK_FILE_AND_LINE = "60000123"
37+
K_EVENT_OMP_PARALLEL = 60000001
38+
K_EVENT_OMP_LOOP_FUNCTION = 60000018
39+
K_EVENT_OMP_TASK_FUNCTION = 60000023
40+
K_EVENT_OMP_LOOP_FILE_AND_LINE = 60000118
41+
K_EVENT_OMP_TASK_FILE_AND_LINE = 60000123
4242

4343

4444
class PRV(object):
@@ -49,6 +49,7 @@ class PRV(object):
4949
_commkey = "/PyPOPPRVComms"
5050
_eventnamekey = "/PyPOPPRVEventNames"
5151
_eventvaluekey = "/PyPOPPRVEventVals_"
52+
_ompregionkey = "/PyPOPPRVOMPRegionDetail"
5253

5354
_formatversionkey = "/PyPOPPRVBinaryTraceFormatVersion"
5455
_formatversion = 1
@@ -159,14 +160,14 @@ def _parse_pcf(self):
159160

160161
if block_mode == "EVENT_TYPE":
161162
linevals = line.strip().split(maxsplit=2)
162-
eventkey = linevals[1]
163+
eventkey = int(linevals[1])
163164
self.event_names[eventkey] = linevals[2]
164165
self.event_vals[eventkey] = {}
165166
continue
166167

167168
if block_mode == "VALUES":
168169
linevals = line.strip().split(maxsplit=1)
169-
valuekey = linevals[0]
170+
valuekey = int(linevals[0])
170171
self.event_vals[eventkey][valuekey] = linevals[1]
171172

172173
except FileNotFoundError:
@@ -259,8 +260,20 @@ def _write_binarycache(self):
259260

260261
with HDFStoreContext(binaryfile, mode="w") as hdfstore:
261262
hdfstore.put(self._metadatakey, packed_metadata, format="t")
262-
hdfstore.put(self._statekey, self.state, format="t", complib="blosc")
263-
hdfstore.put(self._eventkey, self.event, format="t", complib="blosc")
263+
if self.state is not None and not self.state.empty:
264+
hdfstore.put(self._statekey, self.state, format="t", complib="blosc")
265+
if self.event is not None and not self.event.empty:
266+
hdfstore.put(self._eventkey, self.event, format="t", complib="blosc")
267+
if self.comm is not None and not self.comm.empty:
268+
hdfstore.put(self._commkey, self.comm, format="t", complib="blosc")
269+
if self._omp_region_data is not None and not self._omp_region_data.empty:
270+
hdfstore.put(
271+
self._ompregionkey,
272+
self._omp_region_data,
273+
format="t",
274+
complib="blosc",
275+
)
276+
264277
hdfstore.put(self._eventnamekey, pd.Series(self.event_names), format="t")
265278

266279
for evtkey, evtvals in self.event_vals.items():
@@ -270,9 +283,6 @@ def _write_binarycache(self):
270283
format="t",
271284
)
272285

273-
if self.comm is not None and not self.comm.empty:
274-
hdfstore.put(self._commkey, self.comm, format="t", complib="blosc")
275-
276286
def _load_binarycache(self):
277287

278288
try:
@@ -303,8 +313,6 @@ def _read_binarycache(self, filename):
303313

304314
try:
305315
self.metadata = TraceMetadata.unpack_dataframe(file_metadata)
306-
self.state = hdfstore[PRV._statekey]
307-
self.event = hdfstore[PRV._eventkey]
308316
self.event_names = hdfstore[PRV._eventnamekey].to_dict()
309317
self.event_vals = {}
310318
for evtkey in (
@@ -315,10 +323,22 @@ def _read_binarycache(self, filename):
315323
except KeyError:
316324
raise ValueError("{} corrupted binary event cache")
317325

326+
try:
327+
self.state = hdfstore[PRV._statekey]
328+
except KeyError:
329+
pass
330+
try:
331+
self.event = hdfstore[PRV._eventkey]
332+
except KeyError:
333+
pass
318334
try:
319335
self.comm = hdfstore[PRV._commkey]
320336
except KeyError:
321337
pass
338+
try:
339+
self._omp_region_data = hdfstore[self._ompregionkey]
340+
except KeyError:
341+
pass
322342

323343
def profile_openmp_regions(self, no_progress=False, ignore_cache=False):
324344
"""Profile OpenMP Region Info

0 commit comments

Comments
 (0)