Actual source code: logstate.c
1: #include <petsc/private/logimpl.h>
3: /*@
4: PetscLogStateCreate - Create a logging state.
6: Not collective
8: Output Parameters:
9: . state - a `PetscLogState`
11: Level: developer
13: Note:
14: Most users will not need to create a `PetscLogState`. The global state `PetscLogState()`
15: is created in `PetscInitialize()`.
17: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateDestroy()`
18: @*/
19: PetscErrorCode PetscLogStateCreate(PetscLogState *state)
20: {
21: PetscInt num_entries, max_events, max_stages;
22: PetscLogState s;
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));
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: }
41: /*@
42: PetscLogStateDestroy - Destroy a logging state.
44: Not collective
46: Input Parameters:
47: . state - a `PetscLogState`
49: Level: developer
51: Note:
52: Most users will not need to destroy a `PetscLogState`. The global state `PetscLogState()`
53: is destroyed in `PetscFinalize()`.
55: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateCreate()`
56: @*/
57: PetscErrorCode PetscLogStateDestroy(PetscLogState *state)
58: {
59: PetscLogState s;
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: }
72: /*@
73: PetscLogStateStagePush - Start a new logging stage.
75: Not collective
77: Input Parameters:
78: + state - a `PetscLogState`
79: - stage - a registered `PetscLogStage`
81: Level: developer
83: Note:
84: This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.
86: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePop()`, `PetscLogStateGetCurrentStage()`
87: @*/
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: }
101: /*@
102: PetscLogStateStagePop - End a running logging stage.
104: Not collective
106: Input Parameter:
107: . state - a `PetscLogState`
109: Level: developer
111: Note:
112: This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.
114: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePush()`, `PetscLogStateGetCurrentStage()`
115: @*/
116: PetscErrorCode PetscLogStateStagePop(PetscLogState state)
117: {
118: int curStage;
119: PetscBool empty;
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: }
129: /*@
130: PetscLogStateGetCurrentStage - Get the last stage that was started
132: Not collective
134: Input Parameter:
135: . state - a `PetscLogState`
137: Output Parameter:
138: . current - the last `PetscLogStage` started with `PetscLogStateStagePop()`
140: Level: developer
142: Note:
143: This is called for the global state (`PetscLogGetState()`) in `PetscLogGetCurrentStage()`.
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: }
154: static PetscErrorCode PetscLogStateResize(PetscLogState state)
155: {
156: PetscBT active_new;
157: PetscInt new_num_events;
158: PetscInt new_num_stages;
160: PetscFunctionBegin;
161: PetscCall(PetscLogRegistryGetNumEvents(state->registry, NULL, &new_num_events));
162: new_num_events++;
163: PetscCall(PetscLogRegistryGetNumStages(state->registry, NULL, &new_num_stages));
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;
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;
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: }
186: /*@
187: PetscLogStateStageRegister - Register a new stage with a logging state
189: Not collective
191: Input Parameters:
192: + state - a `PetscLogState`
193: - sname - a unique name
195: Output Parameter:
196: . stage - the identifier for the registered stage
198: Level: developer
200: Note:
201: This is called for the global state (`PetscLogGetState()`) in `PetscLogStageRegister()`.
203: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStagePush()`, `PetscLogStateStagePop()`
204: @*/
205: PetscErrorCode PetscLogStateStageRegister(PetscLogState state, const char sname[], PetscLogStage *stage)
206: {
207: PetscInt s;
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)) PetscCall(PetscBTSet(state->active, s + e * state->bt_num_stages));
217: else PetscCall(PetscBTClear(state->active, s + e * state->bt_num_stages));
218: }
219: PetscFunctionReturn(PETSC_SUCCESS);
220: }
222: /*@
223: PetscLogStateEventRegister - Register a new event with a logging state
225: Not collective
227: Input Parameters:
228: + state - a `PetscLogState`
229: . sname - a unique name
230: - id - the `PetscClassId` for the type of object most closely associated with this event
232: Output Parameter:
233: . event - the identifier for the registered event
235: Level: developer
237: Note:
238: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventRegister()`.
240: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageRegister()`
241: @*/
242: PetscErrorCode PetscLogStateEventRegister(PetscLogState state, const char sname[], PetscClassId id, PetscLogEvent *event)
243: {
244: PetscInt e;
246: PetscFunctionBegin;
247: *event = PETSC_DECIDE;
248: PetscCall(PetscLogRegistryGetEventFromName(state->registry, sname, event));
249: if (*event > 0) PetscFunctionReturn(PETSC_SUCCESS);
250: PetscCall(PetscLogRegistryEventRegister(state->registry, sname, id, event));
251: PetscCall(PetscLogStateResize(state));
252: e = *event;
253: 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
254: PetscFunctionReturn(PETSC_SUCCESS);
255: }
257: /*@
258: PetscLogStateEventSetCollective - Set the collective nature of a logging event
260: Logically collective
262: Input Parameters:
263: + state - a `PetscLogState`
264: . event - a registered `PetscLogEvent`
265: - 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
267: Level: developer
269: Note:
270: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetCollective()`.
272: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventRegister()`
273: @*/
274: PetscErrorCode PetscLogStateEventSetCollective(PetscLogState state, PetscLogEvent event, PetscBool collective)
275: {
276: PetscFunctionBegin;
277: PetscCall(PetscLogRegistryEventSetCollective(state->registry, event, collective));
278: PetscFunctionReturn(PETSC_SUCCESS);
279: }
281: /*@
282: PetscLogStateStageSetActive - Mark a stage as active or inactive.
284: Not collective
286: Input Parameters:
287: + state - a `PetscLogState`
288: . stage - a registered `PetscLogStage`
289: - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for all events during this stage
291: Level: developer
293: Note:
294: This is called for the global state (`PetscLogGetState()`) in `PetscLogStageSetActive()`
296: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventSetActive()`
297: @*/
298: PetscErrorCode PetscLogStateStageSetActive(PetscLogState state, PetscLogStage stage, PetscBool isActive)
299: {
300: PetscFunctionBegin;
301: 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);
302: if (isActive) {
303: for (PetscInt e = 0; e < state->bt_num_events; e++) PetscCall(PetscBTSet(state->active, stage + e * state->bt_num_stages));
304: } else {
305: for (PetscInt e = 0; e < state->bt_num_events; e++) PetscCall(PetscBTClear(state->active, stage + e * state->bt_num_stages));
306: }
307: PetscFunctionReturn(PETSC_SUCCESS);
308: }
310: /*@
311: PetscLogStateStageGetActive - Check if a logging stage is active or inactive.
313: Not collective
315: Input Parameters:
316: + state - a `PetscLogState`
317: - stage - a registered `PetscLogStage`
319: Output Parameter:
320: . isActive - if `PETSC_FALSE`, the state should not send logging events to log handlers during this stage.
322: Level: developer
324: Note:
325: This is called for the global state (`PetscLogGetState()`) in `PetscLogStageGetActive()`.
327: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageSetActive()`, `PetscLogHandler`, `PetscLogHandlerStart()`, `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`
328: @*/
329: PetscErrorCode PetscLogStateStageGetActive(PetscLogState state, PetscLogStage stage, PetscBool *isActive)
330: {
331: PetscFunctionBegin;
332: *isActive = PetscBTLookup(state->active, stage) ? PETSC_TRUE : PETSC_FALSE;
333: PetscFunctionReturn(PETSC_SUCCESS);
334: }
336: /*@
337: PetscLogStateEventSetActive - Set a logging event as active or inactive during a logging stage.
339: Not collective
341: Input Parameters:
342: + state - a `PetscLogState`
343: . stage - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
344: . event - a registered `PetscLogEvent`
345: - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for this stage and this event
347: Level: developer
349: Note:
350: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivate()` and `PetscLogEventDeactivate()`.
352: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogEventSetActiveAll()`
353: @*/
354: PetscErrorCode PetscLogStateEventSetActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event, PetscBool isActive)
355: {
356: PetscFunctionBegin;
357: stage = (stage < 0) ? state->current_stage : stage;
358: 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);
359: 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);
360: PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, state->current_stage + (event + 1) * state->bt_num_stages));
361: PetscFunctionReturn(PETSC_SUCCESS);
362: }
364: /*@
365: PetscLogStateEventSetActiveAll - Set logging event as active or inactive for all logging stages
367: Not collective
369: Input Parameters:
370: + state - a `PetscLogState`
371: . event - a registered `PetscLogEvent`
372: - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return `PETSC_FALSE` for all stages and all events
374: Level: developer
376: Note:
377: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetActiveAll()`.
379: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`
380: @*/
381: PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState state, PetscLogEvent event, PetscBool isActive)
382: {
383: PetscFunctionBegin;
384: 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);
385: 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));
386: PetscFunctionReturn(PETSC_SUCCESS);
387: }
389: /*@
390: PetscLogStateClassSetActive - Set logging events associated with an event as active or inactive during a logging stage.
392: Not collective
394: Input Parameters:
395: + state - a `PetscLogState`
396: . stage - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
397: . classid - a `PetscClassId`
398: - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return
399: `PETSC_FALSE` for this stage and all events that were associated
400: with this class when they were registered (see
401: `PetscLogStateEventRegister()`).
403: Level: developer
405: Note:
406: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivateClass()` and `PetscLogEventDeactivateClass()`.
408: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateEventSetActive()`
409: @*/
410: PetscErrorCode PetscLogStateClassSetActive(PetscLogState state, PetscLogStage stage, PetscClassId classid, PetscBool isActive)
411: {
412: PetscInt num_events;
414: PetscFunctionBegin;
415: stage = stage < 0 ? state->current_stage : stage;
416: 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);
417: PetscCall(PetscLogRegistryGetNumEvents(state->registry, &num_events, NULL));
418: for (PetscLogEvent e = 0; e < num_events; e++) {
419: PetscLogEventInfo event_info;
420: PetscCall(PetscLogRegistryEventGetInfo(state->registry, e, &event_info));
421: if (event_info.classid == classid) PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, stage + (e + 1) * state->bt_num_stages));
422: }
423: PetscFunctionReturn(PETSC_SUCCESS);
424: }
426: /*@
427: PetscLogStateClassSetActiveAll - Set logging events associated with an event as active or inactive for all logging stages
429: Not collective
431: Input Parameters:
432: + state - a `PetscLogState`
433: . classid - a `PetscClassId`
434: - isActive - if `PETSC_FALSE`, `PetscLogStateEventGetActive()` will return
435: `PETSC_FALSE` for all events that were associated with this class when they
436: were registered (see `PetscLogStateEventRegister()`).
438: Level: developer
440: Note:
441: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventIncludeClass()` and `PetscLogEventExcludeClass()`.
443: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateClassSetActive()`
444: @*/
445: PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState state, PetscClassId classid, PetscBool isActive)
446: {
447: PetscInt num_events, num_stages;
449: PetscFunctionBegin;
450: PetscCall(PetscLogRegistryGetNumEvents(state->registry, &num_events, NULL));
451: PetscCall(PetscLogRegistryGetNumStages(state->registry, &num_stages, NULL));
452: for (PetscLogEvent e = 0; e < num_events; e++) {
453: PetscLogEventInfo event_info;
454: PetscCall(PetscLogRegistryEventGetInfo(state->registry, e, &event_info));
455: if (event_info.classid == classid) {
456: for (PetscLogStage s = 0; s < num_stages; s++) PetscCall((isActive ? PetscBTSet : PetscBTClear)(state->active, s + (e + 1) * state->bt_num_stages));
457: }
458: }
459: PetscFunctionReturn(PETSC_SUCCESS);
460: }
462: /*@
463: PetscLogStateEventGetActive - Check if a logging event is active or inactive during a logging stage.
465: Not collective
467: Input Parameters:
468: + state - a `PetscLogState`
469: . stage - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
470: - event - a registered `PetscLogEvent`
472: Output Parameter:
473: . isActive - If `PETSC_FALSE`, log handlers should not be notified of the event's beginning or end.
475: Level: developer
477: Note:
478: This is called for the global state (`PetscLogGetState()`) in `PetscLogEventGetActive()`, where it has significance
479: for what information is sent to log handlers.
481: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogHandler()`
482: @*/
483: PetscErrorCode PetscLogStateEventGetActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event, PetscBool *isActive)
484: {
485: PetscFunctionBegin;
486: stage = (stage < 0) ? state->current_stage : stage;
487: 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);
488: 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);
489: *isActive = PetscLogStateStageEventIsActive(state, stage, event) ? PETSC_TRUE : PETSC_FALSE;
490: PetscFunctionReturn(PETSC_SUCCESS);
491: }
493: /*@
494: PetscLogStateGetEventFromName - Get a `PetscLogEvent` from the name it was registered with.
496: Not collective
498: Input Parameters:
499: + state - a `PetscLogState`
500: - name - an event's name
502: Output Parameter:
503: . event - the event's id
505: Level: developer
507: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateEventGetInfo()`
508: @*/
509: PetscErrorCode PetscLogStateGetEventFromName(PetscLogState state, const char name[], PetscLogEvent *event)
510: {
511: PetscFunctionBegin;
512: PetscCall(PetscLogRegistryGetEventFromName(state->registry, name, event));
513: PetscFunctionReturn(PETSC_SUCCESS);
514: }
516: /*@
517: PetscLogStateGetStageFromName - Get a `PetscLogStage` from the name it was registered with.
519: Not collective
521: Input Parameters:
522: + state - a `PetscLogState`
523: - name - a stage's name
525: Output Parameter:
526: . stage - the stage's id
528: Level: developer
530: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStageGetInfo()`
531: @*/
532: PetscErrorCode PetscLogStateGetStageFromName(PetscLogState state, const char name[], PetscLogStage *stage)
533: {
534: PetscFunctionBegin;
535: PetscCall(PetscLogRegistryGetStageFromName(state->registry, name, stage));
536: PetscFunctionReturn(PETSC_SUCCESS);
537: }
539: /*@
540: PetscLogStateGetClassFromName - Get a `PetscLogClass` from the name of the class it was registered with.
542: Not collective
544: Input Parameters:
545: + state - a `PetscLogState`
546: - name - the name string of the class
548: Output Parameter:
549: . clss - the classes's logging id
551: Level: developer
553: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
554: @*/
555: PetscErrorCode PetscLogStateGetClassFromName(PetscLogState state, const char name[], PetscLogClass *clss)
556: {
557: PetscFunctionBegin;
558: PetscCall(PetscLogRegistryGetClassFromName(state->registry, name, clss));
559: PetscFunctionReturn(PETSC_SUCCESS);
560: }
562: /*@
563: PetscLogStateGetClassFromClassId - Get a `PetscLogClass` from the `PetscClassId` it was registered with.
565: Not collective
567: Input Parameters:
568: + state - a `PetscLogState`
569: - classid - a `PetscClassId`
571: Output Parameter:
572: . clss - the classes's logging id
574: Level: developer
576: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
577: @*/
578: PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState state, PetscClassId classid, PetscLogClass *clss)
579: {
580: PetscFunctionBegin;
581: PetscCall(PetscLogRegistryGetClassFromClassId(state->registry, classid, clss));
582: PetscFunctionReturn(PETSC_SUCCESS);
583: }
585: /*@
586: PetscLogStateGetNumEvents - Get the number of registered events in a logging state.
588: Not collective
590: Input Parameter:
591: . state - a `PetscLogState`
593: Output Parameter:
594: . numEvents - the number of registered `PetscLogEvent`s
596: Level: developer
598: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`
599: @*/
600: PetscErrorCode PetscLogStateGetNumEvents(PetscLogState state, PetscInt *numEvents)
601: {
602: PetscFunctionBegin;
603: PetscCall(PetscLogRegistryGetNumEvents(state->registry, numEvents, NULL));
604: PetscFunctionReturn(PETSC_SUCCESS);
605: }
607: /*@
608: PetscLogStateGetNumStages - Get the number of registered stages in a logging state.
610: Not collective
612: Input Parameter:
613: . state - a `PetscLogState`
615: Output Parameter:
616: . numStages - the number of registered `PetscLogStage`s
618: Level: developer
620: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`
621: @*/
622: PetscErrorCode PetscLogStateGetNumStages(PetscLogState state, PetscInt *numStages)
623: {
624: PetscFunctionBegin;
625: PetscCall(PetscLogRegistryGetNumStages(state->registry, numStages, NULL));
626: PetscFunctionReturn(PETSC_SUCCESS);
627: }
629: /*@
630: PetscLogStateGetNumClasses - Get the number of registered classes in a logging state.
632: Not collective
634: Input Parameter:
635: . state - a `PetscLogState`
637: Output Parameter:
638: . numClasses - the number of registered `PetscLogClass`s
640: Level: developer
642: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`
643: @*/
644: PetscErrorCode PetscLogStateGetNumClasses(PetscLogState state, PetscInt *numClasses)
645: {
646: PetscFunctionBegin;
647: PetscCall(PetscLogRegistryGetNumClasses(state->registry, numClasses, NULL));
648: PetscFunctionReturn(PETSC_SUCCESS);
649: }
651: /*@
652: PetscLogStateEventGetInfo - Get the registration information of an event
654: Not collective
656: Input Parameters:
657: + state - a `PetscLogState`
658: - event - a registered `PetscLogEvent`
660: Output Parameter:
661: . info - the `PetscLogEventInfo` of the event will be copied into info
663: Level: developer
665: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateGetEventFromName()`
666: @*/
667: PetscErrorCode PetscLogStateEventGetInfo(PetscLogState state, PetscLogEvent event, PetscLogEventInfo *info)
668: {
669: PetscFunctionBegin;
670: PetscCall(PetscLogRegistryEventGetInfo(state->registry, event, info));
671: PetscFunctionReturn(PETSC_SUCCESS);
672: }
674: /*@
675: PetscLogStateStageGetInfo - Get the registration information of an stage
677: Not collective
679: Input Parameters:
680: + state - a `PetscLogState`
681: - stage - a registered `PetscLogStage`
683: Output Parameter:
684: . info - the `PetscLogStageInfo` of the stage will be copied into info
686: Level: developer
688: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateGetStageFromName()`
689: @*/
690: PetscErrorCode PetscLogStateStageGetInfo(PetscLogState state, PetscLogStage stage, PetscLogStageInfo *info)
691: {
692: PetscFunctionBegin;
693: PetscCall(PetscLogRegistryStageGetInfo(state->registry, stage, info));
694: PetscFunctionReturn(PETSC_SUCCESS);
695: }
697: /*@
698: PetscLogStateClassRegister - Register a class to with a `PetscLogState` used by `PetscLogHandler`s.
700: Logically collective on `PETSC_COMM_WORLD`
702: Input Parameters:
703: + state - a `PetscLogState`
704: . name - the name of a class registered with `PetscClassIdRegister()`
705: - id - the `PetscClassId` obtained from `PetscClassIdRegister()`
707: Output Parameter:
708: . logclass - a `PetscLogClass` for this class with this state
710: Level: developer
712: Note:
713: Classes are automatically registered with PETSc's global logging state (`PetscLogGetState()`), so this
714: is only needed for non-global states.
716: .seealso: [](ch_profiling), `PetscLogStateClassGetInfo()`, `PetscLogStateGetClassFromName()`, `PetscLogStateGetClassFromClassId()`
717: @*/
718: PetscErrorCode PetscLogStateClassRegister(PetscLogState state, const char name[], PetscClassId id, PetscLogClass *logclass)
719: {
720: PetscFunctionBegin;
721: PetscCall(PetscLogRegistryClassRegister(state->registry, name, id, logclass));
722: PetscFunctionReturn(PETSC_SUCCESS);
723: }
725: /*@
726: PetscLogStateClassGetInfo - Get the registration information of an class
728: Not collective
730: Input Parameters:
731: + state - a `PetscLogState`
732: - clss - a registered `PetscLogClass`
734: Output Parameter:
735: . info - the `PetscLogClassInfo` of the class will be copied into info
737: Level: developer
739: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateGetClassFromName()`
740: @*/
741: PetscErrorCode PetscLogStateClassGetInfo(PetscLogState state, PetscLogClass clss, PetscLogClassInfo *info)
742: {
743: PetscFunctionBegin;
744: PetscCall(PetscLogRegistryClassGetInfo(state->registry, clss, info));
745: PetscFunctionReturn(PETSC_SUCCESS);
746: }