Skip to content

Commit 52c887a

Browse files
authored
[VSC-1581] App trace update example and fix (#1656)
* Update documentation for app trace * Reset target before app trace * Change: Add validation to open app trace files * Fix grammar * Update default trace values * Update deprecated esp-idf setting * Remove unnecessary edge case * Stop OpenOCD automatically - stop openocd automatically when app tracing is stopped. - remove workspaceFolder * Fix: Escape spaces in trace file paths for TCL command
1 parent d6b6554 commit 52c887a

File tree

7 files changed

+147
-60
lines changed

7 files changed

+147
-60
lines changed

docs_espressif/en/additionalfeatures/app-tracing.rst

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,52 @@ This feature allows to transfer arbitrary data between host and ESP32 via JTAG i
55

66
Developers can use this library to send application specific state of execution to the host and receive commands or other type of info in the opposite direction at runtime.
77

8-
Let's open a ESP-IDF project. For this tutorial we will use the `system/app_trace_to_host <https://github.com/espressif/esp-idf/tree/master/examples/system/app_trace_to_host>`_ example.
8+
Let's open a ESP-IDF project. For this tutorial we will use the `system/app_trace_basic <https://github.com/espressif/esp-idf/tree/master/examples/system/app_trace_basic>`_ example.
99

1010
- Navigate to **View** > **Command Palette**.
1111

1212
- Type **ESP-IDF: New Project**, select the command and choose ESP-IDF version to use.
1313

1414
If you don't see the option, please review the setup in :ref:`Install ESP-IDF and Tools <installation>`.
1515

16-
- A window will be open with settings to configure the project. Later you can choose from a list a ESP-IDF examples, go the **system** section and choose the ``app_trace_to_host``. You will see a **Create Project Using Example app_trace_to_host** button in the top and a description of the project below. Click the button and the project will be opened in a new window.
16+
- A window will be open with settings to configure the project. Later you can choose from the ESP-IDF examples, go the **system** section and choose the ``app_trace_basic``. You will see a **Create Project Using Example app_trace_basic project** button in the top and a description of the project below. Click the button and the project will be opened in a new window.
1717

1818
.. image:: ../../../media/tutorials/app_trace/app_tracing.png
1919

20-
For this example, the project has been already configured for application tracing purposes. On other projects you need to enable ``CONFIG_APPTRACE_DEST_TRAX`` and ``CONFIG_APPTRACE_ENABLE`` with the **ESP-IDF: SDK Configuration Editor** command.
20+
For this example, the project has been already configured for application tracing purposes. On other projects you need to enable ``CONFIG_APPTRACE_DEST_JTAG`` and ``CONFIG_APPTRACE_ENABLE`` with the **ESP-IDF: SDK Configuration Editor** command.
21+
22+
.. note::
23+
For the ``app_trace_basic`` example to work properly, you need to add the following settings to your project's ``.vscode/settings.json`` file:
24+
25+
.. code-block:: json
26+
27+
{
28+
"trace.poll_period": 0,
29+
"trace.trace_size": 2048,
30+
"trace.stop_tmo": 3,
31+
"trace.wait4halt": 0,
32+
"trace.skip_size": 0
33+
}
34+
35+
These settings ensure the same tracing behavior as demonstrated in the example.
2136

2237
- Configure, build and flash your project as explained in the :ref:`Build the project <build the project>`.
2338

24-
- Click the ``ESP-IDF Explorer`` in the `Visual Studio Code Activity bar <https://code.visualstudio.com/docs/getstarted/userinterface>`_ (1). On the ``IDF APP TRACER`` section, click the ``Start App Trace`` (2). This will execute the extension's OpenOCD server and send the corresponding tracing commands to generate a tracing log. You can see the generated tracing log in the ``APP TRACE ARCHIVES`` named with ``Trace Log #1`` (3). Each time you execute ``Start App Trace`` a new tracing will be generated and shown in the archives list. You can also start tracing by running the **ESP-IDF: App Trace** command.
39+
- Click the ``ESP-IDF Explorer`` in the `Visual Studio Code Activity bar <https://code.visualstudio.com/docs/getstarted/userinterface>`_.
40+
41+
1. On the ``IDF APP TRACER`` section, click the ``Start App Trace``. This will execute the extension's OpenOCD server and send the corresponding tracing commands to generate a tracing log.
42+
43+
2. You can see the generated tracing log in the ``APP TRACE ARCHIVES`` named with ``Trace Log #1``.
44+
45+
3. Each time you execute ``Start App Trace`` a new tracing will be generated and shown in the archives list. You can also start tracing by running the **ESP-IDF: App Trace** command.
2546

2647
.. note::
2748
* The OpenOCD server output is shown in menu **View** > **Output** > **ESP-IDF**.
2849
* Make sure that OpenOCD configuration files are properly configured with **ESP-IDF: Select OpenOCD Board Configuration** command.
2950

3051
.. image:: ../../../media/tutorials/app_trace/start_tracing.png
3152

32-
- Click on ``Trace Log #1`` to open a window with the trace report. Click ``Show Report`` button to see the trace output.
53+
- Click on ``Trace Log #1`` to open the trace file directly in the editor.
3354

3455
.. image:: ../../../media/tutorials/app_trace/trace_report.png
3556

-74.1 KB
Loading
-32.5 KB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@
821821
},
822822
"trace.poll_period": {
823823
"type": "number",
824-
"default": 1,
824+
"default": 0,
825825
"scope": "resource",
826826
"description": "%trace.poll_period.description%"
827827
},
@@ -833,7 +833,7 @@
833833
},
834834
"trace.stop_tmo": {
835835
"type": "number",
836-
"default": 5,
836+
"default": 3,
837837
"scope": "resource",
838838
"description": "%trace.stop_tmo.description%"
839839
},

src/espIdf/tracing/appTraceManager.ts

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export class AppTraceManager extends EventEmitter {
127127
private archiveDataProvider: AppTraceArchiveTreeDataProvider;
128128
private tclConnectionParams: TCLConnection;
129129
private shallContinueCheckingStatus: boolean;
130-
private workspaceFolder: vscode.Uri;
131130

132131
constructor(
133132
treeDataProvider: AppTraceTreeDataProvider,
@@ -147,59 +146,82 @@ export class AppTraceManager extends EventEmitter {
147146
AppTraceButtonType.AppTraceButton,
148147
""
149148
);
150-
const fileName = `file:${sep}${sep}${join(
151-
workspace.fsPath,
152-
"trace",
153-
`trace_${new Date().getTime()}.trace`
154-
)}`.replace(/\\/g, "/");
155-
const pollPeriod = idfConf.readParameter(
156-
"trace.poll_period",
157-
workspace
158-
);
159-
this.workspaceFolder = workspace;
160-
const traceSize = idfConf.readParameter("trace.trace_size", workspace) as string;
161-
const stopTmo = idfConf.readParameter("trace.stop_tmo", workspace) as string;
162-
const wait4halt = idfConf.readParameter("trace.wait4halt", workspace) as string;
163-
const skipSize = idfConf.readParameter("trace.skip_size", workspace) as string;
164-
const startTrackingHandler = this.sendCommandToTCLSession(
165-
[
166-
"esp",
167-
"apptrace",
168-
"start",
169-
fileName,
170-
pollPeriod,
171-
traceSize,
172-
stopTmo,
173-
wait4halt,
174-
skipSize,
175-
].join(" "),
176-
workspace
177-
);
178-
const tracingStatusHandler = this.appTracingStatusChecker(() => {
179-
tracingStatusHandler.stop();
180-
startTrackingHandler.stop();
181149

182-
this.treeDataProvider.showStartButton(
183-
AppTraceButtonType.AppTraceButton
184-
);
185-
this.treeDataProvider.updateDescription(
186-
AppTraceButtonType.AppTraceButton,
187-
"[Stopped]"
188-
);
189-
this.archiveDataProvider.populateArchiveTree();
150+
// Send reset command first to ensure proper initialization, then start app trace
151+
const resetHandler = this.sendCommandToTCLSession("reset", workspace);
152+
resetHandler.on("response", () => {
153+
// Reset completed, now start app trace
154+
this.executeAppTraceStart(workspace);
155+
resetHandler.stop();
190156
});
191157
}
192158
} catch (error) {
193159
Logger.errorNotify(error.message, error, "AppTraceManager start");
194160
}
195161
}
196162

197-
public async stop() {
163+
private executeAppTraceStart(workspace: vscode.Uri) {
164+
const fileName = `file:${sep}${sep}${join(
165+
workspace.fsPath,
166+
"trace",
167+
`trace_${new Date().getTime()}.trace`
168+
)}`.replace(/\\/g, "/");
169+
const pollPeriod = idfConf.readParameter("trace.poll_period", workspace);
170+
const traceSize = idfConf.readParameter(
171+
"trace.trace_size",
172+
workspace
173+
) as string;
174+
const stopTmo = idfConf.readParameter(
175+
"trace.stop_tmo",
176+
workspace
177+
) as string;
178+
const wait4halt = idfConf.readParameter(
179+
"trace.wait4halt",
180+
workspace
181+
) as string;
182+
const skipSize = idfConf.readParameter(
183+
"trace.skip_size",
184+
workspace
185+
) as string;
186+
const startTrackingHandler = this.sendCommandToTCLSession(
187+
[
188+
"esp",
189+
"apptrace",
190+
"start",
191+
`{${fileName}}`,
192+
pollPeriod,
193+
traceSize,
194+
stopTmo,
195+
wait4halt,
196+
skipSize,
197+
].join(" "),
198+
workspace
199+
);
200+
const tracingStatusHandler = this.appTracingStatusChecker(() => {
201+
tracingStatusHandler.stop();
202+
startTrackingHandler.stop();
203+
204+
this.treeDataProvider.showStartButton(AppTraceButtonType.AppTraceButton);
205+
this.treeDataProvider.updateDescription(
206+
AppTraceButtonType.AppTraceButton,
207+
"[Stopped]"
208+
);
209+
this.archiveDataProvider.populateArchiveTree();
210+
211+
// Stop OpenOCD server when app tracing finishes naturally
212+
const openOCDManager = OpenOCDManager.init();
213+
if (openOCDManager.isRunning()) {
214+
openOCDManager.stop();
215+
}
216+
});
217+
}
218+
219+
public async stop(workspace: vscode.Uri) {
198220
if (await OpenOCDManager.init().promptUserToLaunchOpenOCDServer()) {
199221
this.shallContinueCheckingStatus = false;
200222
const stopHandler = this.sendCommandToTCLSession(
201223
"esp apptrace stop",
202-
this.workspaceFolder
224+
workspace
203225
);
204226
stopHandler.on("response", (resp: Buffer) => {
205227
const respStr = resp.toString();
@@ -215,6 +237,12 @@ export class AppTraceManager extends EventEmitter {
215237
);
216238
}
217239
stopHandler.stop();
240+
241+
// Stop OpenOCD server after app tracing is stopped
242+
const openOCDManager = OpenOCDManager.init();
243+
if (openOCDManager.isRunning()) {
244+
openOCDManager.stop();
245+
}
218246
});
219247
} else {
220248
this.treeDataProvider.updateDescription(

src/espIdf/tracing/tree/appTraceArchiveTreeDataProvider.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Project: ESP-IDF VSCode Extension
33
* File Created: Tuesday, 16th July 2019 1:38:00 pm
44
* Copyright 2019 Espressif Systems (Shanghai) CO LTD
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -119,19 +119,32 @@ export class AppTraceArchiveTreeDataProvider
119119
appTraceArchiveNode.fileName = label;
120120
appTraceArchiveNode.filePath = join(traceFolder, fileName);
121121
appTraceArchiveNode.type = type;
122-
appTraceArchiveNode.command = {
123-
command: "espIdf.apptrace.archive.showReport",
124-
title: "Show Report",
125-
arguments: [appTraceArchiveNode],
126-
};
122+
123+
// Only set command for Heap Trace items - App Trace items will open the file directly
127124
if (appTraceArchiveNode.type === TraceType.HeapTrace) {
125+
appTraceArchiveNode.command = {
126+
command: "espIdf.apptrace.archive.showReport",
127+
title: "Show Report",
128+
arguments: [appTraceArchiveNode],
129+
};
128130
appTraceArchiveNode.iconPath = new vscode.ThemeIcon("pulse");
129131
} else {
132+
// For App Trace, set command to open file directly
133+
appTraceArchiveNode.command = {
134+
command: "vscode.open",
135+
title: "Open File",
136+
arguments: [vscode.Uri.file(appTraceArchiveNode.filePath)],
137+
};
130138
appTraceArchiveNode.iconPath = new vscode.ThemeIcon("archive");
131139
}
140+
132141
const traceSize = statSync(appTraceArchiveNode.filePath);
133-
appTraceArchiveNode.description = `${this.sinceAgo(name[1].split(".trace")[0])} ${traceSize.size}B`;
134-
appTraceArchiveNode.tooltip = `${label} has ${traceSize.size} bytes (${this.sinceAgo(name[1].split(".trace")[0])})`;
142+
appTraceArchiveNode.description = `${this.sinceAgo(
143+
name[1].split(".trace")[0]
144+
)} ${traceSize.size}B`;
145+
appTraceArchiveNode.tooltip = `${label} has ${
146+
traceSize.size
147+
} bytes (${this.sinceAgo(name[1].split(".trace")[0])})`;
135148
return appTraceArchiveNode;
136149
}
137150
private sinceAgo(epoch: string): string {

src/extension.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ export async function activate(context: vscode.ExtensionContext) {
25652565
if (appTraceLabel) {
25662566
await appTraceManager.start(workspaceRoot);
25672567
} else {
2568-
await appTraceManager.stop();
2568+
await appTraceManager.stop(workspaceRoot);
25692569
}
25702570
});
25712571
});
@@ -2972,6 +2972,31 @@ export async function activate(context: vscode.ExtensionContext) {
29722972
);
29732973
}
29742974
}
2975+
2976+
// For App Trace, directly open the file instead of showing the webview
2977+
if (trace.type === TraceType.AppTrace) {
2978+
try {
2979+
const textDocument = await vscode.workspace.openTextDocument(
2980+
trace.filePath
2981+
);
2982+
const column = vscode.window.activeTextEditor
2983+
? vscode.window.activeTextEditor.viewColumn
2984+
: undefined;
2985+
await vscode.window.showTextDocument(textDocument, {
2986+
viewColumn: column || vscode.ViewColumn.One,
2987+
});
2988+
return;
2989+
} catch (error) {
2990+
Logger.errorNotify(
2991+
`Failed to open App Trace file: ${error.message}`,
2992+
error,
2993+
"extension apptrace showReport openFile"
2994+
);
2995+
return;
2996+
}
2997+
}
2998+
2999+
// For Heap Trace, show the webview as before
29753000
AppTracePanel.createOrShow(context, {
29763001
trace: {
29773002
fileName: trace.fileName,

0 commit comments

Comments
 (0)