Skip to content

Commit

Permalink
Profiling fixes for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Apr 9, 2024
1 parent f16d177 commit e2615d6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
10 changes: 5 additions & 5 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4374,24 +4374,24 @@ output_funcall (cb_tree x)
output ("cob_prof_enter_procedure (prof_info, %d);", proc_idx);
output_newline ();
output_prefix ();
output ("cob_prof_fallthrough_label = 0");
output ("fallthrough_label = 0");
break;
case COB_PROF_USE_PARAGRAPH_ENTRY: {
int paragraph_idx = CB_INTEGER(p->argv[1])->val;
int entry_idx = CB_INTEGER(p->argv[2])->val;
output ("if (!cob_prof_fallthrough_label)");
output ("if (!fallthrough_label)");
output_block_open ();
output_line ("cob_prof_use_paragraph_entry (prof_info, %d, %d);",
paragraph_idx, entry_idx);
output_block_close ();
output_line ("else");
output_block_open ();
output_line ("cob_prof_fallthrough_label = 0;");
output_line ("fallthrough_label = 0;");
output_block_close ();
break;
}
case COB_PROF_STAYIN_PARAGRAPH:
output ("cob_prof_fallthrough_label = 1");
output ("fallthrough_label = 1");
break;
}
return;
Expand Down Expand Up @@ -13782,7 +13782,7 @@ output_cob_prof_data ( struct cb_program * program )
}
output_local ("};\n");

output_local ("static int cob_prof_fallthrough_label = 0;\n");
output_local ("static int fallthrough_label = 0;\n");
output_local ("static struct cob_prof_module *prof_info;\n");

output_local ("\n/* End of cob_prof data */\n");
Expand Down
3 changes: 3 additions & 0 deletions libcob/coblocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ COB_HIDDEN int cob_cmps (const unsigned char *, const unsigned char *,

COB_HIDDEN FILE * cob_open_logfile (const char *filename);

/* Whether we are in testsuite mode */
COB_HIDDEN int is_test;

#undef COB_HIDDEN

#endif /* COB_LOCAL_H */
10 changes: 9 additions & 1 deletion libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static const unsigned char *sort_collate = NULL;
static const char *cob_source_file = NULL;
static unsigned int cob_source_line = 0;

int is_test = 0;

#ifdef HAVE_DESIGNATED_INITS
const char *cob_statement_name[STMT_MAX_ENTRY] = {
[STMT_UNKNOWN] = "UNKNOWN"
Expand Down Expand Up @@ -7864,7 +7866,11 @@ cob_expand_env_string (const char *strval)
const char *s = NULL;
switch ( strval[k+1] ){
case '$': /* Replace $$ with process-id */
j += sprintf (&env[j], "%d", cob_sys_getpid());
if (is_test) {
j += sprintf (&env[j], "%d", 123456);
} else {
j += sprintf (&env[j], "%d", cob_sys_getpid());
}
k++;
break;
case 'f': /* $f is the executable filename */
Expand Down Expand Up @@ -10289,6 +10295,8 @@ cob_init (const int argc, char **argv)

cob_initialized = 1;

is_test = !!getenv ("COB_IS_RUNNING_IN_TESTMODE");

#ifdef HAVE_SETLOCALE
/* Prime the locale from user settings */
s = setlocale (LC_ALL, "");
Expand Down
7 changes: 1 addition & 6 deletions libcob/profiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ static int current_idx = -1;

/* Whether profiling is active or not. */
static int is_active = 0;
/* Whether we are in testsuite mode */
static int is_test = 0;

/* Which clock to use for clock_gettime (if available) */
#ifdef HAVE_CLOCK_GETTIME
Expand Down Expand Up @@ -155,9 +153,6 @@ prof_init_static ()
if (!init_done && cobsetptr) {
prof_setup_clock ();
is_active = cobsetptr->cob_prof_enable;
if (is_active) {
is_test = !!getenv ("COB_IS_RUNNING_IN_TESTMODE");
}
init_done = 1;
}
}
Expand Down Expand Up @@ -460,7 +455,7 @@ cob_prof_print_line (
case 'i':
if (info){
if (is_test){
fprintf (file, "%d", 42);
fprintf (file, "%d", 123456);
} else {
fprintf (file, "%d", cob_sys_getpid());
}
Expand Down
26 changes: 13 additions & 13 deletions tests/testsuite.src/run_misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -14675,26 +14675,26 @@ prog.cob:11: warning: GO TO SECTION '2ND'

AT_CHECK([COB_PROF_ENABLE=0 COB_PROF_FILE='prof-$b.csv' $COBCRUN_DIRECT ./prog], [0], [], [])

AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE='prof-$b.csv' COB_PROF_FORMAT=%i,%m,%s,%p,%e,%f,%l,%w,%k,%t,%h,%n,%x $COBCRUN_DIRECT ./prog], [0], [],
[File prof-prog.csv generated
AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE='prof-$$-$b.csv' COB_PROF_FORMAT=%i,%m,%s,%p,%e,%f,%l,%w,%k,%t,%h,%n,%x $COBCRUN_DIRECT ./prog], [0], [],
[File prof-123456-prog.csv generated
])

# note: The time here is actually the number of times the procedure has
# been run, to avoid any indeterminism in the running time of the
# procedure.

AT_CHECK([cat prof-prog.csv], [0],
AT_CHECK([cat prof-123456-prog.csv], [0],
[pid,program-id,section,paragraph,entry,file,line,location,kind,time-ns,time,ncalls,%x
42,prog,,,,prog.cob,4,prog.cob:4,PROGRAM,13000000,0.013 s,1,%x
42,prog,1ST,,,prog.cob,5,prog.cob:5,SECTION,12000000,0.012 s,1,%x
42,prog,1ST,PARA-0001,,prog.cob,6,prog.cob:6,PARAGRAPH,11000000,0.011 s,1,%x
42,prog,1ST,PARA-0002,,prog.cob,8,prog.cob:8,PARAGRAPH,0,0.000 s,0,%x
42,prog,1ST,PARA-0003,,prog.cob,10,prog.cob:10,PARAGRAPH,1000000,0.001 s,1,%x
42,prog,1ST,PARA-0004,,prog.cob,12,prog.cob:12,PARAGRAPH,0,0.000 s,0,%x
42,prog,2ND,,,prog.cob,14,prog.cob:14,SECTION,6000000,0.006 s,1,%x
42,prog,2ND,PARA-0005,,prog.cob,15,prog.cob:15,PARAGRAPH,3000000,0.003 s,1,%x
42,prog,2ND,PARA-0006,,prog.cob,17,prog.cob:17,PARAGRAPH,2000000,0.002 s,2,%x
42,prog,2ND,PARA-0007,,prog.cob,19,prog.cob:19,PARAGRAPH,1000000,0.001 s,1,%x
123456,prog,,,,prog.cob,4,prog.cob:4,PROGRAM,13000000,0.013 s,1,%x
123456,prog,1ST,,,prog.cob,5,prog.cob:5,SECTION,12000000,0.012 s,1,%x
123456,prog,1ST,PARA-0001,,prog.cob,6,prog.cob:6,PARAGRAPH,11000000,0.011 s,1,%x
123456,prog,1ST,PARA-0002,,prog.cob,8,prog.cob:8,PARAGRAPH,0,0.000 s,0,%x
123456,prog,1ST,PARA-0003,,prog.cob,10,prog.cob:10,PARAGRAPH,1000000,0.001 s,1,%x
123456,prog,1ST,PARA-0004,,prog.cob,12,prog.cob:12,PARAGRAPH,0,0.000 s,0,%x
123456,prog,2ND,,,prog.cob,14,prog.cob:14,SECTION,6000000,0.006 s,1,%x
123456,prog,2ND,PARA-0005,,prog.cob,15,prog.cob:15,PARAGRAPH,3000000,0.003 s,1,%x
123456,prog,2ND,PARA-0006,,prog.cob,17,prog.cob:17,PARAGRAPH,2000000,0.002 s,2,%x
123456,prog,2ND,PARA-0007,,prog.cob,19,prog.cob:19,PARAGRAPH,1000000,0.001 s,1,%x
])

AT_CLEANUP
Expand Down

0 comments on commit e2615d6

Please sign in to comment.