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:   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: }

 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:   state->bt_num_events = new_num_events;
182:   state->bt_num_stages = new_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)) {
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: }

225: /*@
226:   PetscLogStateEventRegister - Register a new event with a logging state

228:   Not collective

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

235:   Output Parameter:
236: . event - the identifier for the registered event

238:   Level: developer

240:   Note:
241:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventRegister()`.

243: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageRegister()`
244: @*/
245: PetscErrorCode PetscLogStateEventRegister(PetscLogState state, const char sname[], PetscClassId id, PetscLogEvent *event)
246: {
247:   PetscInt e;

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: }

260: /*@
261:   PetscLogStateEventSetCollective - Set the collective nature of a logging event

263:   Logically collective

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

270:   Level: developer

272:   Note:
273:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetCollective()`.

275: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventRegister()`
276: @*/
277: PetscErrorCode PetscLogStateEventSetCollective(PetscLogState state, PetscLogEvent event, PetscBool collective)
278: {
279:   PetscFunctionBegin;
280:   PetscCall(PetscLogRegistryEventSetCollective(state->registry, event, collective));
281:   PetscFunctionReturn(PETSC_SUCCESS);
282: }

284: /*@
285:   PetscLogStateStageSetActive - Mark a stage as active or inactive.

287:   Not collective

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

294:   Level: developer

296:   Note:
297:   This is called for the global state (`PetscLogGetState()`) in `PetscLogStageSetActive()`

299: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventSetActive()`
300: @*/
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: }

313: /*@
314:   PetscLogStateStageGetActive - Check if a logging stage is active or inactive.

316:   Not collective

318:   Input Parameters:
319: + state - a `PetscLogState`
320: - stage - a registered `PetscLogStage`

322:   Output Parameter:
323: . isActive - if `PETSC_FALSE`, the state should not send logging events to log handlers during this stage.

325:   Level: developer

327:   Note:
328:   This is called for the global state (`PetscLogGetState()`) in `PetscLogStageGetActive()`.

330: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStageSetActive()`, `PetscLogHandler`, `PetscLogHandlerStart()`, `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`
331: @*/
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: }

339: /*@
340:   PetscLogStateEventSetActive - Set a logging event as active or inactive during a logging stage.

342:   Not collective

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

350:   Level: developer

352:   Note:
353:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivate()` and `PetscLogEventDeactivate()`.

355: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogEventSetActiveAll()`
356: @*/
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: }

367: /*@
368:   PetscLogStateEventSetActiveAll - Set logging event as active or inactive for all logging stages

370:   Not collective

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

377:   Level: developer

379:   Note:
380:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventSetActiveAll()`.

382: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`
383: @*/
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: }

392: /*@
393:   PetscLogStateClassSetActive - Set logging events associated with an event as active or inactive during a logging stage.

395:   Not collective

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()`).

406:   Level: developer

408:   Note:
409:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventActivateClass()` and `PetscLogEventDeactivateClass()`.

411: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateEventSetActive()`
412: @*/
413: PetscErrorCode PetscLogStateClassSetActive(PetscLogState state, PetscLogStage stage, PetscClassId classid, PetscBool isActive)
414: {
415:   PetscInt num_events;

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: }

429: /*@
430:   PetscLogStateClassSetActiveAll - Set logging events associated with an event as active or inactive for all logging stages

432:   Not collective

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()`).

441:   Level: developer

443:   Note:
444:   This is called for the global state (`PetscLogGetState()`) in `PetscLogEventIncludeClass()` and `PetscLogEventExcludeClass()`.

446: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateClassSetActive()`
447: @*/
448: PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState state, PetscClassId classid, PetscBool isActive)
449: {
450:   PetscInt num_events, num_stages;

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: }

465: /*@
466:   PetscLogStateEventGetActive - Check if a logging event is active or inactive during a logging stage.

468:   Not collective

470:   Input Parameters:
471: + state - a `PetscLogState`
472: . stage - a registered `PetscLogStage`, or `PETSC_DEFAULT` for the current stage
473: - event - a registered `PetscLogEvent`

475:   Output Parameter:
476: . isActive - If `PETSC_FALSE`, log handlers should not be notified of the event's beginning or end.

478:   Level: developer

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.

484: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogEventGetActive()`, `PetscLogStateGetCurrentStage()`, `PetscLogHandler()`
485: @*/
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: }

496: /*@
497:   PetscLogStateGetEventFromName - Get a `PetscLogEvent` from the name it was registered with.

499:   Not collective

501:   Input Parameters:
502: + state - a `PetscLogState`
503: - name  - an event's name

505:   Output Parameter:
506: . event - the event's id

508:   Level: developer

510: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateEventGetInfo()`
511: @*/
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: }

519: /*@
520:   PetscLogStateGetStageFromName - Get a `PetscLogStage` from the name it was registered with.

522:   Not collective

524:   Input Parameters:
525: + state - a `PetscLogState`
526: - name  - a stage's name

528:   Output Parameter:
529: . stage - the stage's id

531:   Level: developer

533: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStageGetInfo()`
534: @*/
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: }

542: /*@
543:   PetscLogStateGetClassFromName - Get a `PetscLogClass` from the name of the class it was registered with.

545:   Not collective

547:   Input Parameters:
548: + state - a `PetscLogState`
549: - name  - the name string of the class

551:   Output Parameter:
552: . clss - the classes's logging id

554:   Level: developer

556: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
557: @*/
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: }

565: /*@
566:   PetscLogStateGetClassFromClassId - Get a `PetscLogClass` from the `PetscClassId` it was registered with.

568:   Not collective

570:   Input Parameters:
571: + state   - a `PetscLogState`
572: - classid - a `PetscClassId`

574:   Output Parameter:
575: . clss - the classes's logging id

577:   Level: developer

579: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateClassGetInfo()`
580: @*/
581: PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState state, PetscClassId classid, PetscLogClass *clss)
582: {
583:   PetscFunctionBegin;
584:   PetscCall(PetscLogRegistryGetClassFromClassId(state->registry, classid, clss));
585:   PetscFunctionReturn(PETSC_SUCCESS);
586: }

588: /*@
589:   PetscLogStateGetNumEvents - Get the number of registered events in a logging state.

591:   Not collective

593:   Input Parameter:
594: . state - a `PetscLogState`

596:   Output Parameter:
597: . numEvents - the number of registered `PetscLogEvent`s

599:   Level: developer

601: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`
602: @*/
603: PetscErrorCode PetscLogStateGetNumEvents(PetscLogState state, PetscInt *numEvents)
604: {
605:   PetscFunctionBegin;
606:   PetscCall(PetscLogRegistryGetNumEvents(state->registry, numEvents, NULL));
607:   PetscFunctionReturn(PETSC_SUCCESS);
608: }

610: /*@
611:   PetscLogStateGetNumStages - Get the number of registered stages in a logging state.

613:   Not collective

615:   Input Parameter:
616: . state - a `PetscLogState`

618:   Output Parameter:
619: . numStages - the number of registered `PetscLogStage`s

621:   Level: developer

623: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`
624: @*/
625: PetscErrorCode PetscLogStateGetNumStages(PetscLogState state, PetscInt *numStages)
626: {
627:   PetscFunctionBegin;
628:   PetscCall(PetscLogRegistryGetNumStages(state->registry, numStages, NULL));
629:   PetscFunctionReturn(PETSC_SUCCESS);
630: }

632: /*@
633:   PetscLogStateGetNumClasses - Get the number of registered classes in a logging state.

635:   Not collective

637:   Input Parameter:
638: . state - a `PetscLogState`

640:   Output Parameter:
641: . numClasses - the number of registered `PetscLogClass`s

643:   Level: developer

645: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`
646: @*/
647: PetscErrorCode PetscLogStateGetNumClasses(PetscLogState state, PetscInt *numClasses)
648: {
649:   PetscFunctionBegin;
650:   PetscCall(PetscLogRegistryGetNumClasses(state->registry, numClasses, NULL));
651:   PetscFunctionReturn(PETSC_SUCCESS);
652: }

654: /*@
655:   PetscLogStateEventGetInfo - Get the registration information of an event

657:   Not collective

659:   Input Parameters:
660: + state - a `PetscLogState`
661: - event - a registered `PetscLogEvent`

663:   Output Parameter:
664: . info - the `PetscLogEventInfo` of the event will be copied into info

666:   Level: developer

668: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateEventRegister()`, `PetscLogStateGetEventFromName()`
669: @*/
670: PetscErrorCode PetscLogStateEventGetInfo(PetscLogState state, PetscLogEvent event, PetscLogEventInfo *info)
671: {
672:   PetscFunctionBegin;
673:   PetscCall(PetscLogRegistryEventGetInfo(state->registry, event, info));
674:   PetscFunctionReturn(PETSC_SUCCESS);
675: }

677: /*@
678:   PetscLogStateStageGetInfo - Get the registration information of an stage

680:   Not collective

682:   Input Parameters:
683: + state - a `PetscLogState`
684: - stage - a registered `PetscLogStage`

686:   Output Parameter:
687: . info - the `PetscLogStageInfo` of the stage will be copied into info

689:   Level: developer

691: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateGetStageFromName()`
692: @*/
693: PetscErrorCode PetscLogStateStageGetInfo(PetscLogState state, PetscLogStage stage, PetscLogStageInfo *info)
694: {
695:   PetscFunctionBegin;
696:   PetscCall(PetscLogRegistryStageGetInfo(state->registry, stage, info));
697:   PetscFunctionReturn(PETSC_SUCCESS);
698: }

700: /*@
701:   PetscLogStateClassRegister - Register a class to with a `PetscLogState` used by `PetscLogHandler`s.

703:   Logically collective on `PETSC_COMM_WORLD`

705:   Input Parameters:
706: + state - a `PetscLogState`
707: . name  - the name of a class registered with `PetscClassIdRegister()`
708: - id    - the `PetscClassId` obtained from `PetscClassIdRegister()`

710:   Output Parameter:
711: . logclass - a `PetscLogClass` for this class with this state

713:   Level: developer

715:   Note:
716:   Classes are automatically registered with PETSc's global logging state (`PetscLogGetState()`), so this
717:   is only needed for non-global states.

719: .seealso: [](ch_profiling), `PetscLogStateClassGetInfo()` `PetscLogStateGetClassFromName()`, `PetscLogStateGetClassFromClassId()`
720: @*/
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: }

728: /*@
729:   PetscLogStateClassGetInfo - Get the registration information of an class

731:   Not collective

733:   Input Parameters:
734: + state - a `PetscLogState`
735: - clss  - a registered `PetscLogClass`

737:   Output Parameter:
738: . info - the `PetscLogClassInfo` of the class will be copied into info

740:   Level: developer

742: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateClassRegister()`, `PetscLogStateGetClassFromName()`
743: @*/
744: PetscErrorCode PetscLogStateClassGetInfo(PetscLogState state, PetscLogClass clss, PetscLogClassInfo *info)
745: {
746:   PetscFunctionBegin;
747:   PetscCall(PetscLogRegistryClassGetInfo(state->registry, clss, info));
748:   PetscFunctionReturn(PETSC_SUCCESS);
749: }