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