1 #pragma once 2 3 #include <petsc/private/loghandlerimpl.h> 4 #include <petsc/private/logimpl.h> 5 #include <../src/sys/logging/handler/impls/default/logdefault.h> 6 #include <petsc/private/hashmap.h> 7 8 typedef int NestedId; 9 10 static inline PETSC_UNUSED NestedId NestedIdFromEvent(PetscLogEvent e) 11 { 12 return e; 13 } 14 15 static inline PETSC_UNUSED PetscLogEvent NestedIdToEvent(NestedId e) 16 { 17 return e; 18 } 19 20 static inline PETSC_UNUSED NestedId NestedIdFromStage(PetscLogStage s) 21 { 22 return -(s + 2); 23 } 24 25 static inline PETSC_UNUSED PetscLogStage NestedIdToStage(NestedId s) 26 { 27 return -(s + 2); 28 } 29 30 typedef struct _n_NestedIdPair NestedIdPair; 31 struct _n_NestedIdPair { 32 PetscLogEvent root; 33 NestedId leaf; 34 }; 35 36 #define NestedIdPairHash(key) PetscHashCombine(PetscHash_UInt32((PetscHash32_t)((key).root)), PetscHash_UInt32((PetscHash32_t)((key).leaf))) 37 #define NestedIdPairEqual(k1, k2) (((k1).root == (k2).root) && ((k1).leaf == (k2).leaf)) 38 39 PETSC_HASH_MAP(NestedHash, NestedIdPair, PetscLogEvent, NestedIdPairHash, NestedIdPairEqual, -1) 40 41 typedef struct _n_PetscLogHandler_Nested *PetscLogHandler_Nested; 42 struct _n_PetscLogHandler_Nested { 43 PetscLogState state; 44 PetscLogHandler handler; 45 PetscNestedHash pair_map; 46 PetscIntStack nested_stack; // stack of nested ids 47 PetscIntStack orig_stack; // stack of the original ids 48 PetscClassId nested_stage_id; 49 PetscLogDouble threshold; 50 }; 51 52 typedef struct { 53 const char *name; 54 PetscInt id; 55 PetscInt parent; 56 PetscInt num_descendants; 57 } PetscNestedEventNode; 58 59 typedef struct { 60 MPI_Comm comm; 61 PetscLogGlobalNames global_events; 62 PetscNestedEventNode *nodes; 63 PetscEventPerfInfo *perf; 64 } PetscNestedEventTree; 65 66 typedef enum { 67 PETSC_LOG_NESTED_XML, 68 PETSC_LOG_NESTED_FLAMEGRAPH 69 } PetscLogNestedType; 70 71 PETSC_INTERN PetscErrorCode PetscLogHandlerView_Nested_XML(PetscLogHandler_Nested, PetscNestedEventTree *, PetscViewer); 72 PETSC_INTERN PetscErrorCode PetscLogHandlerView_Nested_Flamegraph(PetscLogHandler_Nested, PetscNestedEventTree *, PetscViewer); 73