3. Python examples

You can use the PopVision tracing API in Python. See the example below.

In order to start with the tracing API you need to import the libpvti library:

import libpvti

You can create your own trace channel:

def create_trace_channel():
  channel = pvti.createTraceChannel("Trace Channel")
  return channel

You can create events in your newly created channel or you can use one of default channels:

def create_trace_events():
  channel = pvti.createTraceChannel("Trace Channel")
  pvti.Tracepoint.begin(channel, "My begin event") 
  pvti.Tracepoint.event(pvti.traceDrivers, "My event") 
  pvti.Tracepoint.end(pvti.tracePoplar, "My end event") 

You can associate JSON metadata with the events:

def create_trace_events_with_metadata():
  j = '{"Temperature": 90.0}'
  m = pvti.createJsonMetadata(j)
  pvti.Tracepoint.begin(pvti.traceDrivers, "Sensor reading", m)

You can use high level json library to conveniently generate JSON objects:

def create_trace_events_with_metadata2():
  import json
  j = {}
  j["Temperature"] = 90
  j["Unit"] = "Celsius"
  m = pvti.createJsonMetadata(json.dumps(j))
  pvti.Tracepoint.begin(pvti.traceDrivers, "Sensor reading 2", m)

You can create graphs and data series to record performance metrics. Series can be enabled or disabled during runtime:

def create_graphs_and_data_series():
  graph = pvti.Graph("Utilisation", "%")
  ipu1 = graph.addSeries("IPU 1")
  ipu2 = graph.addSeries("IPU 2")

The PopVision tutorial on Instrumenting applications contains more information about using the libpvti Python module.