MSBA-343 · Lesson 3 of 12 · 19 min
Performance tools and tracing
▶ Video coming soon A video version of this lesson is on the way.
Kiri's second checklist line was a performance baseline, and it came with a complaint. During the second migration rehearsal in UAT, Clemency Quintrell's accounts payable team had loaded several hundred open purchase orders, and the receiving clerks at the Akron plant had then posted product receipts against them. Most receipts were quick. Receipts for large casting orders, with a hundred lines or more, took minutes, and one clerk had given up and logged a ticket that simply said the receipt screen freezes. Desmond suspected the inspection certificate check from MSBA-341. He also knew that suspecting is not measuring, and he made that the theme of the session.
Measure before you change anything
Performance work goes wrong in a familiar way. A developer guesses at the cause, rewrites the code they suspect, sees a small improvement on their own machine and declares victory, while the real cost sits somewhere else. Desmond's method had four steps: reproduce the problem with realistic data, measure it with a trace, change one thing, and measure again with the same scenario. He wrote the scenario down so that anyone could repeat it: purchase order PO-CRCA-001842, 312 lines, 140 of them castings, receipt of all lines at the Akron plant, posted by a test user with the receiving clerk role.
Realistic data mattered more than anything. A developer environment with five purchase lines will never show a problem that grows with the number of lines. Prudence asked whether she could test in UAT directly. Desmond said tracing in UAT was fine and often necessary, but changes to code had to be made and measured first in a developer environment with a copy of enough data to reproduce the problem, and only then promoted.
Tools at a glance
Finance and operations apps offer several tools, each answering a different question. Desmond drew them on the whiteboard in the order a developer usually reaches for them.
| Tool | Question it answers | Where it runs |
|---|---|---|
| Trace capture in the client | What happened, call by call, while I did this? | Any environment, by a user with the System tracing user role |
| Trace Parser | Where did the time go in that trace? | Desktop application on the developer machine |
| Performance timer | How long did this form take, and how many calls did it make? | In the browser, in development and test environments |
| Environment monitoring and SQL insights | Which queries are slow or blocking across the environment? | Lifecycle Services or the Power Platform admin center for managed environments |
| Application Insights telemetry | How does the system behave over days and weeks? | Azure, once monitoring and telemetry is enabled (lesson 11) |
Capturing a trace
A trace records the X++ calls, database statements and timing of one user's session while tracing is on. In the unified developer experience and in cloud environments, traces are captured from the browser. The user who captures the trace needs the System tracing user role. Microsoft recommends removing that role after tracing, so that nobody starts traces by accident and fills storage with them.
Prudence assigned herself the role in UAT through a request to the administrator, logged in as the receiving test user and followed the steps. On the navigation bar she selected the question mark and then Trace. She named the trace after the scenario, CRCA receipt PO 1842 312 lines, so that anyone looking at it later would know what it measured. She left Include SQL parameter value set to No. Desmond explained why: parameter values show the actual data in each query, which helps diagnosis but makes the trace as sensitive as the database itself. When parameter values are needed, the trace must be handled like production data.
She selected Start trace, posted the receipt, waited for it to finish and selected Stop trace. The page then offered three choices: download the trace to her computer, upload it to the cloud so that someone else could download it later, or return to the menu to start another trace. Microsoft documents that uploaded traces are deleted automatically after seven days and can be deleted sooner from the Captured traces page. She downloaded it.
Long scenarios make traces that are hard to read. Microsoft advises splitting a scenario that runs more than a few minutes into several traces. Prudence's receipt ran for about four minutes, which was at the edge; Desmond suggested a second trace that posted a receipt for only twenty lines, so they could compare how the cost grew with the number of lines.
Trace Parser
Trace Parser is a desktop application that reads trace files and stores them in a SQL Server database for analysis. When a developer downloads the metadata, cross-reference database and related items for an application version in the unified developer experience, the installer, TraceParser.msi, comes with them. The first time the tool starts it asks for a database name; Microsoft suggests a distinct name such as Traces, and recommends the same SQL Server instance as the cross-reference data. The trace itself is an ETL file, short for event trace log, which the tool imports.
The tool has three views that Desmond used constantly. The Timeline view, the default, groups events by session and user and shows them on a time axis with a property grid for the selected event. The Call Tree view shows the tree of X++ method calls with the time spent in each method and each database call beneath it. The X++ view lists methods in a sortable grid by inclusive or exclusive duration, by the number of calls, or by the number of database calls.
Inclusive and exclusive time are the first thing to understand. Inclusive time is the time spent in a method and everything it calls. Exclusive time is the time spent in the method's own code, excluding calls. A method with large inclusive time and small exclusive time is a doorway; the cost is somewhere beneath it. A method with large exclusive time, or a method called thousands of times, is a place where the cost actually is.
Reading the receipt trace
Prudence sorted the X++ view by inclusive time. The standard posting class sat at the top, as expected, with about 236 seconds. Below it, the method that stood out was CRInspectionReceiptRule.isSatisfied from MSBA-341, with 171 seconds inclusive across 312 calls. The Call Tree showed why. Each call ran a select against CRInspectionCertTable to find the certificate for the line, and each of those selects took around half a second, because the table had grown to several thousand rows during the migration rehearsal and the select used fields that no index covered. Each call also ran a find on PurchTable to read the vendor, even though every line on the order belonged to the same purchase order.
The trace showed a second cost: 38 seconds spent inserting rows into CRInspAlertQueue, one insert per line, each raising data events and writing to the database log that an administrator had switched on for the queue during testing. Standard posting itself took less than half a minute. The finding was clear and specific, and none of it required guessing. Lessons 4 and 5 deal with the fixes. Lesson 12 returns to the full case once the fixes are in place.
The performance timer
For forms, a lighter tool is often enough. The performance timer shows, in the browser, how long the server and client took for recent interactions and how many server calls and database queries a form made. In development and test environments it is opened by adding debug=develop to the client URL. Desmond used it on the warranty list form, which Prudence had built with two display methods. The timer showed dozens of extra server calls while scrolling, one for each display method on each row. Lesson 5 covers the cure, which is caching display methods.
Environment-level views
Traces show one user's session. Some problems only appear across many sessions: blocking between two processes, a query plan that went bad after statistics changed, or a batch job that hogs the database at the same time each night. For cloud sandboxes and production, Microsoft provides environment monitoring with SQL insights, historically in Lifecycle Services. It shows current and historical activity on the environment's database, lists the most expensive queries, shows blocking chains and lets administrators perform some actions, such as viewing a query's plan. As environments move from Lifecycle Services to the Power Platform admin center, these tools are moving with them; lesson 10 discusses that migration.
Desmond did not have direct database access in UAT or production and did not want it. The cloud model hides the database server from developers on purpose. What he could do was ask the environment administrator for the SQL insights view when a problem looked environment-wide, and compare the queries it listed with the X++ that generated them.
Indexes
Many performance problems end with an index. An index on a table in finance and operations apps is defined in metadata, with ordered fields, and is created in the database when the model is synchronized. The clustered index decides the physical order of rows; other indexes are separate structures that the database uses to find rows without scanning the table. An index helps a query when the query's conditions match the leading fields of the index. An index on ItemId then InventLocationId helps a query that filters on ItemId, or on both, but not one that filters only on InventLocationId.
Indexes are not free. Each insert, update and delete must also maintain every index, and too many indexes slow writes and take space. Desmond's rule was to add an index only for a query that a trace or SQL insights showed to be slow, to design it for that query's conditions, and to measure again afterwards. Unique indexes also enforce rules, which is a separate reason to have them; the warranty table's unique index on serial number existed to stop duplicate warranties as much as to speed up lookups.
// Index added to CRInspectionCertTable after the receipt trace
// Name: CRPurchLineIdx AllowDuplicates: Yes
// Field 1: PurchId
// Field 2: LineNumber
// Supports the select in CRInspectionReceiptRule.isSatisfied:
select firstonly RecId, Status from cert
where cert.PurchId == _line.PurchId
&& cert.LineNumber == _line.LineNumber;Data entities and reports
The MB-500 skills outline lists data entities and reports alongside forms and queries as things a developer must optimize, and the tools are the same. For data entities, a trace of an import or export shows whether the entity's data sources and computed columns are the cost. Entities with many joined data sources, virtual fields computed in X++ for every row, or custom validation that runs row by row are the usual suspects; enabling set-based processing for an entity, where its design allows it, can change an import from minutes to seconds. MSBA-342 covers entity design in detail.
For reports, the report data provider is where the time goes. A provider that loops over records and inserts them one by one into its temporary table can be rewritten with set-based statements, and the temporary table type matters too, as lesson 4 explains. Desmond had already traced the weekly casting certificate report from MSBA-341 and found it acceptable, but he added it to the baseline so that a later change would be noticed.
Keeping traces safe
Traces contain queries, statements and call stacks, and sometimes parameter values. Microsoft treats them as sensitive, and so did Desmond. He asked Prudence to store traces only in the project's restricted folder, to delete trace databases and ETL files when an investigation was finished, and never to attach a trace with parameter values to a public support thread. He also asked that the System tracing user role be removed from her test account in UAT at the end of the day. Thandeka added that last point to her security checklist, because a role that lets someone record other activity in detail deserves the same review as any other privileged access.
Worked problem
Building the performance baseline
Kiri wants a performance baseline before go-live that can be repeated after each release. Which scenarios and measurements should Prudence include?
Show solution
- List the processes that matter most and grow with volume: product receipt of a large casting order, warranty list scrolling, the alert job, the weekly casting report and the warranty data entity export.
- Write each scenario down with its data, user role and environment, so that it can be repeated exactly.
- Capture a trace for each scenario in UAT with the System tracing user role, without SQL parameter values unless needed.
- Record total time, the top five methods by inclusive time and the number of database calls from Trace Parser.
- Store the results with the release number, remove the tracing role, and repeat the same scenarios after every release.
Answer: A small set of written, repeatable scenarios with traced timings gives Kiri a baseline that shows whether each release made things better or worse, and why.
Common mistakes
MistakeChanging code because it looks slow without measuring it.
InsteadReproduce, trace, change one thing and trace again.
MistakeTesting performance with a handful of records.
InsteadUse realistic volumes, because many problems grow with the number of rows.
MistakeLeaving SQL parameter values on and sharing the trace widely.
InsteadTreat traces as sensitive and include parameter values only when needed.
MistakeAdding indexes for every field that appears in a query.
InsteadAdd indexes for measured problems and remember that they slow writes.
Summary and key terms
- Performance work starts with a written, realistic scenario and a measurement, not a guess.
- Traces are captured from the question mark menu by users with the System tracing user role, which should be removed afterwards.
- Trace Parser imports ETL files into a SQL database and shows Timeline, Call Tree and X++ views.
- Inclusive time shows where cost sits beneath a method; exclusive time and call counts show where it is spent.
- Indexes help queries that match their leading fields but slow writes, and traces must be stored and deleted with care.
- Trace
- A recording of one session's X++ calls, database statements and timings.
- Trace Parser
- A desktop tool that imports trace files into a database and analyzes them.
- Inclusive time
- Time spent in a method including the methods it calls.
- Exclusive time
- Time spent in a method's own code, excluding calls.
- Performance timer
- A browser tool, opened with debug=develop in test environments, that shows server time and call counts for forms.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Which role must a user hold to capture a trace?
Show answer
System tracing user.
How long are uploaded traces kept before automatic deletion?
Show answer
Seven days.
A method has large inclusive time but tiny exclusive time. Where is the cost?
Show answer
In the methods it calls.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.