1 #include <petscviewer.h>
2 #include <petsc/private/logimpl.h> /*I "petscsys.h" I*/
3 #include <petsc/private/loghandlerimpl.h>
4 #include <petsc/private/petscimpl.h>
5
6 /*@
7 PetscLogHandlerCreate - Create a log handler for profiling events and stages. PETSc
8 provides several implementations of `PetscLogHandler` that interface to different ways to
9 summarize or visualize profiling data: see `PetscLogHandlerType` for a list.
10
11 Collective
12
13 Input Parameter:
14 . comm - the communicator for synchronizing and viewing events with this handler
15
16 Output Parameter:
17 . handler - the `PetscLogHandler`
18
19 Level: developer
20
21 Notes:
22 This does not put the handler in use in PETSc's global logging system: use `PetscLogHandlerStart()` after creation.
23
24 See `PetscLogHandler` for example usage.
25
26 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerSetType()`, `PetscLogHandlerStart()`, `PetscLogHandlerStop()`
27 @*/
PetscLogHandlerCreate(MPI_Comm comm,PetscLogHandler * handler)28 PetscErrorCode PetscLogHandlerCreate(MPI_Comm comm, PetscLogHandler *handler)
29 {
30 PetscLogHandler h;
31
32 PetscFunctionBegin;
33 *handler = NULL;
34 PetscCall(PetscLogHandlerPackageInitialize());
35 // We do not use PetscHeaderCreate() here because having PetscLogObjectCreate() run for PetscLogHandler would be very fragile
36 PetscCall(PetscNew(&h));
37 PetscCall(PetscHeaderCreate_Private((PetscObject)(h), PETSCLOGHANDLER_CLASSID, "PetscLogHandler", "Profile events, stages, and objects", "Profiling", comm, (PetscObjectDestroyFn *)PetscLogHandlerDestroy, (PetscObjectViewFn *)PetscLogHandlerView));
38 *handler = h;
39 PetscFunctionReturn(PETSC_SUCCESS);
40 }
41
42 /*@
43 PetscLogHandlerDestroy - Destroy a `PetscLogHandler`
44
45 Logically collective
46
47 Input Parameter:
48 . handler - handler to be destroyed
49
50 Level: developer
51
52 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerCreate()`
53 @*/
PetscLogHandlerDestroy(PetscLogHandler * handler)54 PetscErrorCode PetscLogHandlerDestroy(PetscLogHandler *handler)
55 {
56 PetscLogHandler h;
57
58 PetscFunctionBegin;
59 if (!*handler) PetscFunctionReturn(PETSC_SUCCESS);
60 h = *handler;
61 *handler = NULL;
62 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
63 if (--((PetscObject)h)->refct > 0) PetscFunctionReturn(PETSC_SUCCESS);
64 PetscTryTypeMethod(h, destroy);
65 PetscCall(PetscLogStateDestroy(&h->state));
66 // We do not use PetscHeaderDestroy() because having PetscLogObjectDestroy() run for PetscLgoHandler would be very fragile
67 PetscCall(PetscHeaderDestroy_Private((PetscObject)(h), PETSC_FALSE));
68 PetscCall(PetscFree(h));
69 PetscFunctionReturn(PETSC_SUCCESS);
70 }
71
72 /*@
73 PetscLogHandlerSetState - Set the logging state that provides the stream of events and stages for a log handler.
74
75 Logically collective
76
77 Input Parameters:
78 + h - the `PetscLogHandler`
79 - state - the `PetscLogState`
80
81 Level: developer
82
83 Note:
84 Most users well not need to set a state explicitly: the global logging state (`PetscLogGetState()`) is set when calling `PetscLogHandlerStart()`
85
86 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogState`, `PetscLogEventBegin()`, `PetscLogHandlerStart()`
87 @*/
PetscLogHandlerSetState(PetscLogHandler h,PetscLogState state)88 PetscErrorCode PetscLogHandlerSetState(PetscLogHandler h, PetscLogState state)
89 {
90 PetscFunctionBegin;
91 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
92 if (state) {
93 PetscAssertPointer(state, 2);
94 state->refct++;
95 }
96 PetscCall(PetscLogStateDestroy(&h->state));
97 h->state = state;
98 PetscFunctionReturn(PETSC_SUCCESS);
99 }
100
101 /*@
102 PetscLogHandlerGetState - Get the logging state that provides the stream of events and stages for a log handler.
103
104 Logically collective
105
106 Input Parameter:
107 . h - the `PetscLogHandler`
108
109 Output Parameter:
110 . state - the `PetscLogState`
111
112 Level: developer
113
114 Note:
115 For a log handler started with `PetscLogHandlerStart()`, this will be the PETSc global logging state (`PetscLogGetState()`)
116
117 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogState`, `PetscLogEventBegin()`, `PetscLogHandlerStart()`
118 @*/
PetscLogHandlerGetState(PetscLogHandler h,PetscLogState * state)119 PetscErrorCode PetscLogHandlerGetState(PetscLogHandler h, PetscLogState *state)
120 {
121 PetscFunctionBegin;
122 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
123 PetscAssertPointer(state, 2);
124 *state = h->state;
125 PetscFunctionReturn(PETSC_SUCCESS);
126 }
127
128 /*@
129 PetscLogHandlerEventBegin - Record the beginning of an event in a log handler
130
131 Not collective
132
133 Input Parameters:
134 + h - the `PetscLogHandler`
135 . e - a registered `PetscLogEvent`
136 . o1 - `PetscObject` associated with the event (may be `NULL`)
137 . o2 - `PetscObject` associated with the event (may be `NULL`)
138 . o3 - `PetscObject` associated with the event (may be `NULL`)
139 - o4 - `PetscObject` associated with the event (may be `NULL`)
140
141 Level: developer
142
143 Note:
144 Most users will use `PetscLogEventBegin()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`
145
146 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogEventSync()`, `PetscLogHandlerEventEnd()`, `PetscLogHandlerEventSync()`
147 @*/
PetscLogHandlerEventBegin(PetscLogHandler h,PetscLogEvent e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)148 PetscErrorCode PetscLogHandlerEventBegin(PetscLogHandler h, PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
149 {
150 PetscFunctionBegin;
151 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
152 PetscTryTypeMethod(h, eventbegin, e, o1, o2, o3, o4);
153 PetscFunctionReturn(PETSC_SUCCESS);
154 }
155
156 /*@
157 PetscLogHandlerEventEnd - Record the end of an event in a log handler
158
159 Not collective
160
161 Input Parameters:
162 + h - the `PetscLogHandler`
163 . e - a registered `PetscLogEvent`
164 . o1 - `PetscObject` associated with the event (may be `NULL`)
165 . o2 - `PetscObject` associated with the event (may be `NULL`)
166 . o3 - `PetscObject` associated with the event (may be `NULL`)
167 - o4 - `PetscObject` associated with the event (may be `NULL`)
168
169 Level: developer
170
171 Note:
172 Most users will use `PetscLogEventEnd()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`
173
174 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogEventSync()`, `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventSync()`
175 @*/
PetscLogHandlerEventEnd(PetscLogHandler h,PetscLogEvent e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4)176 PetscErrorCode PetscLogHandlerEventEnd(PetscLogHandler h, PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
177 {
178 PetscFunctionBegin;
179 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
180 PetscTryTypeMethod(h, eventend, e, o1, o2, o3, o4);
181 PetscFunctionReturn(PETSC_SUCCESS);
182 }
183
184 /*@
185 PetscLogHandlerEventSync - Synchronize a logging event
186
187 Collective
188
189 Input Parameters:
190 + h - the `PetscLogHandler`
191 . e - a registered `PetscLogEvent`
192 - comm - the communicator over which to synchronize `e`
193
194 Level: developer
195
196 Note:
197 Most users will use `PetscLogEventSync()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`
198
199 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogEventSync()`, `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`
200 @*/
PetscLogHandlerEventSync(PetscLogHandler h,PetscLogEvent e,MPI_Comm comm)201 PetscErrorCode PetscLogHandlerEventSync(PetscLogHandler h, PetscLogEvent e, MPI_Comm comm)
202 {
203 MPI_Comm h_comm;
204 PetscMPIInt size;
205
206 PetscFunctionBegin;
207 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
208 PetscCall(PetscObjectGetComm((PetscObject)h, &h_comm));
209 PetscCallMPI(MPI_Comm_size(comm, &size));
210 if (comm == MPI_COMM_NULL || size == 1) PetscFunctionReturn(PETSC_SUCCESS); // nothing to sync
211 if (PetscDefined(USE_DEBUG)) {
212 PetscMPIInt h_comm_world, compare;
213 PetscCallMPI(MPI_Comm_compare(h_comm, PETSC_COMM_WORLD, &h_comm_world));
214 PetscCallMPI(MPI_Comm_compare(h_comm, comm, &compare));
215 // only synchronze if h->comm and comm have the same processes or h->comm is PETSC_COMM_WORLD
216 PetscCheck(h_comm_world != MPI_UNEQUAL || compare != MPI_UNEQUAL, comm, PETSC_ERR_SUP, "PetscLogHandlerSync does not support arbitrary mismatched communicators");
217 }
218 PetscTryTypeMethod(h, eventsync, e, comm);
219 PetscFunctionReturn(PETSC_SUCCESS);
220 }
221
222 /*@
223 PetscLogHandlerObjectCreate - Record the creation of an object in a log handler.
224
225 Not collective
226
227 Input Parameters:
228 + h - the `PetscLogHandler`
229 - obj - a newly created `PetscObject`
230
231 Level: developer
232
233 Notes:
234 Most users will use `PetscLogObjectCreate()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`.
235
236 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`, `PetscLogHandlerObjectDestroy()`
237 @*/
PetscLogHandlerObjectCreate(PetscLogHandler h,PetscObject obj)238 PetscErrorCode PetscLogHandlerObjectCreate(PetscLogHandler h, PetscObject obj)
239 {
240 PetscFunctionBegin;
241 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
242 PetscTryTypeMethod(h, objectcreate, obj);
243 PetscFunctionReturn(PETSC_SUCCESS);
244 }
245
246 /*@
247 PetscLogHandlerObjectDestroy - Record the destruction of an object in a log handler.
248
249 Not collective
250
251 Input Parameters:
252 + h - the `PetscLogHandler`
253 - obj - a newly created `PetscObject`
254
255 Level: developer
256
257 Notes:
258 Most users will use `PetscLogObjectDestroy()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`.
259
260 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`, `PetscLogHandlerObjectCreate()`
261 @*/
PetscLogHandlerObjectDestroy(PetscLogHandler h,PetscObject obj)262 PetscErrorCode PetscLogHandlerObjectDestroy(PetscLogHandler h, PetscObject obj)
263 {
264 PetscFunctionBegin;
265 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
266 PetscTryTypeMethod(h, objectdestroy, obj);
267 PetscFunctionReturn(PETSC_SUCCESS);
268 }
269
270 /*@
271 PetscLogHandlerStagePush - Begin a new logging stage in a log handler.
272
273 Not collective
274
275 Input Parameters:
276 + h - the `PetscLogHandler`
277 - stage - a registered `PetscLogStage`
278
279 Level: developer
280
281 Notes:
282 Most users will use `PetscLogStagePush()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`.
283
284 This function is called right before the stage is pushed for the handler's `PetscLogState`, so `PetscLogStateGetCurrentStage()`
285 can be used to see what the previous stage was.
286
287 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogHandlerStagePop()`
288 @*/
PetscLogHandlerStagePush(PetscLogHandler h,PetscLogStage stage)289 PetscErrorCode PetscLogHandlerStagePush(PetscLogHandler h, PetscLogStage stage)
290 {
291 PetscFunctionBegin;
292 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
293 PetscTryTypeMethod(h, stagepush, stage);
294 PetscFunctionReturn(PETSC_SUCCESS);
295 }
296
297 /*@
298 PetscLogHandlerStagePop - End the current logging stage in a log handler.
299
300 Not collective
301
302 Input Parameters:
303 + h - the `PetscLogHandler`
304 - stage - a registered `PetscLogStage`
305
306 Level: developer
307
308 Notes:
309 Most users will use `PetscLogStagePop()`, which will call this function for all handlers registered with `PetscLogHandlerStart()`.
310
311 This function is called right after the stage is popped for the handler's `PetscLogState`, so `PetscLogStateGetCurrentStage()`
312 can be used to see what the next stage will be.
313
314 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogHandlerStagePush()`
315 @*/
PetscLogHandlerStagePop(PetscLogHandler h,PetscLogStage stage)316 PetscErrorCode PetscLogHandlerStagePop(PetscLogHandler h, PetscLogStage stage)
317 {
318 PetscFunctionBegin;
319 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
320 PetscTryTypeMethod(h, stagepop, stage);
321 PetscFunctionReturn(PETSC_SUCCESS);
322 }
323
324 /*@
325 PetscLogHandlerView - View the data recorded in a log handler.
326
327 Collective
328
329 Input Parameters:
330 + h - the `PetscLogHandler`
331 - viewer - the `PetscViewer`
332
333 Level: developer
334
335 .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogView()`
336 @*/
PetscLogHandlerView(PetscLogHandler h,PetscViewer viewer)337 PetscErrorCode PetscLogHandlerView(PetscLogHandler h, PetscViewer viewer)
338 {
339 PetscFunctionBegin;
340 PetscValidHeaderSpecific(h, PETSCLOGHANDLER_CLASSID, 1);
341 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 2);
342 PetscTryTypeMethod(h, view, viewer);
343 PetscFunctionReturn(PETSC_SUCCESS);
344 }
345
346 /*@C
347 PetscLogHandlerGetEventPerfInfo - Get a direct reference to the `PetscEventPerfInfo` of a stage and event
348
349 Not collective, No Fortran Support
350
351 Input Parameters:
352 + handler - a `PetscLogHandler`
353 . stage - a `PetscLogStage` (or `PETSC_DEFAULT` for the current stage)
354 - event - a `PetscLogEvent`
355
356 Output Parameter:
357 . event_info - a pointer to a performance log for `event` during `stage` (or `NULL` if this handler does not use
358 `PetscEventPerfInfo` to record performance data); writing to `event_info` will change the record in
359 `handler`
360
361 Level: developer
362
363 .seealso: [](ch_profiling), `PetscLogEventGetPerfInfo()`, `PETSCLOGHANDLERDEFAULT`
364 @*/
PetscLogHandlerGetEventPerfInfo(PetscLogHandler handler,PetscLogStage stage,PetscLogEvent event,PetscEventPerfInfo ** event_info)365 PetscErrorCode PetscLogHandlerGetEventPerfInfo(PetscLogHandler handler, PetscLogStage stage, PetscLogEvent event, PetscEventPerfInfo **event_info)
366 {
367 PetscFunctionBegin;
368 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
369 PetscAssertPointer(event_info, 4);
370 *event_info = NULL;
371 PetscTryMethod(handler, "PetscLogHandlerGetEventPerfInfo_C", (PetscLogHandler, PetscLogStage, PetscLogEvent, PetscEventPerfInfo **), (handler, stage, event, event_info));
372 PetscFunctionReturn(PETSC_SUCCESS);
373 }
374
375 /*@C
376 PetscLogHandlerGetStagePerfInfo - Get a direct reference to the `PetscEventPerfInfo` of a stage
377
378 Not collective, No Fortran Support
379
380 Input Parameters:
381 + handler - a `PetscLogHandler`
382 - stage - a `PetscLogStage` (or `PETSC_DEFAULT` for the current stage)
383
384 Output Parameter:
385 . stage_info - a pointer to a performance log for `stage` (or `NULL` if this handler does not use `PetscEventPerfInfo`
386 to record performance data); writing to `stage_info` will change the record in `handler`
387
388 Level: developer
389
390 .seealso: [](ch_profiling), `PetscLogEventGetPerfInfo()`, `PETSCLOGHANDLERDEFAULT`
391 @*/
PetscLogHandlerGetStagePerfInfo(PetscLogHandler handler,PetscLogStage stage,PetscEventPerfInfo ** stage_info)392 PetscErrorCode PetscLogHandlerGetStagePerfInfo(PetscLogHandler handler, PetscLogStage stage, PetscEventPerfInfo **stage_info)
393 {
394 PetscFunctionBegin;
395 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
396 PetscAssertPointer(stage_info, 3);
397 *stage_info = NULL;
398 PetscTryMethod(handler, "PetscLogHandlerGetStagePerfInfo_C", (PetscLogHandler, PetscLogStage, PetscEventPerfInfo **), (handler, stage, stage_info));
399 PetscFunctionReturn(PETSC_SUCCESS);
400 }
401
402 /*@
403 PetscLogHandlerSetLogActions - Determines whether actions are logged for a log handler.
404
405 Not Collective
406
407 Input Parameters:
408 + handler - a `PetscLogHandler`
409 - flag - `PETSC_TRUE` if actions are to be logged (ignored if `handler` does not log actions)
410
411 Level: developer
412
413 Notes:
414 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
415 `PetscLogSetLogActions()` to call this function for the default log handler that is connected to the global
416 logging state (`PetscLogGetState()`).
417
418 Logging of actions continues to consume more memory as the program runs. Long running programs should consider
419 turning this feature off.
420
421 .seealso: [](ch_profiling), `PetscLogSetLogActions()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogGetDefaultHandler()`
422 @*/
PetscLogHandlerSetLogActions(PetscLogHandler handler,PetscBool flag)423 PetscErrorCode PetscLogHandlerSetLogActions(PetscLogHandler handler, PetscBool flag)
424 {
425 PetscFunctionBegin;
426 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
427 PetscTryMethod(handler, "PetscLogHandlerSetLogActions_C", (PetscLogHandler, PetscBool), (handler, flag));
428 PetscFunctionReturn(PETSC_SUCCESS);
429 }
430
431 /*@
432 PetscLogHandlerSetLogObjects - Determines whether objects are logged for a log handler.
433
434 Not Collective
435
436 Input Parameters:
437 + handler - a `PetscLogHandler`
438 - flag - `PETSC_TRUE` if objects are to be logged (ignored if `handler` does not log objects)
439
440 Level: developer
441
442 Notes:
443 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
444 `PetscLogSetLogObjects()` to call this function for the default log handler that is connected to the global
445 logging state (`PetscLogGetState()`).
446
447 Logging of objects continues to consume more memory as the program runs. Long running programs should consider
448 turning this feature off.
449
450 .seealso: [](ch_profiling), `PetscLogSetLogObjects()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogGetDefaultHandler()`
451 @*/
PetscLogHandlerSetLogObjects(PetscLogHandler handler,PetscBool flag)452 PetscErrorCode PetscLogHandlerSetLogObjects(PetscLogHandler handler, PetscBool flag)
453 {
454 PetscFunctionBegin;
455 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
456 PetscTryMethod(handler, "PetscLogHandlerSetLogObjects_C", (PetscLogHandler, PetscBool), (handler, flag));
457 PetscFunctionReturn(PETSC_SUCCESS);
458 }
459
PetscLogHandlerLogObjectState_Internal(PetscLogHandler handler,PetscObject obj,const char format[],va_list argp)460 PetscErrorCode PetscLogHandlerLogObjectState_Internal(PetscLogHandler handler, PetscObject obj, const char format[], va_list argp)
461 {
462 PetscFunctionBegin;
463 PetscTryMethod(handler, "PetscLogHandlerLogObjectState_C", (PetscLogHandler, PetscObject, const char *, va_list), (handler, obj, format, argp));
464 PetscFunctionReturn(PETSC_SUCCESS);
465 }
466
467 /*@C
468 PetscLogHandlerLogObjectState - Record information about an object with the default log handler
469
470 Not Collective, No Fortran Support
471
472 Input Parameters:
473 + handler - a `PetscLogHandler`
474 . obj - the `PetscObject`
475 . format - a printf-style format string
476 - ... - printf arguments to format
477
478 Level: developer
479
480 Note:
481 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
482 `PetscLogObjectState()` to call this function for the default log handler that is connected to the global
483 logging state (`PetscLogGetState()`).
484
485 .seealso: [](ch_profiling), `PetscLogObjectState`, `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`, `PetscLogGetDefaultHandler()`
486 @*/
PetscLogHandlerLogObjectState(PetscLogHandler handler,PetscObject obj,const char format[],...)487 PetscErrorCode PetscLogHandlerLogObjectState(PetscLogHandler handler, PetscObject obj, const char format[], ...)
488 {
489 va_list argp;
490
491 PetscFunctionBegin;
492 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
493 PetscValidHeader(obj, 2);
494 PetscAssertPointer(format, 3);
495 va_start(argp, format);
496 PetscCall(PetscLogHandlerLogObjectState_Internal(handler, obj, format, argp));
497 va_end(argp);
498 PetscFunctionReturn(PETSC_SUCCESS);
499 }
500
501 /*@
502 PetscLogHandlerGetNumObjects - Get the number of objects that were logged with a log handler
503
504 Not Collective
505
506 Input Parameter:
507 . handler - a `PetscLogHandler`
508
509 Output Parameter:
510 . num_objects - the number of objects whose creations and destructions were logged with `handler`
511 (`PetscLogHandlerObjectCreate()` / `PetscLogHandlerObjectDestroy()`), or -1
512 if the handler does not keep track of this number.
513
514 Level: developer
515
516 Note:
517 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not.
518
519 .seealso: [](ch_profiling)
520 @*/
PetscLogHandlerGetNumObjects(PetscLogHandler handler,PetscInt * num_objects)521 PetscErrorCode PetscLogHandlerGetNumObjects(PetscLogHandler handler, PetscInt *num_objects)
522 {
523 PetscFunctionBegin;
524 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
525 PetscAssertPointer(num_objects, 2);
526 PetscTryMethod(handler, "PetscLogHandlerGetNumObjects_C", (PetscLogHandler, PetscInt *), (handler, num_objects));
527 PetscFunctionReturn(PETSC_SUCCESS);
528 }
529
530 /*@
531 PetscLogHandlerEventDeactivatePush - Temporarily deactivate a logging event for a log handler
532
533 Not collective
534
535 Input Parameters:
536 + handler - a `PetscLogHandler`
537 . stage - a `PetscLogStage` (or `PETSC_DEFAULT` for the current stage)
538 - event - a `PetscLogEvent`
539
540 Level: developer
541
542 Note:
543 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
544 `PetscLogEventDeactivatePush()` to call this function for the default log handler that is connected to the global
545 logging state (`PetscLogGetState()`).
546
547 .seealso: [](ch_profiling), `PetscLogHandlerEventDeactivatePop()`
548 @*/
PetscLogHandlerEventDeactivatePush(PetscLogHandler handler,PetscLogStage stage,PetscLogEvent event)549 PetscErrorCode PetscLogHandlerEventDeactivatePush(PetscLogHandler handler, PetscLogStage stage, PetscLogEvent event)
550 {
551 PetscFunctionBegin;
552 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
553 PetscTryMethod(handler, "PetscLogHandlerEventDeactivatePush_C", (PetscLogHandler, PetscLogStage, PetscLogEvent), (handler, stage, event));
554 PetscFunctionReturn(PETSC_SUCCESS);
555 }
556
557 /*@
558 PetscLogHandlerEventDeactivatePop - Undo temporary deactivation a logging event for a log handler
559
560 Not collective
561
562 Input Parameters:
563 + handler - a `PetscLogHandler`
564 . stage - a `PetscLogStage` (or `PETSC_DEFAULT` for the current stage)
565 - event - a `PetscLogEvent`
566
567 Level: developer
568
569 Note:
570 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
571 `PetscLogEventDeactivatePop()` to call this function for the default log handler that is connected to the global
572 logging state (`PetscLogGetState()`).
573
574 .seealso: [](ch_profiling), `PetscLogHandlerEventDeactivatePush()`
575 @*/
PetscLogHandlerEventDeactivatePop(PetscLogHandler handler,PetscLogStage stage,PetscLogEvent event)576 PetscErrorCode PetscLogHandlerEventDeactivatePop(PetscLogHandler handler, PetscLogStage stage, PetscLogEvent event)
577 {
578 PetscFunctionBegin;
579 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
580 PetscTryMethod(handler, "PetscLogHandlerEventDeactivatePop_C", (PetscLogHandler, PetscLogStage, PetscLogEvent), (handler, stage, event));
581 PetscFunctionReturn(PETSC_SUCCESS);
582 }
583
584 /*@
585 PetscLogHandlerEventsPause - Put event logging into "paused" mode (see `PetscLogEventsPause()` for details.) for a log handler
586
587 Not collective
588
589 Input Parameter:
590 . handler - a `PetscLogHandler`
591
592 Level: developer
593
594 Note:
595 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
596 `PetscLogEventsPause()` to call this function for the default log handler that is connected to the global
597 logging state (`PetscLogGetState()`).
598
599 .seealso: [](ch_profiling), `PetscLogHandlerEventsResume()`
600 @*/
PetscLogHandlerEventsPause(PetscLogHandler handler)601 PetscErrorCode PetscLogHandlerEventsPause(PetscLogHandler handler)
602 {
603 PetscFunctionBegin;
604 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
605 PetscTryMethod(handler, "PetscLogHandlerEventsPause_C", (PetscLogHandler), (handler));
606 PetscFunctionReturn(PETSC_SUCCESS);
607 }
608
609 /*@
610 PetscLogHandlerEventsResume - Resume event logging that had been put into "paused" mode (see `PetscLogEventsPause()` for details.) for a log handler
611
612 Not collective
613
614 Input Parameter:
615 . handler - a `PetscLogHandler`
616
617 Level: developer
618
619 Note:
620 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
621 `PetscLogEventsResume()` to call this function for the default log handler that is connected to the global
622 logging state (`PetscLogGetState()`).
623
624 .seealso: [](ch_profiling), `PetscLogHandlerEventsPause()`
625 @*/
PetscLogHandlerEventsResume(PetscLogHandler handler)626 PetscErrorCode PetscLogHandlerEventsResume(PetscLogHandler handler)
627 {
628 PetscFunctionBegin;
629 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
630 PetscTryMethod(handler, "PetscLogHandlerEventsResume_C", (PetscLogHandler), (handler));
631 PetscFunctionReturn(PETSC_SUCCESS);
632 }
633
634 /*@
635 PetscLogHandlerDump - Dump the records of a log handler to file
636
637 Not collective
638
639 Input Parameters:
640 + handler - a `PetscLogHandler`
641 - sname - the name of the file to dump log data to
642
643 Level: developer
644
645 Note:
646 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
647 `PetscLogDump()` to call this function for the default log handler that is connected to the global
648 logging state (`PetscLogGetState()`).
649
650 .seealso: [](ch_profiling)
651 @*/
PetscLogHandlerDump(PetscLogHandler handler,const char sname[])652 PetscErrorCode PetscLogHandlerDump(PetscLogHandler handler, const char sname[])
653 {
654 PetscFunctionBegin;
655 PetscTryMethod(handler, "PetscLogHandlerDump_C", (PetscLogHandler, const char *), (handler, sname));
656 PetscFunctionReturn(PETSC_SUCCESS);
657 }
658
659 /*@
660 PetscLogHandlerStageSetVisible - Set the visibility of logging stage in `PetscLogHandlerView()` for a log handler
661
662 Not collective
663
664 Input Parameters:
665 + handler - a `PetscLogHandler`
666 . stage - a `PetscLogStage`
667 - isVisible - the visibility flag, `PETSC_TRUE` to print, else `PETSC_FALSE` (defaults to `PETSC_TRUE`)
668
669 Level: developer
670
671 Note:
672 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
673 `PetscLogStageSetVisible()` to call this function for the default log handler that is connected to the global
674 logging state (`PetscLogGetState()`).
675
676 .seealso: [](ch_profiling), `PetscLogHandlerStageGetVisible()`
677 @*/
PetscLogHandlerStageSetVisible(PetscLogHandler handler,PetscLogStage stage,PetscBool isVisible)678 PetscErrorCode PetscLogHandlerStageSetVisible(PetscLogHandler handler, PetscLogStage stage, PetscBool isVisible)
679 {
680 PetscFunctionBegin;
681 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
682 PetscTryMethod(handler, "PetscLogHandlerStageSetVisible_C", (PetscLogHandler, PetscLogStage, PetscBool), (handler, stage, isVisible));
683 PetscFunctionReturn(PETSC_SUCCESS);
684 }
685
686 /*@
687 PetscLogHandlerStageGetVisible - Get the visibility of logging stage in `PetscLogHandlerView()` for a log handler
688
689 Not collective
690
691 Input Parameters:
692 + handler - a `PetscLogHandler`
693 - stage - a `PetscLogStage`
694
695 Output Parameter:
696 . isVisible - the visibility flag, `PETSC_TRUE` to print, else `PETSC_FALSE` (defaults to `PETSC_TRUE`)
697
698 Level: developer
699
700 Note:
701 The default log handler `PETSCLOGHANDLERDEFAULT` implements this function, but others generally do not. You can use
702 `PetscLogStageGetVisible()` to call this function for the default log handler that is connected to the global
703 logging state (`PetscLogGetState()`).
704
705 .seealso: [](ch_profiling), `PetscLogHandlerStageSetVisible()`
706 @*/
PetscLogHandlerStageGetVisible(PetscLogHandler handler,PetscLogStage stage,PetscBool * isVisible)707 PetscErrorCode PetscLogHandlerStageGetVisible(PetscLogHandler handler, PetscLogStage stage, PetscBool *isVisible)
708 {
709 PetscFunctionBegin;
710 PetscValidHeaderSpecific(handler, PETSCLOGHANDLER_CLASSID, 1);
711 PetscTryMethod(handler, "PetscLogHandlerStageGetVisible_C", (PetscLogHandler, PetscLogStage, PetscBool *), (handler, stage, isVisible));
712 PetscFunctionReturn(PETSC_SUCCESS);
713 }
714