Skip to content

Commit

Permalink
xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
lefessan committed Dec 19, 2023
1 parent bcef2ed commit 52f6f56
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
2023-09-04 Fabrice Le Fessant <[email protected]> and Emilien Lemaire <[email protected]>

* parser.y: generate `cob_prof_section/paragraph_enter/exit` calls when
needed
* parser.y: generate `cob_prof_{enter/exit}_{section/paragraph}` calls
when needed

This comment has been minimized.

Copy link
@GitMensch

GitMensch Dec 19, 2023

Collaborator

From the GNU Coding Standards:

If you mention the names of the modified functions or variables, it’s important to name them in full. Don’t abbreviate function or variable names, and don’t combine them. Subsequent maintainers will often search for a function name to find all the change log entries that pertain to it; if you abbreviate the name, they won’t find it when they search.

For example, some people are tempted to abbreviate groups of function names by writing ‘* register.el ({insert,jump-to}-register)’; this is not a good idea, since searching for jump-to-register or insert-register would not find that entry.

(I've post-fixed the places where I did when reading that the first time)

* flag.def: add `-fprof` to enable profiling
* codegen.c: handle profiling code generation

Expand Down
21 changes: 7 additions & 14 deletions doc/gnucobol.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,9 @@ more information.
@cindex Profiling results
@cindex How to interpret the profiling results

The generated CSV file has 8 columns for each line:
By default, the generated CSV file has 8 columns for each line (it can
be customized with the @code{COB_PROF_FORMAT} environment/runtime
configuration):

@table @code

Expand All @@ -1810,8 +1812,8 @@ directly, but as the sum of the time spent in its paragraphs.
@item paragraph

The name of the paragraph. If a section has no paragraph, or does not
start by a paragraph, a default paragraph is created with name
@code{MAIN PARAGRAPH}.
start with a paragraph, a default paragraph called
@code{MAIN PARAGRAPH} is created.

@item entry

Expand All @@ -1836,24 +1838,15 @@ The time spent in the module/section/paragraph in nanoseconds

@item time

The time spent in the section/paragraph in the most human readable form
The time spent in the section/paragraph in a human readable form
(currently, the time in seconds and milliseconds)

@item ncalls

The number of calls to this section/paragraph

@end table


@subsection Consideration for @code{GO TO}

When executing a @code{GO TO} that targets a section or a paragraph
outside of the current section, the profiler consider that you exited
every paragraphs and sections that were called before the @code{GO TO}.

If the @code{GO TO} targets a paragraph inside the current section,
then all the previous paragraph are exited but not the current section.

@node Extensions, System Routines, Profiling, Top
@chapter Non-standard extensions
@cindex Extensions
Expand Down
2 changes: 2 additions & 0 deletions libcob/profiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <string.h>
#include <time.h>

#include "config.h"

/* include internal and external libcob definitions, forcing exports */
#define COB_LIB_EXPIMP
#include "coblocal.h"
Expand Down
41 changes: 19 additions & 22 deletions tests/testsuite.src/used_binaries.at
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,6 @@ AT_DATA([XXX], [
this test should include a second program which is CALLed two times
and has a different code path and therefore profiling depending on a
"mode" parameter passed

one test is missing that involves multiple COBOL programs, maybe a
module profcob1 (started by cobcrun, doing CALL "SYSTEM" USING
"profcob2" (of a compiled executable))
])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
Expand Down Expand Up @@ -1109,8 +1105,9 @@ AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE=prof.csv ./prog], [0], [],
[File prof.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.
# note: The time here is actually the number of times the procedure has

This comment has been minimized.

Copy link
@GitMensch

GitMensch Dec 19, 2023

Collaborator

Do we actually gain anything of that?

The number of calls are already in "ncalls" and we can tweak the format to drop the time columns for running the test, even in tests/atlocal.in. But as "ncalls" is not identical to "time" - maybe we even need another column (format) to represent what "time" in testmode currently is?

Adjusting COB_PROF_FORMAT, possibly "global" in tests/atlocal.in, also has the benefit that we can drop the code that checks if we are "running in testmode" (the less checks of that variable, the better)

# been run, to avoid any indeterminism in the running time of the
# procedure.

AT_CHECK([cat prof.csv], [0],
[program-id,section,paragraph,entry,location,kind,time-ns,time,ncalls
Expand Down Expand Up @@ -1196,25 +1193,24 @@ AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
PROCEDURE DIVISION.
MAIN SECTION.
DISPLAY "HELLO WORLD".
CALL "entry".
GOBACK.
ENTRY "entry".
CALL "inside-program".
FIN SECTION.
PROGRAM-ID. inside-program.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 COUNTER PIC 9(4).
PROCEDURE DIVISION.
MOVE 5000 TO COUNTER.
MAIN SECTION.
MOVE 100 TO COUNTER.
INSIDE SECTION.
PERFORM ITER.
EXIT SECTION.
ITER.
IF COUNTER = 0
DISPLAY "end iter".
DISPLAY "end iter"
EXIT PARAGRAPH.
SUBTRACT 1 FROM COUNTER.
PERFORM INSIDE.
Expand All @@ -1225,24 +1221,25 @@ AT_CAPTURE_FILE([prof.csv])

AT_CHECK([$COMPILE -fprof -x prog.cob])

AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE=prof.csv ./prog], [0], [HELLO WORLD
AT_CHECK([COB_PROF_ENABLE=1 COB_PROF_FILE=prof.csv ./prog], [0],
[HELLO WORLD
end iter
],
[File prof.csv generated
])

AT_CHECK([cat prof.csv], [0],
[program-id,section,paragraph,entry,location,kind,time-ns,time,ncalls
inside__program,,,,prog.cob:12,PROGRAM,7000000,0.007 s,1
inside__program,MAIN SECTION,,,prog.cob:17,SECTION,1000000,0.001 s,1
inside__program,MAIN SECTION,MAIN PARAGRAPH,,prog.cob:17,PARAGRAPH,1000000,0.001 s,1
inside__program,INSIDE,,,prog.cob:18,SECTION,4000000,0.004 s,1
inside__program,INSIDE,MAIN PARAGRAPH,,prog.cob:18,PARAGRAPH,3000000,0.003 s,1
inside__program,INSIDE,ITER,,prog.cob:21,PARAGRAPH,1000000,0.001 s,1
prog,,,,prog.cob:0,PROGRAM,15000000,0.015 s,2
prog,MAIN,,,prog.cob:5,SECTION,13000000,0.013 s,1
prog,MAIN,MAIN PARAGRAPH,,prog.cob:5,PARAGRAPH,13000000,0.013 s,2
prog,MAIN,MAIN PARAGRAPH,entry,prog.cob:5,ENTRY,0,0.000 s,1
prog,FIN,,,prog.cob:11,SECTION,0,0.000 s,1
inside__program,,,,prog.cob:10,PROGRAM,407000000,0.407 s,1
inside__program,MAIN,,,prog.cob:15,SECTION,1000000,0.001 s,1
inside__program,MAIN,MAIN PARAGRAPH,,prog.cob:15,PARAGRAPH,1000000,0.001 s,1
inside__program,INSIDE,,,prog.cob:17,SECTION,804000000,0.804 s,101
inside__program,INSIDE,MAIN PARAGRAPH,,prog.cob:17,PARAGRAPH,403000000,0.403 s,101
inside__program,INSIDE,ITER,,prog.cob:20,PARAGRAPH,401000000,0.401 s,101
prog,,,,prog.cob:0,PROGRAM,415000000,0.415 s,2
prog,MAIN SECTION,,,prog.cob:5,SECTION,413000000,0.413 s,1
prog,MAIN SECTION,MAIN PARAGRAPH,,prog.cob:5,PARAGRAPH,413000000,0.413 s,2
prog,MAIN SECTION,MAIN PARAGRAPH,entry,prog.cob:5,ENTRY,0,0.000 s,1
])

AT_CLEANUP
Expand Down

0 comments on commit 52f6f56

Please sign in to comment.