Exporting Profile Data

Before exporting profile data, finish profile data parsing. For details, see Parsing Profile Data. Start profile data export as follows:

  1. Log in to the development environment as the Ascend-CANN-Toolkit running user.
  2. Switch to the directory where the msprof.py script is located.

    ${INSTALL_DIR}/tools/profiler/profiler_tool/analysis/msprof. Replace ${INSTALL_DIR} with the actual CANN component directory. If the Ascend-CANN-Toolkit package is installed as the root user, the CANN component directory is /usr/local/Ascend/ascend-toolkit/latest.

    Quick tip: Create an alias for the msprof.py script with the command alias msprof_analysis='python3 msprof.py_script_directory' as the running user. Then, you can start profiling with the shortcut msprof_analysis in any directory. This operation takes effect only in the current window.

  3. Export profile data. The timeline, summary, and db files can be exported. The command formats are as follows:
    • Exporting timeline reports
      python3 msprof.py export timeline -dir <dir> [--iteration-id <iteration_id>] [--model-id <model-id>] [--iteration-count <iteration_count>] [--clear]

      Example: python3 msprof.py export timeline -dir /home/HwHiAiUser/profiler_data/PROF_XXX

    • Exporting summary reports
      python3 msprof.py export summary -dir <dir> [--iteration-id <iteration_id>] [--model-id <model-id>] [--iteration-count <iteration_count>] [--format <export_format>] [--clear]

      Example: python3 msprof.py export summary -dir /home/HwHiAiUser/profiler_data/PROF_XXX

    • Exporting db data
      python3 msprof.py export db -dir <dir>

      Generate a .db file (msprof_timestamp.db) that summarizes all profile data.

      Example: python3 msprof.py export db -dir /home/HwHiAiUser/profiler_data/PROF_XXX

    Table 1 Command-line options

    Option

    Description

    Required/Optional

    -dir, --collection-dir

    Directory of collected profile data. The value must be PROF_XXX or the parent directory of PROF_XXX, for example,

    /home/HwHiAiUser/profiler_data/PROF_XXX

    Required

    --iteration-id

    Iteration ID. The value must be a positive integer. This option and --model-id must be configured at the same time.

    • If --model-id is set to other values, this option specifies the iteration ID for graph-based statistics collection. (The iteration ID increases by 1 each time a graph is executed. When a script is compiled into multiple graphs, the iteration ID is different from the step ID at the script layer.)

    Optional

    --model-id

    Model ID. The value must be a positive integer. This option and --iteration-id must be configured at the same time.

    Optional

    --iteration-count

    Number of exported iterations.

    Optional

    --format

    File format, either csv (default) or json.

    This option is supported only when the summary parameter is configured.

    The following uses summary files in .csv format as examples.

    Optional

    --clear

    Data clearance mode. After this option is enabled, the sqlite directory in PROF_XXX/device_{id} is deleted after profile data is exported, so as to save storage space. When this parameter is configured, the data clearance mode is enabled. This parameter is not configured by default.

    Optional

    -h, --help

    Help information.

    Optional

    Note 1: For the Atlas 200/300/500 Inference Product, if --iteration-id and --model-id are not configured, profile data of the model (model ID) with the largest number of iterations is exported by default. For other processors, all profile data is exported by default.

    Note 2: In single-operator scenarios and scenarios where only Collecting Ascend AI Processor System Data is involved, --iteration-id and --model-id are not supported.

  4. After the preceding command is executed, the mindstudio_profiler_output directory is generated in the PROF_XXX directory under collection-dir.

    The following shows the directory structure of the generated profile data:

    When the export db command is executed, a .db file (msprof_timestamp.db) that summarizes all profile data is generated in the PROF_XXX directory, and the mindstudio_profiler_output directory is not generated.

    • Single-process collection
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      └── PROF_XXX
            ├── device_0
                └── data
            ├── device_1
                └── data
            ├── host
                └── data
            └── mindstudio_profiler_output
                  ├── msprof_{timestamp}.json
                  ├── step_trace_{timestamp}.json
                  ├── xx_*.csv
                   ...
                  └── README.txt
      
    • Multi-process collection
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      └── PROF_XXX1
            ├── device_0
                └── data
            ├── host
                └── data
            └── mindstudio_profiler_output
                  ├── msprof_{timestamp}.json
                  ├── step_trace_{timestamp}.json
                  ├── xx_*.csv
                   ...
                  └── README.txt
      └── PROF_XXX2
            ├── device_1
                └── data
            ├── host
                └── data
            └── mindstudio_profiler_output
                  ├── msprof_{timestamp}.json
                  ├── step_trace_{timestamp}.json
                  ├── xx_*.csv
                   ...
                  └── README.txt
      
    • In multi-device scenarios, if single-process collection is started, only one PROF_XXX directory is generated. If multi-process collection is started, multiple PROF_XXX directories are generated. In addition, the Device directory is generated in the PROF_XXX directory. The number of Device directories generated in each PROF_XXX directory is related to the actual user operations and does not affect profile data analysis.
    • For details about profile data, see Profile Data File References.
    • The files in the mindstudio_profiler_output directory are generated based on the actual collected profile data. If the necessary profile data file is absent, the corresponding timeline and summary data will be unavailable.
    • You can run the export command to directly export summary reports from the profile data parsing result. Even the profile data has not been parsed, the export command can parse the profile data and export the reports.
    • For a msprof collection process that is forcibly interrupted, the tool saves the collected raw profile data. You can also run export to parse and export the data.