Rate This Document
Findability
Accuracy
Completeness
Readability

Profiling Process

Prerequisites

  • The server and OS are running properly.
  • An SSH remote login tool has been installed on the local PC.
  • The System Profiler has been installed in the target environment and is running properly.
  • GCC 7.3.0 has been installed in the target environment.

Procedure

This function is used to accumulate a variable by multiple threads. Obtain the required demo from testdemo.

When using the demo, note the following:

  1. The GCC version must be 7.3 or later. If you use an earlier version to compile pthread_atomic.c, an error will be reported.
  2. If the GCC version is 10.x.x or later, you are advised to add the -march=armv8-a+nolse -mno-outline-atomics parameter to disable the LSE instruction set during compilation because the LSE instruction set is enabled by default in this version and impairs the tuning effect.
  3. To associate the source code, you are advised to add the -g parameter during compilation. Run file pthread_mutex to check whether BuildID exists in the compiled binary file. If it does not exist, add the -Wl,--build-id parameter. Example: gcc -g -Wl,--build-id pthread_mutex.c -o pthread_mutex -lpthread
  4. If you create a hotspot function analysis task to check lock contention of your system, run the corresponding application demo in the backend when starting the task. Otherwise, lock contention data cannot be collected.
  5. For more details about the demo, see readme.
  1. Create a hotspot function analysis task.

    Click next to the System Profiler and select General analysis. On the task creation page that is displayed, select Hotspot Function, set the required parameters, and click OK to start the hotspot function analysis task. Retain the default values for the parameters unless otherwise specified.

    Figure 1 Creating a hotspot function analysis task
    Table 1 Task parameters

    Parameter

    Description

    Analysis Type

    Set it to Hotspot functions.

    Analysis Object

    Set it to Application.

    Application Path

    /opt/testdemo/pthread_mutex

    Sampling Duration

    Set it to 30.

    Sampling Frequency

    100 times per second

    Sampling Range

    Set it to User mode.

    dwarf

    Enable this option.

    C/C++ Source File Directory

    Associates the source code during collection. Example: /opt/testdemo/

  2. View the analysis result.
    Figure 2 Overview

    As shown in the preceding figure, the ratio of the clock cycles of the two functions corresponding to the two threads is small. The main hot spot lies in the mutex corresponding to glibc.

  3. Create a lock and wait analysis task.

    Click next to the System Profiler and select General analysis. On the task creation page that is displayed, select Locks and Waits, set the required parameters, and click OK to start the lock and wait analysis task. Retain the default values for the parameters unless otherwise specified.

    Figure 3 Creating a lock and wait analysis task
    Table 2 Task parameters

    Parameter

    Description

    Analysis Type

    Set it to Lock and wait analysis.

    Analysis Object

    Set it to Application.

    Mode

    Set it to Attach to process.

    PID

    Select the process ID corresponding to the pthread_mutex application.

    Lock Analysis Type

    Select all (select Histogram statistics and Lock variable analysis).

    Predefined Lock Type

    Retain the default value.

    Sampling Duration

    Set it to 60.

    Max. Collected Data

    Set it to 1024.

    Stack Analysis

    Set it to Disabled.

  4. View the analysis result.
    Figure 4 Lock and Wait Information

    The calling status of related locks and the source code of the corresponding function are displayed. A mutex needs to be used before and after the accumulation operation is performed on the variable num to ensure that the operation of reading a thread is executed. However, the actual efficiency of the application is low. Excessive overhead is spent on the acquire and release of the mutex.