Skip to content
Snippets Groups Projects
Commit cc3c905f authored by Georges Da Costa's avatar Georges Da Costa
Browse files

Adds performance monitoring comming from linux/perf tools

parent d8a6a0b0
No related branches found
No related tags found
No related merge requests found
import os
import stat
def read_int(filename):
"""Read integer from file filename"""
with open(filename) as file_id:
return int(file_id.readline())
class Lperf:
'Monitoring using a modified version of Linux Perf tool'
def __init__(self, sensor_set={'instructions'}, interval=100):
self.executor = None
self.names = sensor_set
self.interval = interval
self.cmdline = ''
def build(self, executor):
"""Installs and modifies the Linux Perf Tool"""
current_path=os.path.dirname(os.path.abspath(__file__))
if not os.path.exists('/tmp/lperf/tools/perf/perf'):
executor.local('mkdir /tmp/lperf; tar xj -C /tmp/lperf/ -f %s/lperf_tools.tar.bz2' % current_path)
executor.local('patch -i %s/lperf_builtin-stat.diff /tmp/lperf/tools/perf/builtin-stat.c' % current_path)
executor.local('cd /tmp/lperf/tools/perf/; make')
executor.local('cp /tmp/lperf/tools/perf/perf /tmp/bin/lperf')
if read_int('/proc/sys/kernel/perf_event_paranoid') != 0:
executor.hosts("sh -c 'echo 0 >/proc/sys/kernel/perf_event_paranoid'", root=True)
self.executor = executor
self.cmdline = '/tmp/bin/lperf stat -x " " -I %s -a -A -e %s' % (self.interval, ' '.join(self.names))
self.cmdline += ' -o /dev/shm/lperf_monitoring &'
def start(self):
'Starts the monitoring right before the benchmark'
self.executor.hosts(self.cmdline)
def stop(self):
'Stops the monitoring right before the benchmark'
self.executor.hosts('killall lperf')
def save(self, experiment, benchname, beg_time):
'Save the results when time is no more critical'
filename_moj = experiment.output_file+'_lperf'
os.makedirs(filename_moj, exist_ok=True)
if len(self.executor.hostnames) > 1:
for hostname in self.executor.hostnames:
self.executor.local('oarcp %s:/dev/shm/lperf_monitoring %s/%s_%s_%s' %
(hostname, filename_moj, hostname, benchname, beg_time))
else:
self.executor.local('cp /dev/shm/lperf_monitoring %s/%s_%s_%s' %
(filename_moj, 'localhost', benchname, beg_time))
--- /tmp/builtin-stat.c 2021-04-21 14:21:15.022060847 +0200
+++ builtin-stat.c 2021-04-21 14:26:22.983556200 +0200
@@ -474,7 +474,7 @@
perf_stat__reset_shadow_per_stat(&rt_stat);
runtime_stat_reset(&stat_config);
- read_counters(&rs);
+ read_counters(&ts);
if (STAT_RECORD) {
if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL))
@@ -483,7 +483,7 @@
init_stats(&walltime_nsecs_stats);
update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000ULL);
- print_counters(&rs, 0, NULL);
+ print_counters(&ts, 0, NULL);
}
static bool handle_interval(unsigned int interval, int *times)
@@ -628,6 +628,17 @@
time_to_sleep = sleep_time;
+ clock_gettime(CLOCK_MONOTONIC, &time_start);
+ if(interval > 1000) {
+ time_start.tv_sec+=1;
+ usleep(time_start.tv_nsec / 1000);
+ time_start.tv_nsec=0;
+ } else {
+ time_to_sleep -= (time_start.tv_nsec/1000000) % interval;
+ time_start.tv_nsec -= time_start.tv_nsec % (1000000*interval);
+ }
+
+
while (!done) {
if (forks)
child_exited = waitpid(child_pid, &status, WNOHANG);
@@ -637,16 +648,17 @@
if (child_exited)
break;
- clock_gettime(CLOCK_MONOTONIC, &time_start);
if (!(evlist__poll(evsel_list, time_to_sleep) > 0)) { /* poll timeout or EINTR */
if (timeout || handle_interval(interval, times))
break;
time_to_sleep = sleep_time;
} else { /* fd revent */
process_evlist(evsel_list, interval);
- clock_gettime(CLOCK_MONOTONIC, &time_stop);
- compute_tts(&time_start, &time_stop, &time_to_sleep);
}
+ clock_gettime(CLOCK_MONOTONIC, &time_stop);
+ compute_tts(&time_start, &time_stop, &time_to_sleep);
+ time_start.tv_sec += interval / 1000;
+ time_start.tv_nsec += (interval % 1000)*1000000;
}
return status;
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment