memgraph/tests/macro_benchmark/harness/perf.py
Mislav Bradac 5e3ff2438e Fix some benchmarks
Summary: Fix bug in perf wrapper

Reviewers: mferencevic

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D611
2017-07-30 20:12:25 +02:00

33 lines
1005 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from pathlib import Path
import subprocess
import signal
class Perf():
def __init__(self):
self.first = True
self.max_frequency = Path(
"/proc/sys/kernel/perf_event_max_sample_rate").read_text().strip()
# Check if lbr is available.
status = subprocess.call(
"perf record --call-graph=lbr -a -g sleep 0.0000001".split())
self.call_graph_technique = "lbr" if not status else "dwarf"
def start(self, pid, frequency=None):
if frequency is None: frequency = self.max_frequency
append = "-A" if not self.first else ""
self.first = False
perf_command = "perf record --call-graph={} -F {} -p {} -g {}".format(
self.call_graph_technique, frequency, pid, append).split()
self.perf_proc = subprocess.Popen(perf_command)
def stop(self):
self.perf_proc.send_signal(signal.SIGINT)
self.perf_proc.wait()