1*a60856c8SToby Isaac const char help[] = "Test PetscLogEventsPause() and PetscLogEventsUnpause()"; 2*a60856c8SToby Isaac 3*a60856c8SToby Isaac #include <petscsys.h> 4*a60856c8SToby Isaac 5*a60856c8SToby Isaac int main(int argc, char **argv) 6*a60856c8SToby Isaac { 7*a60856c8SToby Isaac PetscLogStage main_stage, unrelated_stage; 8*a60856c8SToby Isaac PetscLogEvent runtime_event, unrelated_event; 9*a60856c8SToby Isaac PetscLogHandler default_handler; 10*a60856c8SToby Isaac PetscClassId runtime_classid, unrelated_classid; 11*a60856c8SToby Isaac PetscBool main_visible = PETSC_FALSE; 12*a60856c8SToby Isaac PetscBool unrelated_visible = PETSC_FALSE; 13*a60856c8SToby Isaac PetscBool get_main_visible; 14*a60856c8SToby Isaac PetscBool get_unrelated_visible; 15*a60856c8SToby Isaac PetscBool is_active; 16*a60856c8SToby Isaac 17*a60856c8SToby Isaac PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 18*a60856c8SToby Isaac PetscCall(PetscLogIsActive(&is_active)); 19*a60856c8SToby Isaac PetscCheck(is_active, PETSC_COMM_WORLD, PETSC_ERR_SUP, "Logging must be active for this test"); 20*a60856c8SToby Isaac PetscCall(PetscLogActions(PETSC_FALSE)); 21*a60856c8SToby Isaac PetscCall(PetscLogObjects(PETSC_FALSE)); 22*a60856c8SToby Isaac 23*a60856c8SToby Isaac PetscOptionsBegin(PETSC_COMM_WORLD, NULL, help, NULL); 24*a60856c8SToby Isaac PetscCall(PetscOptionsBool("-main_visible", "The logging visibility of the main stage", NULL, main_visible, &main_visible, NULL)); 25*a60856c8SToby Isaac PetscCall(PetscOptionsBool("-unrelated_visible", "The logging visibility of the unrelated stage", NULL, unrelated_visible, &unrelated_visible, NULL)); 26*a60856c8SToby Isaac PetscOptionsEnd(); 27*a60856c8SToby Isaac 28*a60856c8SToby Isaac /* This test simulates a program with unrelated logging stages and events 29*a60856c8SToby Isaac that has to "stop the world" to lazily initialize a runtime. 30*a60856c8SToby Isaac 31*a60856c8SToby Isaac - Pausing events should send the log data for the runtime initalization 32*a60856c8SToby Isaac to the Main Stage 33*a60856c8SToby Isaac 34*a60856c8SToby Isaac - Turning the Main Stage invisible should hide it from -log_view 35*a60856c8SToby Isaac 36*a60856c8SToby Isaac So the runtime intialization should be more or less missing from -log_view. */ 37*a60856c8SToby Isaac 38*a60856c8SToby Isaac PetscCall(PetscClassIdRegister("External runtime", &runtime_classid)); 39*a60856c8SToby Isaac PetscCall(PetscLogEventRegister("External runtime initialization", runtime_classid, &runtime_event)); 40*a60856c8SToby Isaac 41*a60856c8SToby Isaac PetscCall(PetscClassIdRegister("Unrelated class", &unrelated_classid)); 42*a60856c8SToby Isaac PetscCall(PetscLogEventRegister("Unrelated event", unrelated_classid, &unrelated_event)); 43*a60856c8SToby Isaac PetscCall(PetscLogStageRegister("Unrelated stage", &unrelated_stage)); 44*a60856c8SToby Isaac PetscCall(PetscLogStageGetId("Main Stage", &main_stage)); 45*a60856c8SToby Isaac PetscCall(PetscLogStageSetVisible(main_stage, main_visible)); 46*a60856c8SToby Isaac PetscCall(PetscLogStageSetVisible(unrelated_stage, unrelated_visible)); 47*a60856c8SToby Isaac PetscCall(PetscLogGetDefaultHandler(&default_handler)); 48*a60856c8SToby Isaac if (default_handler) { 49*a60856c8SToby Isaac PetscCall(PetscLogStageGetVisible(main_stage, &get_main_visible)); 50*a60856c8SToby Isaac PetscCall(PetscLogStageGetVisible(unrelated_stage, &get_unrelated_visible)); 51*a60856c8SToby Isaac PetscCheck(main_visible == get_main_visible, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Get/Set stage visibility discrepancy"); 52*a60856c8SToby Isaac PetscCheck(unrelated_visible == get_unrelated_visible, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Get/Set stage visibility discrepancy"); 53*a60856c8SToby Isaac } 54*a60856c8SToby Isaac 55*a60856c8SToby Isaac PetscCall(PetscLogStagePush(unrelated_stage)); 56*a60856c8SToby Isaac PetscCall(PetscLogEventBegin(unrelated_event, NULL, NULL, NULL, NULL)); 57*a60856c8SToby Isaac 58*a60856c8SToby Isaac PetscCall(PetscLogEventsPause()); 59*a60856c8SToby Isaac PetscCall(PetscLogEventBegin(runtime_event, NULL, NULL, NULL, NULL)); 60*a60856c8SToby Isaac PetscCall(PetscSleep(0.2)); 61*a60856c8SToby Isaac PetscCall(PetscLogEventEnd(runtime_event, NULL, NULL, NULL, NULL)); 62*a60856c8SToby Isaac PetscCall(PetscLogEventsResume()); 63*a60856c8SToby Isaac 64*a60856c8SToby Isaac PetscCall(PetscLogEventEnd(unrelated_event, NULL, NULL, NULL, NULL)); 65*a60856c8SToby Isaac PetscCall(PetscLogStagePop()); 66*a60856c8SToby Isaac PetscCall(PetscFinalize()); 67*a60856c8SToby Isaac return 0; 68*a60856c8SToby Isaac } 69*a60856c8SToby Isaac 70*a60856c8SToby Isaac /*TEST 71*a60856c8SToby Isaac 72*a60856c8SToby Isaac # main stage invisible, "External runtime initialization" shouldn't appear in the log 73*a60856c8SToby Isaac test: 74*a60856c8SToby Isaac requires: defined(PETSC_USE_LOG) 75*a60856c8SToby Isaac suffix: 0 76*a60856c8SToby Isaac args: -log_view -unrelated_visible 77*a60856c8SToby Isaac filter: grep -o "\\(External runtime initialization\\|Unrelated event\\)" 78*a60856c8SToby Isaac 79*a60856c8SToby Isaac # unrelated stage invisible, "Unrelated event" shouldn't appear in the log 80*a60856c8SToby Isaac test: 81*a60856c8SToby Isaac requires: defined(PETSC_USE_LOG) 82*a60856c8SToby Isaac suffix: 1 83*a60856c8SToby Isaac args: -log_view -main_visible 84*a60856c8SToby Isaac filter: grep -o "\\(External runtime initialization\\|Unrelated event\\)" 85*a60856c8SToby Isaac 86*a60856c8SToby Isaac TEST*/ 87