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

 71: /*@
 72:   PetscLogStateStagePush - Start a new logging stage.

 74:   Not collective

 76:   Input Parameters:
 77: + state - a `PetscLogState`
 78: - stage - a registered `PetscLogStage`

 80:   Level: developer

 82:   Note:
 83:   This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.

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

100: /*@
101:   PetscLogStateStagePop - End a running logging stage.

103:   Not collective

105:   Input Parameter:
106: . state - a `PetscLogState`

108:   Level: developer

110:   Note:
111:   This is called for the global state (`PetscLogGetState()`) in `PetscLogStagePush()`.

113: .seealso: [](ch_profiling), `PetscLogState`, `PetscLogStateStageRegister()`, `PetscLogStateStagePush()`, `PetscLogStateGetCurrentStage()`
114: @*/
115: PetscErrorCode PetscLogStateStagePop(PetscLogState state)
116: {
117:   int       curStage;
118:   PetscBool empty;

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

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: /*@C
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;
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: }

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

227:   Not collective

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

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

237:   Level: developer

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

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

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

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

262:   Logically collective

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

269:   Level: developer

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

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

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

286:   Not collective

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

293:   Level: developer

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

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

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

315:   Not collective

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

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

324:   Level: developer

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

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

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

341:   Not collective

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

349:   Level: developer

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

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

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

369:   Not collective

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

376:   Level: developer

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

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

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

394:   Not collective

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

405:   Level: developer

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

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

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

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

431:   Not collective

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

440:   Level: developer

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

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

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

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

467:   Not collective

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

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

477:   Level: developer

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.

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

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

498:   Not collective

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

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

507:   Level: developer

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

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

521:   Not collective

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

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

530:   Level: developer

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

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

544:   Not collective

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

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

553:   Level: developer

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

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

567:   Not collective

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

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

576:   Level: developer

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

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

590:   Not collective

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

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

598:   Level: developer

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

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

612:   Not collective

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

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

620:   Level: developer

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

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

634:   Not collective

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

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

642:   Level: developer

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

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

656:   Not collective

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

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

665:   Level: developer

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

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

679:   Not collective

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

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

688:   Level: developer

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

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

702:   Logically collective on `PETSC_COMM_WORLD`

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

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

712:   Level: developer

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

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

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

730:   Not collective

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

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

739:   Level: developer

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