Using msproftx APIs to Collect and Flush Profile Data
To collect the profile data of the user and upper-layer framework applications, instrument the code using msproftx APIs before enabling the profiling tool.
API Overview
API |
Description |
|---|---|
acl.prof.create_stamp |
Creates a msproftx event stamp for an instantaneous event. |
acl.prof.set_stamp_trace_message |
Sets the description in a msproftx event stamp, which is displayed in the parsed msprof_tx summary data of the Profiling tool. |
acl.prof.mark |
Marks an instantaneous event by msproftx. |
acl.prof.push |
Records the start time of the time span by msproftx when an event occurs. It is used with acl.prof.pop in pairs and can be used only in a single thread. |
acl.prof.pop |
Records the end time of the time span by msproftx when an event occurs. It is used with acl.prof.push in pairs and can be used only in a single thread. |
acl.prof.range_start |
Records the start time of the time span by msproftx when an event occurs. It is used with acl.prof.range_stop in pairs and can be used across threads. |
acl.prof.range_stop |
Records the end time of the time span by msproftx when an event occurs. It is used with acl.prof.range_start in pairs and can be used across threads. |
acl.prof.destroy_stamp |
Destroys a msproftx event stamp. |
API Call Examples
The following is the sample code of the msproftx Profiling API:
- Example 1
1 2 3 4 5 6 7 8 9 10 11 12
for i in range(200000): stamp = acl.prof.create_stamp() if stamp == 0: print("stamp is nullptr") return FAILED msg = "test msprof tx" msg_len = len(msg) ret = acl.prof.set_stamp_trace_message(stamp, msg, msg_len) ret = acl.prof.mark(stamp) ret = acl.prof.destroy_stamp(stamp)
- Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
for i in range(200000): stamp = acl.prof.create_stamp() if stamp == 0: print("stamp is nullptr") return FAILED msg = "test msprof tx" msg_len = len(msg) ret = acl.prof.set_stamp_trace_message(stamp, msg, msg_len) # The acl.prof.push and acl.prof.pop APIs are used in pairs to complete single-thread profiling. ret = acl.prof.push(stamp) ret = acl.prof.pop() ret = acl.prof.destroy_stamp(stamp)
- Example 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for i in range(200000): stamp = acl.prof.create_stamp() if stamp == 0: print("stamp is nullptr") return FAILED msg = "test msprof tx" msg_len = len(msg) ret = acl.prof.set_stamp_trace_message(stamp, msg, msg_len) # The acl.prof.range_start and acl.prof.range_stop APIs are used in pairs to complete multi-thread profiling. range_id = 0 range_id, ret = acl.prof.range_start(stamp) ret = acl.prof.range_stop(range_id) ret = acl.prof.destroy_stamp(stamp)
msproftx APIs are called within the main function.