Calling nvprof from a pythoon code

I want to turn on the nvprof inside a python code. The code looks like

for batch, i in enumerate(range(0, train_data.size(0) - 1, args.bptt)):
        data, targets = get_batch(train_data, i)
        hidden = repackage_hidden(hidden)
        output, hidden = model(data, hidden)
        loss = criterion(output.view(-1, ntokens), targets)

And I want to insert profiling after getting the batch. Any idea?