采集操作

为了获取用户和上层框架程序的性能数据,Profiling开启msproftx功能之前,需要在程序内调用msproftx相关接口(Profiling pyACL API扩展接口)来对用户程序进行打点以输出对应的性能数据。

调用接口如Profiling pyACL API扩展接口所示,调用示例如Profiling pyACL API扩展接口调用示例所示。

Profiling pyACL API扩展接口

表1 Profiling pyACL API扩展接口

接口

说明

acl.prof.create_stamp

创建msproftx事件标记,用于描述瞬时事件。

acl.prof.set_stamp_trace_message

为msproftx事件标记携带描述信息,在Profiling解析结果中msprof_tx summary数据展示。

acl.prof.mark

msproftx标记瞬时事件。

acl.prof.push

msproftx用于记录事件发生的时间跨度的开始时间。与acl.prof.pop成对使用,仅能在单线程内使用。

acl.prof.pop

msproftx用于记录事件发生的时间跨度的结束时间。与acl.prof.push成对使用,仅能在单线程内使用。

acl.prof.range_start

msproftx用于记录事件发生的时间跨度的开始时间。与acl.prof.range_stop成对使用,可跨线程使用。

acl.prof.range_stop

msproftx用于记录事件发生的时间跨度的结束时间。与acl.prof.range_start成对使用,可跨线程使用。

acl.prof.destroy_stamp

释放msproftx事件标记。

Profiling pyACL API扩展接口调用示例

Profiling msproftx接口,示例如下加粗部分代码。

示例一:

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)

示例二:

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)

# acl.prof.push 和 acl.prof.pop 接口配对使用,完成单线程采集
    ret = acl.prof.push(stamp)
    ret = acl.prof.pop()

    ret = acl.prof.destroy_stamp(stamp)

示例三:

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)

# acl.prof.range_start 和 acl.prof.range_stop 接口配对使用,可以完成多线程采集
    range_id = 0
    range_id, ret = acl.prof.range_start(stamp)
    ret = acl.prof.range_stop(range_id)

    ret = acl.prof.destroy_stamp(stamp)

Profiling AscendCL API扩展接口在main函数内调用。