xref: /petsc/include/petsclogtypes.h (revision 0619917b5a674bb687c64e7daba2ab22be99af31)
1 #ifndef PETSCLOGTYPES_H
2 #define PETSCLOGTYPES_H
3 #include <petscsystypes.h>
4 
5 /* SUBMANSEC = Profiling */
6 
7 /*S
8   PetscEventPerfInfo - statistics on how many times the event is used, how much time it takes, etc.
9 
10   Level: advanced
11 
12   Note:
13   This is the data structure that describes profiling statsitics collected for an event from
14   the default log handler (`PetscLogDefaultBegin()`) using `PetscLogEventGetPerfInfo()`.
15 
16 .seealso(): [](ch_profiling)
17 S*/
18 typedef struct {
19   int            id;                  /* The integer identifying this event / stage */
20   PetscBool      active;              /* Deprecated */
21   PetscBool      visible;             /* The flag to print info in summary */
22   int            depth;               /* The nesting depth of the event call */
23   int            count;               /* The number of times this event was executed */
24   PetscLogDouble flops;               /* The flops used in this event */
25   PetscLogDouble flops2;              /* The square of flops used in this event */
26   PetscLogDouble flopsTmp;            /* The accumulator for flops used in this event */
27   PetscLogDouble time;                /* The time taken for this event */
28   PetscLogDouble time2;               /* The square of time taken for this event */
29   PetscLogDouble timeTmp;             /* The accumulator for time taken for this event */
30   PetscLogDouble syncTime;            /* The synchronization barrier time */
31   PetscLogDouble dof[8];              /* The number of degrees of freedom associated with this event */
32   PetscLogDouble errors[8];           /* The errors (user-defined) associated with this event */
33   PetscLogDouble numMessages;         /* The number of messages in this event */
34   PetscLogDouble messageLength;       /* The total message lengths in this event */
35   PetscLogDouble numReductions;       /* The number of reductions in this event */
36   PetscLogDouble memIncrease;         /* How much the resident memory has increased in this event */
37   PetscLogDouble mallocIncrease;      /* How much the maximum malloced space has increased in this event */
38   PetscLogDouble mallocSpace;         /* How much the space was malloced and kept during this event */
39   PetscLogDouble mallocIncreaseEvent; /* Maximum of the high water mark with in event minus memory available at the end of the event */
40 #if defined(PETSC_HAVE_DEVICE)
41   PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */
42   PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */
43   PetscLogDouble CpuToGpuSize;  /* The total size of CPU to GPU copies */
44   PetscLogDouble GpuToCpuSize;  /* The total size of GPU to CPU copies */
45   PetscLogDouble GpuFlops;      /* The flops done on a GPU in this event */
46   PetscLogDouble GpuTime;       /* The time spent on a GPU in this event */
47 #endif
48 } PetscEventPerfInfo;
49 
50 typedef struct _n_PetscIntStack *PetscIntStack;
51 
52 /*MC
53     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
54      code.
55 
56     Level: intermediate
57 
58 .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogStage`
59 M*/
60 typedef int PetscLogEvent;
61 
62 /*MC
63     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
64 
65     Level: intermediate
66 
67 .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogEvent`
68 M*/
69 typedef int PetscLogStage;
70 
71 /*MC
72     PetscLogClass - id used to identify classes for logging purposes only.  It
73     is not equal to its `PetscClassId`, which is the identifier used for other
74     purposes.
75 
76     Level: developer
77 
78 .seealso: [](ch_profiling), `PetscLogStateClassRegister()`
79 M*/
80 typedef int PetscLogClass;
81 
82 /*S
83   PetscLogHandler - Interface for performance logging.  A log handler receives a `PetscLogState` that has
84   information about the events (`PetscLogEvent`) and stages (`PetscLogStage`) in the logging environment.
85   When a handler is connected to PETSc's global logging stream (`PetscLogHandlerStart()`), it receives
86   updates about events (`PetscLogEventBegin()` / `PetscLogEventEnd()`), stages (`PetscLogStagePush()` /
87   `PetscLogStagePop()`), and objects (`PetscLogObjectCreate()` / `PetscLogObjectDestroy()`).  After
88   collecting information the logger can summarize its data with `PetscLogHandlerView()`.
89 
90   Example Usage:
91 .vb
92 #include <petscsys.h>
93 
94 int main() {
95   UserCtx             ctx;
96   PetscLogHandlerType handler_type;
97 
98   PetscInitialize(...);
99   // ... fill in ctx
100   PetscLogHandlerCreate(PETSC_COMM_WORLD, &handler);
101   PetscLogHandlerSetType(handler, handler_type);
102   PetscLogHandlerStart(handler); // connect your handler to global logging state
103   // ... run code to be profiled
104   PetscLogHandlerStop(handler); // disconnect your handler from the global logging state
105   PetscLogHandlerView(handler, PETSC_VIEWER_STDOUT_WORLD); // view the results
106   PetscLogHandlerDestroy(&handler);
107   PetscFinalize();
108 }
109 .ve
110 
111   Level: developer
112 
113 .seealso: [](ch_profiling),
114           `PetscLogHandlerCreate()`,
115           `PetscLogHandlerStart()`, `PetscLogHandlerStop()`,
116           `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`,
117           `PetscLogHandlerSetState()`, `PetscLogHandlerGetState()`,
118           `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`,
119           `PetscLogHandlerEventSync()`,
120           `PetscLogHandlerObjectCreate()`, `PetscLogHandlerObjectDestroy()`,
121           `PetscLogHandlerStagePush()`, `PetscLogHandlerStagePop()`,
122           `PetscLogHandlerView()`,
123           `PetscLogHandlerDestroy()`,
124 S*/
125 typedef struct _p_PetscLogHandler *PetscLogHandler;
126 
127 /*J
128   PetscLogHandlerType - String with the name of a `PetscLogHandler` type
129 
130   Level: Developer
131 
132   Note:
133   Implementations included with PETSc include\:
134 + `PETSCLOGHANDLERDEFAULT` (`PetscLogDefaultBegin()`)        - formats data for PETSc's default summary (`PetscLogView()`) and data-dump (`PetscLogDump()`) formats.
135 . `PETSCLOGHANDLERNESTED` (`PetscLogNestedBegin()`)          - formats data for XML or flamegraph output
136 . `PETSCLOGHANDLERTRACE` (`PetscLogTraceBegin()`)            - traces profiling events in an output stream
137 . `PETSCLOGHANDLERMPE` (`PetscLogMPEBegin()`)                - outputs parallel performance visualization using MPE
138 . `PETSCLOGHANDLERPERFSTUBS` (`PetscLogPerfstubsBegin()`)    - outputs instrumentation data for PerfStubs/TAU
139 - `PETSCLOGHANDLERLEGACY` (`PetscLogLegacyCallbacksBegin()`) - adapts legacy callbacks to the `PetscLogHandler` interface
140 
141 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`
142 J*/
143 typedef const char *PetscLogHandlerType;
144 
145 #define PETSCLOGHANDLERDEFAULT   "default"
146 #define PETSCLOGHANDLERNESTED    "nested"
147 #define PETSCLOGHANDLERTRACE     "trace"
148 #define PETSCLOGHANDLERMPE       "mpe"
149 #define PETSCLOGHANDLERPERFSTUBS "perfstubs"
150 #define PETSCLOGHANDLERLEGACY    "legacy"
151 
152 typedef struct _n_PetscLogRegistry *PetscLogRegistry;
153 
154 /*S
155    PetscLogState - Interface for the shared state information used by `PetscLogHandler`s.
156 
157    Most users will not need to reference a `PetscLogState` directly: global logging routines
158    like `PetscLogEventRegister()`  and `PetscLogStagePush()` implicitly manipulate PETSc's global
159    logging state, `PetscLogGetState()`.
160 
161    Level: developer
162 
163    Notes:
164    `PetscLogState` holds a registry of events (`PetscLogStateEventRegister()`), stages
165    (`PetscLogStateStageRegister()`), and classes (`PetscLogStateClassRegister()`).
166    It keeps track of when the user has activated events (`PetscLogStateEventSetActive()`) and
167    stages (`PetscLogStateStageSetActive()`).  It also keeps a stack of running stages
168    (`PetscLogStateStagePush()`, `PetscLogStateStagePop()`).
169 
170    The struct defining `PetscLogState` is in a public header so that `PetscLogEventBegin()`,
171    `PetscLogEventEnd()`, `PetscLogObjectCreate()`, and `PetscLogObjectDestroy()` can be defined
172    as macros rather than function calls, but users are discouraged from directly accessing
173    the struct's fields, which are subject to change.
174 
175 .seealso: [](ch_profiling), `PetscLogStateCreate()`, `PetscLogStateDestroy()`
176 S*/
177 typedef struct _n_PetscLogState *PetscLogState;
178 struct _n_PetscLogState {
179   PetscLogRegistry registry;
180   PetscBT          active;
181   PetscIntStack    stage_stack;
182   int              current_stage;
183   int              bt_num_stages;
184   int              bt_num_events;
185   int              refct;
186 };
187 
188 /*S
189   PetscLogEventInfo - A registry entry about a logging event for `PetscLogState`.
190 
191   Level: developer
192 
193 .seealso: [](ch_profiling), `PetscLogEvent`, `PetscLogState`, `PetscLogStateEventGetInfo()`
194 S*/
195 typedef struct {
196   char        *name;       /* The name of this event */
197   PetscClassId classid;    /* The class the event is associated with */
198   PetscBool    collective; /* Flag this event as collective */
199 } PetscLogEventInfo;
200 
201 /*S
202   PetscLogClassInfo - A registry entry about a class for `PetscLogState`.
203 
204   Level: developer
205 
206 .seealso: [](ch_profiling), `PetscLogClass`, `PetscLogState`, `PetscLogStateStageGetInfo()`
207 S*/
208 typedef struct {
209   char        *name;    /* The class name */
210   PetscClassId classid; /* The integer identifying this class */
211 } PetscLogClassInfo;
212 
213 /*S
214   PetscLogStageInfo - A registry entry about a class for `PetscLogState`.
215 
216   Level: developer
217 
218 .seealso: [](ch_profiling), `PetscLogStage`, `PetscLogState`, `PetscLogStateClassGetInfo()`
219 S*/
220 typedef struct _PetscLogStageInfo {
221   char *name; /* The stage name */
222 } PetscLogStageInfo;
223 
224 #endif
225