import ittapi
from argparse import ArgumentParser
from vtune_tool import run_vtune_hotspot_collection
from workload import workload
def run_sample():
@ittapi.event
def my_function_1():
workload()
@ittapi.event()
def my_function_2():
workload()
@ittapi.event('my function 3')
def my_function_3():
workload()
@ittapi.event
@ittapi.event('my function 4')
def my_function_4():
workload()
with ittapi.event():
workload()
with ittapi.event('my event'):
workload()
my_function_1()
my_function_2()
my_function_3()
my_function_4()
overlapped_event_1 = ittapi.event('overlapped event 1')
overlapped_event_1.begin()
workload()
overlapped_event_2 = ittapi.event('overlapped event 2')
overlapped_event_2.begin()
workload()
overlapped_event_1.end()
workload()
overlapped_event_2.end()
class CallableClass:
def __call__(self, *args, **kwargs): workload()
callable_object = ittapi.event(CallableClass())
callable_object()
if __name__ == '__main__':
parser = ArgumentParser(description='The sample that demonstrates the use of wrappers for the Event API.')
parser.add_argument('--run-sample',
help='Runs code that uses wrappers for the Event API.',
action='store_true')
args = parser.parse_args()
if args.run_sample:
run_sample()
else:
run_vtune_hotspot_collection(['python', __file__, '--run-sample'])