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