Dynamic Profiling

Function

You can start or stop the profiling process at any time during the profiling. Dynamic profiling can be performed in launch or attach mode.

Precautions

Command Format

Command-line Options

Table 1 Options

Option

Optional/Required

Description

--dynamic

Required in launch mode

Switch that controls dynamic profile data collection, either on or off (default).

--pid

Required in attach mode

PID of the application to profile.

You can configure one or more PIDs at a time, for example, --pid 1,2,3.

--dynamic and --pid cannot be passed at the same time.

For details about how to obtain the PID, see Obtaining the PID of an AI Task. You can also run the following command to obtain all PIDs that can be profiled in the current environment:

ls ~/dynamic_profiling_socket_* 2>/dev/null | awk -F '_' '{print $4}' | paste -sd ',' -

start

Optional

Starts collection.

NOTE:
  • You can run the start and stop commands up to 100 times combined. Exceeding this limit will cause the server to disconnect, limiting profile samples to 50. When the server is reconnected, the count will be reset.
  • Repeatedly using start and stop commands might halt the profiling process with the stop command, stopping CANN's data reporting. This triggers an ERROR log, but this is expected behavior.

stop

Optional

Stops collection. Each time the start and stop commands are executed, a PROF_XXX directory for storing the data file is generated in the path specified by the --output option.

quit

Optional

Stops collection and exits the interactive mode. The AI task is running properly. You can run the msprof command to enter the interactive mode again.

Example

Output Description

The PROF_XXX directory is generated in the directory specified by --output. You are advised to use the parsing command to parse and export profile data.

During dynamic profiling, if multiple PIDs are configured, the process of each PID generates its own PROF_XXX directory in the directory specified by --output. In this case, you are advised to set --output to the parent directory of PROF_XXX during parsing so that multiple PROF_XXX directories can be parsed at the same time.

Obtaining the PID of an AI Task

You can run the command below to view the PID that can be collected in the current environment, and then perform the following operations to obtain the PID:

ls ~/dynamic_profiling_socket_* 2>/dev/null | awk -F '_' '{print $4}' | paste -sd ',' -

In multi-device scenarios, you are advised to run AI tasks on each device one by one and obtain the PID in the preceding mode. If AI tasks are running on multiple devices at the same time, obtain any PID for profiling. Currently, multiple PIDs cannot be specified for dynamic profiling at the same time.