Project

General

Profile

Feature #3819

PROFILER system handle

Added by Greg Shah almost 8 years ago. Updated 2 minutes ago.

Status:
WIP
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

20%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:


Related issues

Related to Conversion Tools - Feature #11742: implement a fully featured Debug Adapter Protocol (DAP) server for 4GL code (in FWD) WIP

History

#2 Updated by Greg Shah almost 8 years ago

Many customers use this, but at least one customer is using this in a production environment. The user enters a hotkey combination and a dialog opens to let them start and stop profiling for their session. The result is a text file that is generated with a combination of lists of the top level entry points which were executed and execution statistics. They combine this with other stats read from the VST (virtual system tables - for example, query stats), store all of that as files in a zip. The user provides the zip to the developers and they can analyze what was going on that was slow.

FWD could implement the same features by instrumenting the runtime, but we would have to match the format of the results.

Implement support for the PROFILER system handle, all attributes, methods and runtime features. As of trunk 11338, most features already have conversion support (and stubs). Everything else needs to be completed.

#3 Updated by Robert-Adrian Chelaru over 7 years ago

For Profiler:Attributes we have the following structure

Files which are simply named by the attribute (ex: description.p) contain tests which throw
errors followed by a tests with normal working parameters.

Files which are named by the attribute and test parameter (ex: description_binary.p) contain
test cases with all possible types of parameters (binary, unknown, empty strings etc.) given
to the attribute.

Some attributes have different default values as against the documentation an example is
the :directory attribute which is set to "prof.out" instead of "profile.out" as the documentation
reads. Tests have the correct values.

For Profiler:Methods we use the same structure, we also include a test in which we leave the
Profiler:Enabled & Profiler:Profiling attributes on false, which makes Profiler not generate
any file.

For procedure and class tests we have 4 files, 1. testing all procedure types (internal run,
external run, persistent procedure and a block in a persistent procedure), 2. testing a simple
iterative function and a recursive function defined in a procedure file, 3. testing the properties
(the properties contain one with a custom getter and default setter and one with default getter
and custom setter) and a variable stored in a class, 4. testing its methods (a static method
and an object instance called method).

1. All procedures and the main block are registered by Profiler.

2. Both functions are registered by Profiler.

3. The default getters and setters are not registered by Profiler. The custom ones are registered.

4. Both the instanced and static methods are registered by Profiler.

In the same folder we have a test for dynamic objects, UI Triggers and Subscribe, these also are read by the Profiler.

#4 Updated by Greg Shah over 7 years ago

Robert:

Can you please capture the recorded profiler output for each of the testcases? These should be checked in to the testcases project so that we can confirm that the FWD output matches the 4GL output.

In addition, is there documentation on the format of the output file?

#5 Updated by Robert-Adrian Chelaru over 7 years ago

Greg Shah wrote:

Robert:

Can you please capture the recorded profiler output for each of the testcases? These should be checked in to the testcases project so that we can confirm that the FWD output matches the 4GL output.

Sorry, forgot to mention those, they are already up on bazaar. An output file for each test.

In addition, is there documentation on the format of the output file?

There isn't any official documentation, but there are tools from Progress that can read the output files.

#6 Updated by Greg Shah over 7 years ago

Sorry, forgot to mention those, they are already up on bazaar. An output file for each test.

Good. Those must be in the profiler/out/*.log files.

There isn't any official documentation, but there are tools from Progress that can read the output files.

Would you please use these tools to inspect the content and document the correspondence with the "raw" log files? The details can be posted here. If there is some content in the log files that is not decoded by the tools and it cannot be otherwise explained, please just make notes accordingly.

#7 Updated by Greg Shah about 7 years ago

From testcases/profiler/README.txt (by Robert):

Profiler Raw Data Documentation

Profiler separates the results in sections with the help of a "." (dot) and white line, if two dots follow each other it means there is no information in that category. The profiler has a total of 11 "sections". If the code analyzed by the profiler contains an instantiated object from a class with CUSTOM properties (note: not default properties) and/or methods those will be shown in the profiler in the 4th section.

1. Date followed by description, followed by time of profiling, followed by User ID.

2. ID of procedure/function/method, listed from the most executed to the least, followed by the name and then the source path from where it is called, followed by debug listing path(if any). Lastly we have the CRC of the external procedure.

3. Caller and called ID's
1st parameters are the ID of the caller.
2nd parameter is the line number (Also counts include statements).
3rd parameter is what procedure/function/method is called.
4th parameter is the number of times it is repeated.
example: 2 187 3 1 - means - Procedure with ID 2 is calling procedure with ID 3 at line 187, one time.

4. 1st parameter is the assigned id for the procedure/function/methods/properties,
2nd parameter is the line number,
3rd parameter is how many times it is executed,
4th parameter is total time taken to execute the statement,
5th parameter is total time take to execute the statement + callback's and exiting the statement.

5. 1st parameter is the ID,
2nd parameter is the line number,
3rd parameter is the time of execution for the line without any pauses,
4th parameter is the current total runtime before adding the 3rd parameters number to it (previous execution time + any pause).
If coverage is set on true, section 5 will also show an extra part with all custom properties and methods separated by a "." + white line,
along with how many different places it is called and the ID of the object from within it is called. (It is not needed)

6. It is not needed

7. 1st parameter is the ID of the procedure/function/method or code block that calls the action code,
2nd parameter is the corresponding number for the action code,
3rd parameter is the number of times action codes are executed,
4th parameter is the name of the action code.

Though Section 7 is not found in the the Profiler Viewer, it is needed to have at least one recording in it for the Profiler Viewer - AVM Information to work.
The information is not important as long as its in the basic format for section 7. An example that can be used everywhere
of what can fill section 7 is: 1 37 3 "ECONST"

8. It is not needed

9. It is not needed

10. Run configuration/parameters followed on the next line by database name and number of tables (system tables + defined tables).

11. 1st parameter is the time took to generate the profiler file,
2nd parameter is the user data (This only appears only if the "write-data" method isn't called and user-data method is set).

The profiler assigns an ID for each procedure/function, even if they are called multiple times, they all get unique ID's.
ID: 1 stands for internal statements, definitions and keywords from ABL.

Coverage - If set on false Profiler does not show the extra part of section 5 for custom properties and methods.
Listings - If set on true generates debug listings.
Profiling - If set on false section 5 does not record anything, nor do the other section record anything except internal statements.
Tracing - Must be set after the procedure to work.
Trace-Filter - The 5th section does not output anymore information in case of procedure/functions only for instantiated object and
their custom properties and methods.

#8 Updated by Greg Shah about 7 years ago

Robert, the following are my questions based on your "Profiler Raw Data Documentation".

1. If a section is listed as "It is not needed", what does that mean?

  • Does it mean that OpenEdge always has an empty section? OR
  • Does it mean that the meaning of the data is unknown but cannot be seen in the Profile Viewer?
  • Something else?

2. What do you mean by "Also counts include statements"?

  • Does this mean that the line numbers are based on the fully preprocessed file? OR
  • Are the line numbers specific to the procedure, class or include file in which the code was originally written?

Are all line numbers using this same method?

3. What are debug listings? Do you have any examples of the content of these listings?

#9 Updated by Robert-Adrian Chelaru about 7 years ago

Greg Shah wrote:

1. If a section is listed as "It is not needed", what does that mean?

It means that Profiler Viewer does not make use of those sections.

2. What do you mean by "Also counts include statements"?
  • Does this mean that the line numbers are based on the fully preprocessed file?

Yes

3. What are debug listings? Do you have any examples of the content of these listings?

Debug Listings are generated after Listings is set on true (Note: Directory Attribute changes the path of were debug listings will be generated). If it is set before Enabled, instantiation of an object, run statement w/ external procedure file it will generate a fully preprocessed file and source files for the external procedures/classes.

I have updated the README file with the mentioned information and also updated the Listings test so they generate debug files in /profiler/out/debug.

#10 Updated by Marian Edu about 7 years ago

Hi Greg, is there anything that needs clarification on this topic?

#11 Updated by Greg Shah about 7 years ago

Marian Edu wrote:

Hi Greg, is there anything that needs clarification on this topic?

No, I think this is complete. Thank you.

#12 Updated by Constantin Asofiei over 6 years ago

4231b rev 11493 added PROFILER:COVERAGE, TRACING, TRACE-FILTER and USER-DATA. All the profiler/ tests now convert and compile.

#13 Updated by Greg Shah over 6 years ago

  • % Done changed from 0 to 20

Task branch 4231b has been merged to trunk as revision 11347.

#14 Updated by Constantin Asofiei about 2 hours ago

Greg, please see this; I don't think we want to implement statement-level (or better said, line-level) profiling; only blocks I think it can work.


PROFILER per-line data: OpenEdge behavior and what it would take in FWD

High-level summary for #3819. It is based on OpenEdge 11.6.3 measurements; details and tests are in 3819-profiler-findings.md. Whether FWD implements this part is still open.

What it is

Besides the per-module data (which modules ran, who called whom, how long each module took), the OpenEdge profiler records data per source line of every module that runs while profiling is on. All of it goes into the single output file named by PROFILER:FILE-NAME. It is written on the client machine when profiling is disabled, when PROFILER:WRITE-DATA() is called, or when the session ends.

There are four kinds of per-line data:

Data Enabled by Contents When the line is known
Line summary always (ENABLED + PROFILING) per line: execution count, own time, time including called modules at every statement start
Tracing TRACE-FILTER (module-name patterns) and TRACING (procedure and line pairs), applied when the file is written one row per execution of a traced line: its duration and a timestamp at every statement start
Coverage COVERAGE (for modules first run after it is set) the lines that could execute, per module and internal entry static, from the compiled code
Caller line always the line each call to another module was made from when the called module starts

Example

fx_c.p, an external procedure with one internal procedure:

3 procedure ipc:
4    z = z + 1.
5 end procedure.
6 z = 1.
7 run ipc.

Output (module 6 = the main block, module 7 = ipc):

line summary   6 6 1 0.000015 0.000015    line 6 ran once, 15 µs
               6 7 2 0.000005 0.000027    line 7 (RUN): counted again after the call returns
               7 4 1 0.000016 0.000016
               6 0 1 0.000022 0.000064    line 0 = module entry/exit: 1 call, 64 µs in total
tracing        6 6 0.000015 0.160138      one row per execution: duration, timestamp
               6 7 0.000004 0.160155
               6 7 0.000001 0.160193
coverage       6 "ipc" 2  -> lines 4, 5
               6 "" 2     -> lines 6, 7
caller line    6 7 7 1                    module 6 called module 7 once, from line 7

Behaviors that matter for an implementation:

  • END statements count as lines.
  • A line that calls another module is counted again when control returns to it.
  • Waiting for the user is not counted (PAUSE, dialogs, UPDATE, WAIT-FOR in interactive clients). Waiting for a record lock or for an OS-COMMAND is counted.
  • The trace filters are applied when writing, so every execution has to be recorded while profiling is on.
  • Tracing with the pattern * produces a row for every executed line, which is the most expensive part.

In FWD

Line numbers. FWD would report the Java line numbers of the converted code, not 4GL lines. The listing files would be the converted Java sources, so the numbers match.

What FWD can provide without new instrumentation:

  • the module list, call counts and module times (line 0);
  • the call tree with caller lines, read from the Java stack when a module starts;
  • coverage, from the Java class files' line-number tables.

What needs an event at every statement start:

  • the line summary: counts and own times of every line;
  • tracing.

FWD has no such event today. Converted code is plain Java, and the application classes are loaded by the JDK class loader, so FWD cannot change them at load time. Options:

Option How Cost / impact
Bytecode probe, Java agent a small FWD Java agent inserts a probe call at each Java line of the converted classes as they load no reconversion; one flag check per line when profiling is off; the server is started with -javaagent
Bytecode probe, FWD class loader the same probe, inserted when the application jars are loaded through FWD's own class loader no agent; changes how application jars are deployed and loaded
Conversion-time calls conversion emits a profiler call before every statement larger code and reconversion; the extra calls shift the Java line numbers
Module-level only skip the line summary and tracing no runtime cost; the output keeps the module, call-tree, line 0 and coverage parts, but the per-line timing is missing

Whichever option is chosen, the per-line timing has to subtract the time spent waiting for the user. That wait happens in the client JVM, while the timing is measured on the FWD server.

#15 Updated by Constantin Asofiei about 1 hour ago

  • Assignee set to Constantin Asofiei
  • Status changed from New to WIP

#16 Updated by Greg Shah about 1 hour ago

  • Related to Feature #11742: implement a fully featured Debug Adapter Protocol (DAP) server for 4GL code (in FWD) added

#17 Updated by Greg Shah about 1 hour ago

How does this change in consideration that we are already implementing a DAP (#11742) which allows 4GL source line stepping with mapping from the Java source lines back to the 4GL source lines? Can we use the same facilities to implement the profiler?

#18 Updated by Constantin Asofiei 42 minutes ago

Greg Shah wrote:

How does this change in consideration that we are already implementing a DAP (#11742) which allows 4GL source line stepping with mapping from the Java source lines back to the 4GL source lines? Can we use the same facilities to implement the profiler?

It depends on how the PROFILER is used in a production app - a DAP server may not be available; and it may be useful for production also, to get insight in a scenario by enabling (and then disabling) the profiler.

If is something only for development, then we can extend this with DAP once that is available. But for now, I think we need to postpone this.

More, for full support, consider that the runtime requires to know exactly what line is being executed. And this can be done only by a Java agent to instrument the converted Java code.

#19 Updated by Greg Shah 25 minutes ago

The DAP does already exist in 10804b. It builds upon the JDI. I don't know if we really need the DAP server there at all. My point here is that the JDI integration already is proven to work. It provides the same level of line-level execution control that we would need for the profiler. We've already implemented the .dbgmap mapping from 4GL source lines to Java source lines.

#20 Updated by Constantin Asofiei 12 minutes ago

Greg Shah wrote:

The DAP does already exist in 10804b. It builds upon the JDI. I don't know if we really need the DAP server there at all. My point here is that the JDI integration already is proven to work. It provides the same level of line-level execution control that we would need for the profiler. We've already implemented the .dbgmap mapping from 4GL source lines to Java source lines.

To rephrase this: if we want this measurement to be 'per 4GL instruction', we need an event for every executed line. In-process, that means instrumentation in the bytecode. The .dbgmap mapping can be used to report these rows with 4GL line numbers instead of Java ones, and fallback to Java lines if these files are missing.

Take the bellow with a grain of salt:

JDI can deliver line events too (breakpoints/stepping), but only through a debugger connection (-agentlib:jdwp), which suspends the thread on every line; that is far too slow for timings and not something we can use in production.

If this is true, then I want to avoid both, and leave only blocks (and call-sites for top-level blocks) and plain queries: these all go through the FWD runtime (BlockManager, the persistence layer), so we can time them there, and report them as line rows at the block/statement line.

#21 Updated by Greg Shah 2 minutes ago

If this is true, then I want to avoid both

Agreed.

Also available in: Atom PDF