You are on page 1of 3

ADP Ax 2009 Code Profiler

Maris Orbidans Linked In, last changed: 2015 Sep


Ax project “ADPCodeProfile” version: 1.0

Summary
Tool enhances existing Ax 2009 code profiling feature. Two main improvements:
1. Results processing is much faster - in proportion ~ 1 : 5. Processing takes 5 times longer than test
execution (for CPU intensive operations, DB and resource waits are even faster).
2. Profiling results are presented in context of source code editing. It means each source code line in
X++ editor gets execution statistics right next to it.

Sample of editor and profile browsing window:

Code profile browser displays information for exact source code lines shown in X++ editor. In example
shown “47: 2.108ms #679c” means:
- Source code line number: 47 of SysBPCheck.doTreeNode()
- Total execution time: 2108ms (in executed test including all sub code)
- number of times executed: 6792
ADP Ax 2009 Code Profiler Page 1
Last changed: 2015 Sep
Ax project version: 1.0
- execution tier: c (can be c, s or * for both client and server)

Only lines actually executed will have info - blank lines means no execution. If time is negligible (less than 1
ms) only line number is shown, no time.
This approach really allows to switch focus form “finding” poorly performing code, to actually thinking
“how” to fix/improve it.

Installation
Code is distributed as XPO with shared project ADPCodePorfile. Regular import will do necessary thing.
Warning! Project contains class “EditorScirpts” which can be modified in your
system. Only method “aaCodeProfile” is needed.
Code is kept as compact as possible, so no security, labels, menu items etc.
Approach used in this project works on Ax 2012 to, simple form upgrade is needed.

Use
Class “ADPCodeProfile_Tutorial” is included in project to demonstrate two main usage scenarios:
1. run profiler from code – to analyze only problematic part of code.
2. Interactive – the same way as Ax standard code profiler. Start profiler, interact with Ax, when
required test is ready then stop and see results.

For interactive use or reviewing last profile simply open form ADPCodeProfileBrowse directly from AOT.
When form opens it reads in last profile and:
- Shows info log with top time consuming code trees
- Opens most time consuming root source code in X++ editor

Normal operation:
1. start new trace with "Start" button :)
2. do all the stuff needed, but not overdo it. The more code executed, the more time it takes to
process results, idling does not affect much.
3. "Stop" profiling will start processing result. "Cancel" button can be useful.
4. on completion info log is presented with most time consuming trees. AND the most consuming root
source code is opened in editor.
!! Now please pay attention !!
5. To actually see statistics in browser - in source code editor (X++ editor) right click > choose "Scripts"
> “aaCodeProfile”. This will refresh code profile browser form with information reflecting source
code shown in editor.

Like this:

ADP Ax 2009 Code Profiler Page 2


Last changed: 2015 Sep
Ax project version: 1.0
When new X++ editor window gets opened (on a method “Lookup definition” or Ctrl+Shift+Space)
then do this again to get matching statistics.
It is little bit awkward – it would be possible to update browser automatically on editor code
changes, but at least this method works.

Precision and issues


Currently there are several issues with precision:
- in some cases, observed line number mismatches actual source code <> statistics. Sometimes they
are offset by 1.
- loop headers (“for”, “while select” …), “Switch” statement, “Try” statement incorporate time of
their bodies too. Time on source line with “for” loop will include all time consumed in this loop, not
only actual “for” line. It can be important on “while select” – if body’s total time is significantly less
than time reported on “while select” line itself, then select is main time consumer. In other words,
select time in this case is time reported on this line minus total sum of body lines.
- Time reported may not be exact milliseconds (ms) due CPU frequencies changes or other reasons.

Despite these imprecisions tool still allows to compare analyze source code and locate poorly performing
part. At the end it does not matter whether process was exactly 2.978 sec or 3.421.

ADP Ax 2009 Code Profiler Page 3


Last changed: 2015 Sep
Ax project version: 1.0

You might also like