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

In launch mode, the user program must be passed. For details about app, see app Parameters. For details about options, see Table 1. Other profiling options can also be added, for example, parameters in Profiling AI Tasks When They Are Running or Profiling System Data of the AI processor.

Command-line Options

Table 1 Options

Option

Optional/Required

Description

--dynamic

Required

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

--pid

Required for attach mode; not required for launch mode

PID of the application to profile.

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

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 ',' -

--output

Optional

Path for storing profile data. By default, this parameter is not configured, indicating that profile data is saved in the current path.

The path cannot contain the following characters: "\n", "\\n", "\f", "\\f", "\r", "\\r", "\b", "\\b", "\t", "\\t", "\v", "\\v", "\u007F", "\\u007F", "\"", "\\\"", "'", "\'", "\\", "\\\\", "%", "\\%", ">", "\\>", "<", "\\<", "|", "\\|", "&", "\\&", "$", "\\$", ";", "\\;", "`", and "\\`".

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.

After quit is executed, the AI task continues to run normally. You can run the msprof dynamic profiling command again to re-enter the interactive mode and restart dynamic profile data collection.

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.