xref: /petsc/src/sys/logging/state/logstate.c (revision 1b37a2a7cc4a4fb30c3e967db1c694c0a1013f51)
1 #include <petsc/private/logimpl.h> /*I "petsclog.h" I*/
2 
3 /*@
4   PetscLogStateCreate - Create a logging state.
5 
6   Not collective
7 
8   Output Parameters:
9 . state - a `PetscLogState`
10 
11   Level: developer
12 
13   Note:
14   Most users will not need to create a `PetscLogState`.  The global state `PetscLogState()`
15   is created in `PetscInitialize()`.
16 
17 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateDestroy()`
18 @*/
19 PetscErrorCode PetscLogStateCreate(PetscLogState *state)
20 {
21   PetscInt      num_entries, max_events, max_stages;
22   PetscLogState s;
23 
24   PetscFunctionBegin;
25   PetscCall(PetscNew(state));
26   s = *state;
27   PetscCall(PetscLogRegistryCreate(&s->registry));
28   PetscCall(PetscIntStackCreate(&s->stage_stack));
29   PetscCall(PetscLogRegistryGetNumEvents(s->registry, NULL, &max_events));
30   PetscCall(PetscLogRegistryGetNumStages(s->registry, NULL, &max_stages));
31 
32   s->bt_num_events = max_events + 1; // one extra column for default stage activity
33   s->bt_num_stages = max_stages;
34   num_entries      = s->bt_num_events * s->bt_num_stages;
35   PetscCall(PetscBTCreate(num_entries, &s->active));
36   s->current_stage = -1;
37   s->refct         = 1;
38   PetscFunctionReturn(PETSC_SUCCESS);
39 }
40 
41 /*@
42   PetscLogStateDestroy - Destroy a logging state.
43 
44   Not collective
45 
46   Input Parameters:
47 . state - a `PetscLogState`
48 
49   Level: developer
50 
51   Note:
52   Most users will not need to destroy a `PetscLogState`.  The global state `PetscLogState()`
53   is destroyed in `PetscFinalize()`.
54 
55 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateCreate()`
56 @*/
57 PetscErrorCode PetscLogStateDestroy(PetscLogState *state)
58 {
59   PetscLogState s;
60   PetscFunctionBegin;
61   s      = *state;
62   *state = NULL;
63   if (s == NULL || --(s->refct) > 0) PetscFunctionReturn(PETSC_SUCCESS);
64   PetscCall(PetscLogRegistryDestroy(s->registry));
65   PetscCall(PetscIntStackDestroy(s->stage_stack));
66   PetscCall(PetscBTDestroy(&s->active));
67   PetscCall(PetscFree(s));
68   PetscFunctionReturn(PETSC_SUCCESS);
69 }
70 
71 /*@
72   PetscLogStateStagePush - Start a new logging stage.
73 
74   Not collective
75 
76   Input Parameters:
77 + state - a `PetscLogState`
78 - stage - a registered `PetscLogStage`
79 
80   Level: developer
81 
82   Note:
83   This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.
84 
85 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePop()`, `PetscLogStateGetCurrentStage()`
86 @*/
87 PetscErrorCode PetscLogStateStagePush(PetscLogState state, PetscLogStage stage)
88 {
89   PetscFunctionBegin;
90   if (PetscDefined(USE_DEBUG)) {
91     PetscInt num_stages;
92     PetscCall(PetscLogRegistryGetNumStages(state->registry, &num_stages, NULL));
93     PetscCheck(stage >= 0 && stage < num_stages, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d not in [0,%d)", stage, (int)num_stages);
94   }
95   PetscCall(PetscIntStackPush(state->stage_stack, stage));
96   state->current_stage = stage;
97   PetscFunctionReturn(PETSC_SUCCESS);
98 }
99 
100 /*@
101   PetscLogStateStagePop - End a running logging stage.
102 
103   Not collective
104 
105   Input Parameter:
106 . state - a `PetscLogState`
107 
108   Level: developer
109 
110   Note:
111   This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.
112 
113 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePush()`, `PetscLogStateGetCurrentStage()`
114 @*/
115 PetscErrorCode PetscLogStateStagePop(PetscLogState state)
116 {
117   int       curStage;
118   PetscBool empty;
119 
120   PetscFunctionBegin;
121   PetscCall(PetscIntStackPop(state->stage_stack, &curStage));
122   PetscCall(PetscIntStackEmpty(state->stage_stack, &empty));
123   if (!empty) {
124     PetscCall(PetscIntStackTop(state->stage_stack, &state->current_stage));
125   } else state->current_stage = -1;
126   PetscFunctionReturn(PETSC_SUCCESS);
127 }
128 
129 /*@
130   PetscLogStateGetCurrentStage - Get the last stage that was started
131 
132   Not collective
133 
134   Input Parameter:
135 . state - a `PetscLogState`
136 
137   Output Parameter:
138 . current - the last `PetscLogStage` started with `PetscLogStateStagePop()`
139 
140   Level: developer
141 
142   Note:
143   This is called for the global state (`PetscLogGetState()`) in `PetscLogGetCurrentStage()`.
144 
145 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePush()`, `PetscLogStateStagePop()`
146 @*/
147 PetscErrorCode PetscLogStateGetCurrentStage(PetscLogState state, PetscLogStage *current)
148 {
149   PetscFunctionBegin;
150   *current = state->current_stage;
151   PetscFunctionReturn(PETSC_SUCCESS);
152 }
153 
154 static PetscErrorCode PetscLogStateResize(PetscLogState state)
155 {
156   PetscBT  active_new;
157   PetscInt new_num_events;
158   PetscInt new_num_stages;
159 
160   PetscFunctionBegin;
161   PetscCall(PetscLogRegistryGetNumEvents(state->registry, NULL, &new_num_events));
162   new_num_events++;
163   PetscCall(PetscLogRegistryGetNumStages(state->registry, NULL, &new_num_stages));
164 
165   if (state->bt_num_events == new_num_events && state->bt_num_stages == new_num_stages) PetscFunctionReturn(PETSC_SUCCESS);
166   PetscCheck((new_num_stages % PETSC_BITS_PER_BYTE) == 0, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "new number of stages must be multiple of %d", PETSC_BITS_PER_BYTE);
167   PetscCall(PetscBTCreate(new_num_events * new_num_stages, &active_new));
168   if (new_num_stages == state->bt_num_stages) {
169     // single memcpy
170     size_t num_chars = (state->bt_num_stages * state->bt_num_events) / PETSC_BITS_PER_BYTE;
171 
172     PetscCall(PetscMemcpy(active_new, state->active, num_chars));
173   } else {
174     size_t num_chars_old = state->bt_num_stages / PETSC_BITS_PER_BYTE;
175     size_t num_chars_new = new_num_stages / PETSC_BITS_PER_BYTE;
176 
177     for (PetscInt i = 0; i < state->bt_num_events; i++) { PetscCall(PetscMemcpy(&active_new[i * num_chars_new], &(state->active[i * num_chars_old]), num_chars_old)); }
178   }
179   PetscCall(PetscBTDestroy(&state->active));
180   state->active        = active_new;
181   state->bt_num_events = new_num_events;
182   state->bt_num_stages = new_num_stages;
183   PetscFunctionReturn(PETSC_SUCCESS);
184 }
185 
186 /*@C
187   PetscLogStateStageRegister - Register a new stage with a logging state
188 
189   Not collective
190 
191   Input Parameters:
192 + state - a `PetscLogState`
193 - sname - a unique name
194 
195   Output Parameter:
196 . stage - the identifier for the registered stage
197 
198   Level: developer
199 
200   Note:
201   This is called for the global state (`PetscLogGetState()`) in `PetscLogStageRegister()`.
202 
203 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStagePush()`, `PetscLogStateStagePop()`
204 @*/
205 PetscErrorCode PetscLogStateStageRegister(PetscLogState state, const char sname[], PetscLogStage *stage)
206 {
207   PetscInt s;
208   PetscFunctionBegin;
209   PetscCall(PetscLogRegistryStageRegister(state->registry, sname, stage));
210   PetscCall(PetscLogStateResize(state));
211   s = *stage;
212   PetscCall(PetscBTSet(state->active, s)); // stages are by default active
213   for (PetscInt e = 1; e < state->bt_num_events; e++) {
214     // copy "Main Stage" activities
215     if (PetscBTLookup(state->active, 0 + e * state->bt_num_stages)) {
216       PetscCall(PetscBTSet(state->active, s + e * state->bt_num_stages));
217     } else {
218       PetscCall(PetscBTClear(state->active, s + e * state->bt_num_stages));
219     }
220   }
221   PetscFunctionReturn(PETSC_SUCCESS);
222 }
223 
224 /*@C
225   PetscLogStateEventRegister - Register a new event with a logging state
226 
227   Not collective
228 
229   Input Parameters:
230 + state - a `PetscLogState`
231 . sname - a unique name
232 - id    - the `PetscClassId` for the type of object most closely associated with this event
233 
234   Output Parameter:
235 . event - the identifier for the registered event
236 
237   Level: developer
238 
239   Note:
240   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventRegister()`.
241 
242 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageRegister()`
243 @*/
244 PetscErrorCode PetscLogStateEventRegister(PetscLogState state, const char sname[], PetscClassId id, PetscLogEvent *event)
245 {
246   PetscInt e;
247 
248   PetscFunctionBegin;
249   *event = PETSC_DECIDE;
250   PetscCall(PetscLogRegistryGetEventFromName(state->registry, sname, event));
251   if (*event > 0) PetscFunctionReturn(PETSC_SUCCESS);
252   PetscCall(PetscLogRegistryEventRegister(state->registry, sname, id, event));
253   PetscCall(PetscLogStateResize(state));
254   e = *event;
255   for (PetscInt s = 0; s < state->bt_num_stages; s++) PetscCall(PetscBTSet(state->active, s + (e + 1) * state->bt_num_stages)); // events are by default active
256   PetscFunctionReturn(PETSC_SUCCESS);
257 }
258 
259 /*@
260   PetscLogStateEventSetCollective - Set the collective nature of a logging event
261 
262   Logically collective
263 
264   Input Parameters:
265 + state      - a `PetscLogState`
266 . event      - a registered `PetscLogEvent`
267 - collective - if `PETSC_TRUE`, MPI processes synchronize during this event, and `PetscLogHandlerEventSync()` can be used to help measure the delays between when the processes begin the event
268 
269   Level: developer
270 
271   Note:
272   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetCollective()`.
273 
274 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventRegister()`
275 @*/
276 PetscErrorCode PetscLogStateEventSetCollective(PetscLogState state, PetscLogEvent event, PetscBool collective)
277 {
278   PetscFunctionBegin;
279   PetscCall(PetscLogRegistryEventSetCollective(state->registry, event, collective));
280   PetscFunctionReturn(PETSC_SUCCESS);
281 }
282 
283 /*@
284   PetscLogStateStageSetActive - Mark a stage as active or inactive.
285 
286   Not collective
287 
288   Input Parameters:
289 + state    - a `PetscLogState`
290 . stage    - a registered `PetscLogStage`
291 - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for all events during this stage
292 
293   Level: developer
294 
295   Note:
296   This is called for the global state (`PetscLogGetState()`) in `PetscLogStageSetActive()`
297 
298 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventSetActive()`
299 @*/
300 PetscErrorCode PetscLogStateStageSetActive(PetscLogState state, PetscLogStage stage, PetscBool isActive)
301 {
302   PetscFunctionBegin;
303   PetscCheck(stage >= 0 && stage < state->bt_num_stages, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", stage, state->bt_num_stages);
304   if (isActive) {
305     for (PetscInt e = 0; e < state->bt_num_events; e++) { PetscCall(PetscBTSet(state->active, stage + e * state->bt_num_stages)); }
306   } else {
307     for (PetscInt e = 0; e < state->bt_num_events; e++) { PetscCall(PetscBTClear(state->active, stage + e * state->bt_num_stages)); }
308   }
309   PetscFunctionReturn(PETSC_SUCCESS);
310 }
311 
312 /*@
313   PetscLogStateStageGetActive - Check if a logging stage is active or inactive.
314 
315   Not collective
316 
317   Input Parameters:
318 + state - a `PetscLogState`
319 - stage - a registered `PetscLogStage`
320 
321   Output Parameter:
322 . isActive - if `PETSC_FALSE`, the state should not send logging events to log handlers during this stage.
323 
324   Level: developer
325 
326   Note:
327   This is called for the global state (`PetscLogGetState()`) in `PetscLogStageGetActive()`.
328 
329 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageSetActive()`, `PetscLogHandler`, `PetscLogHandlerStart()`, `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`
330 @*/
331 PetscErrorCode PetscLogStateStageGetActive(PetscLogState state, PetscLogStage stage, PetscBool *isActive)
332 {
333   PetscFunctionBegin;
334   *isActive = PetscBTLookup(state->active, stage) ? PETSC_TRUE : PETSC_FALSE;
335   PetscFunctionReturn(PETSC_SUCCESS);
336 }
337 
338 /*@
339   PetscLogStateEventSetActive - Set a logging event as active or inactive during a logging stage.
340 
341   Not collective
342 
343   Input Parameters:
344 + state    - a `PetscLogState`
345 . stage    - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
346 . event    - a registered `PetscLogEvent`
347 - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for this stage and this event
348 
349   Level: developer
350 
351   Note:
352   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivate()` and `PetscLogEventDeactivate()`.
353 
354 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogEventSetActiveAll()`
355 @*/
356 PetscErrorCode PetscLogStateEventSetActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event, PetscBool isActive)
357 {
358   PetscFunctionBegin;
359   stage = (stage < 0) ? state->current_stage : stage;
360   PetscCheck(event >= 0 && event < state->bt_num_events, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid event %d should be in [0,%d)", event, state->bt_num_events);
361   PetscCheck(stage >= 0 && stage < state->bt_num_stages, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", stage, state->bt_num_stages);
362   PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, state->current_stage + (event + 1) * state->bt_num_stages));
363   PetscFunctionReturn(PETSC_SUCCESS);
364 }
365 
366 /*@
367   PetscLogStateEventSetActiveAll - Set logging event as active or inactive for all logging stages
368 
369   Not collective
370 
371   Input Parameters:
372 + state    - a `PetscLogState`
373 . event    - a registered `PetscLogEvent`
374 - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for all stages and all events
375 
376   Level: developer
377 
378   Note:
379   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetActiveAll()`.
380 
381 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`
382 @*/
383 PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState state, PetscLogEvent event, PetscBool isActive)
384 {
385   PetscFunctionBegin;
386   PetscCheck(event >= 0 && event < state->bt_num_events, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid event %d should be in [0,%d)", event, state->bt_num_events);
387   for (int stage = 0; stage < state->bt_num_stages; stage++) { PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, state->current_stage + (event + 1) * state->bt_num_stages)); }
388   PetscFunctionReturn(PETSC_SUCCESS);
389 }
390 
391 /*@
392   PetscLogStateClassSetActive - Set logging events associated with an event as active or inactive during a logging stage.
393 
394   Not collective
395 
396   Input Parameters:
397 + state    - a `PetscLogState`
398 . stage    - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
399 . classid  - a `PetscClassId`
400 - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return
401              `PETSC_FALSE` for this stage and all events that were associated
402              with this class when they were registered (see
403              `PetscLogStateEventRegister()`).
404 
405   Level: developer
406 
407   Note:
408   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivateClass()` and `PetscLogEventDeactivateClass()`.
409 
410 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateEventSetActive()`
411 @*/
412 PetscErrorCode PetscLogStateClassSetActive(PetscLogState state, PetscLogStage stage, PetscClassId classid, PetscBool isActive)
413 {
414   PetscInt num_events;
415 
416   PetscFunctionBegin;
417   stage = stage < 0 ? state->current_stage : stage;
418   PetscCheck(stage >= 0 && stage < state->bt_num_stages, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", stage, state->bt_num_stages);
419   PetscCall(PetscLogRegistryGetNumEvents(state->registry, &num_events, NULL));
420   for (PetscLogEvent e = 0; e < num_events; e++) {
421     PetscLogEventInfo event_info;
422     PetscCall(PetscLogRegistryEventGetInfo(state->registry, e, &event_info));
423     if (event_info.classid == classid) PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, stage + (e + 1) * state->bt_num_stages));
424   }
425   PetscFunctionReturn(PETSC_SUCCESS);
426 }
427 
428 /*@
429   PetscLogStateClassSetActiveAll - Set logging events associated with an event as active or inactive for all logging stages
430 
431   Not collective
432 
433   Input Parameters:
434 + state    - a `PetscLogState`
435 . classid  - a `PetscClassId`
436 - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return
437              `PETSC_FALSE` for all events that were associated with this class when they
438              were registered (see `PetscLogStateEventRegister()`).
439 
440   Level: developer
441 
442   Note:
443   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventIncludeClass()` and `PetscLogEventExcludeClass()`.
444 
445 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateClassSetActive()`
446 @*/
447 PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState state, PetscClassId classid, PetscBool isActive)
448 {
449   PetscInt num_events, num_stages;
450 
451   PetscFunctionBegin;
452   PetscCall(PetscLogRegistryGetNumEvents(state->registry, &num_events, NULL));
453   PetscCall(PetscLogRegistryGetNumStages(state->registry, &num_stages, NULL));
454   for (PetscLogEvent e = 0; e < num_events; e++) {
455     PetscLogEventInfo event_info;
456     PetscCall(PetscLogRegistryEventGetInfo(state->registry, e, &event_info));
457     if (event_info.classid == classid) {
458       for (PetscLogStage s = 0; s < num_stages; s++) { PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, s + (e + 1) * state->bt_num_stages)); }
459     }
460   }
461   PetscFunctionReturn(PETSC_SUCCESS);
462 }
463 
464 /*@
465   PetscLogStateEventGetActive - Check if a logging event is active or inactive during a logging stage.
466 
467   Not collective
468 
469   Input Parameters:
470 + state - a `PetscLogState`
471 . stage - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
472 - event - a registered `PetscLogEvent`
473 
474   Output Parameter:
475 . isActive - If `PETSC_FALSE`, log handlers should not be notified of the event's beginning or end.
476 
477   Level: developer
478 
479   Note:
480   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventGetActive()`, where it has significance
481   for what information is sent to log handlers.
482 
483 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogHandler()`
484 @*/
485 PetscErrorCode PetscLogStateEventGetActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event, PetscBool *isActive)
486 {
487   PetscFunctionBegin;
488   stage = (stage < 0) ? state->current_stage : stage;
489   PetscCheck(event >= 0 && event < state->bt_num_events, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid event %d should be in [0,%d)", event, state->bt_num_events);
490   PetscCheck(stage >= 0 && stage < state->bt_num_stages, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", event, state->bt_num_stages);
491   *isActive = PetscLogStateStageEventIsActive(state, stage, event) ? PETSC_TRUE : PETSC_FALSE;
492   PetscFunctionReturn(PETSC_SUCCESS);
493 }
494 
495 /*@
496   PetscLogStateGetEventFromName - Get a `PetscLogEvent` from the name it was registered with.
497 
498   Not collective
499 
500   Input Parameters:
501 + state - a `PetscLogState`
502 - name  - an event's name
503 
504   Output Parameter:
505 . event - the event's id
506 
507   Level: developer
508 
509 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateEventGetInfo()`
510 @*/
511 PetscErrorCode PetscLogStateGetEventFromName(PetscLogState state, const char name[], PetscLogEvent *event)
512 {
513   PetscFunctionBegin;
514   PetscCall(PetscLogRegistryGetEventFromName(state->registry, name, event));
515   PetscFunctionReturn(PETSC_SUCCESS);
516 }
517 
518 /*@C
519   PetscLogStateGetStageFromName - Get a `PetscLogStage` from the name it was registered with.
520 
521   Not collective
522 
523   Input Parameters:
524 + state - a `PetscLogState`
525 - name  - a stage's name
526 
527   Output Parameter:
528 . stage - the stage's id
529 
530   Level: developer
531 
532 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStageGetInfo()`
533 @*/
534 PetscErrorCode PetscLogStateGetStageFromName(PetscLogState state, const char name[], PetscLogStage *stage)
535 {
536   PetscFunctionBegin;
537   PetscCall(PetscLogRegistryGetStageFromName(state->registry, name, stage));
538   PetscFunctionReturn(PETSC_SUCCESS);
539 }
540 
541 /*@C
542   PetscLogStateGetClassFromName - Get a `PetscLogClass` from the name of the class it was registered with.
543 
544   Not collective
545 
546   Input Parameters:
547 + state - a `PetscLogState`
548 - name  - the name string of the class
549 
550   Output Parameter:
551 . clss - the classes's logging id
552 
553   Level: developer
554 
555 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
556 @*/
557 PetscErrorCode PetscLogStateGetClassFromName(PetscLogState state, const char name[], PetscLogClass *clss)
558 {
559   PetscFunctionBegin;
560   PetscCall(PetscLogRegistryGetClassFromName(state->registry, name, clss));
561   PetscFunctionReturn(PETSC_SUCCESS);
562 }
563 
564 /*@
565   PetscLogStateGetClassFromClassId - Get a `PetscLogClass` from the `PetscClassId` it was registered with.
566 
567   Not collective
568 
569   Input Parameters:
570 + state   - a `PetscLogState`
571 - classid - a `PetscClassId`
572 
573   Output Parameter:
574 . clss - the classes's logging id
575 
576   Level: developer
577 
578 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
579 @*/
580 PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState state, PetscClassId classid, PetscLogClass *clss)
581 {
582   PetscFunctionBegin;
583   PetscCall(PetscLogRegistryGetClassFromClassId(state->registry, classid, clss));
584   PetscFunctionReturn(PETSC_SUCCESS);
585 }
586 
587 /*@
588   PetscLogStateGetNumEvents - Get the number of registered events in a logging state.
589 
590   Not collective
591 
592   Input Parameter:
593 . state - a `PetscLogState`
594 
595   Output Parameter:
596 . numEvents - the number of registered `PetscLogEvent`s
597 
598   Level: developer
599 
600 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`
601 @*/
602 PetscErrorCode PetscLogStateGetNumEvents(PetscLogState state, PetscInt *numEvents)
603 {
604   PetscFunctionBegin;
605   PetscCall(PetscLogRegistryGetNumEvents(state->registry, numEvents, NULL));
606   PetscFunctionReturn(PETSC_SUCCESS);
607 }
608 
609 /*@
610   PetscLogStateGetNumStages - Get the number of registered stages in a logging state.
611 
612   Not collective
613 
614   Input Parameter:
615 . state - a `PetscLogState`
616 
617   Output Parameter:
618 . numStages - the number of registered `PetscLogStage`s
619 
620   Level: developer
621 
622 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`
623 @*/
624 PetscErrorCode PetscLogStateGetNumStages(PetscLogState state, PetscInt *numStages)
625 {
626   PetscFunctionBegin;
627   PetscCall(PetscLogRegistryGetNumStages(state->registry, numStages, NULL));
628   PetscFunctionReturn(PETSC_SUCCESS);
629 }
630 
631 /*@
632   PetscLogStateGetNumClasses - Get the number of registered classes in a logging state.
633 
634   Not collective
635 
636   Input Parameter:
637 . state - a `PetscLogState`
638 
639   Output Parameter:
640 . numClasses - the number of registered `PetscLogClass`s
641 
642   Level: developer
643 
644 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`
645 @*/
646 PetscErrorCode PetscLogStateGetNumClasses(PetscLogState state, PetscInt *numClasses)
647 {
648   PetscFunctionBegin;
649   PetscCall(PetscLogRegistryGetNumClasses(state->registry, numClasses, NULL));
650   PetscFunctionReturn(PETSC_SUCCESS);
651 }
652 
653 /*@
654   PetscLogStateEventGetInfo - Get the registration information of an event
655 
656   Not collective
657 
658   Input Parameters:
659 + state - a `PetscLogState`
660 - event - a registered `PetscLogEvent`
661 
662   Output Parameter:
663 . info - the `PetscLogEventInfo` of the event will be copied into info
664 
665   Level: developer
666 
667 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateGetEventFromName()`
668 @*/
669 PetscErrorCode PetscLogStateEventGetInfo(PetscLogState state, PetscLogEvent event, PetscLogEventInfo *info)
670 {
671   PetscFunctionBegin;
672   PetscCall(PetscLogRegistryEventGetInfo(state->registry, event, info));
673   PetscFunctionReturn(PETSC_SUCCESS);
674 }
675 
676 /*@
677   PetscLogStateStageGetInfo - Get the registration information of an stage
678 
679   Not collective
680 
681   Input Parameters:
682 + state - a `PetscLogState`
683 - stage - a registered `PetscLogStage`
684 
685   Output Parameter:
686 . info - the `PetscLogStageInfo` of the stage will be copied into info
687 
688   Level: developer
689 
690 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateGetStageFromName()`
691 @*/
692 PetscErrorCode PetscLogStateStageGetInfo(PetscLogState state, PetscLogStage stage, PetscLogStageInfo *info)
693 {
694   PetscFunctionBegin;
695   PetscCall(PetscLogRegistryStageGetInfo(state->registry, stage, info));
696   PetscFunctionReturn(PETSC_SUCCESS);
697 }
698 
699 /*@
700   PetscLogStateClassRegister - Register a class to with a `PetscLogState` used by `PetscLogHandler`s.
701 
702   Logically collective on `PETSC_COMM_WORLD`
703 
704   Input Parameters:
705 + state - a `PetscLogState`
706 . name  - the name of a class registered with `PetscClassIdRegister()`
707 - id    - the `PetscClassId` obtained from `PetscClassIdRegister()`
708 
709   Output Parameter:
710 . logclass - a `PetscLogClass` for this class with this state
711 
712   Level: developer
713 
714   Note:
715   Classes are automatically registered with PETSc's global logging state (`PetscLogGetState()`), so this
716   is only needed for non-global states.
717 
718 .seealso: [](ch_profiling), `PetscLogStateClassGetInfo()` `PetscLogStateGetClassFromName()`, `PetscLogStateGetClassFromClassId()`
719 @*/
720 PetscErrorCode PetscLogStateClassRegister(PetscLogState state, const char name[], PetscClassId id, PetscLogClass *logclass)
721 {
722   PetscFunctionBegin;
723   PetscCall(PetscLogRegistryClassRegister(state->registry, name, id, logclass));
724   PetscFunctionReturn(PETSC_SUCCESS);
725 }
726 
727 /*@
728   PetscLogStateClassGetInfo - Get the registration information of an class
729 
730   Not collective
731 
732   Input Parameters:
733 + state - a `PetscLogState`
734 - clss  - a registered `PetscLogClass`
735 
736   Output Parameter:
737 . info - the `PetscLogClassInfo` of the class will be copied into info
738 
739   Level: developer
740 
741 .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateGetClassFromName()`
742 @*/
743 PetscErrorCode PetscLogStateClassGetInfo(PetscLogState state, PetscLogClass clss, PetscLogClassInfo *info)
744 {
745   PetscFunctionBegin;
746   PetscCall(PetscLogRegistryClassGetInfo(state->registry, clss, info));
747   PetscFunctionReturn(PETSC_SUCCESS);
748 }
749