Skip to content

Commit 63c12cc

Browse files
committed
format code
1 parent 51ff3d1 commit 63c12cc

File tree

16 files changed

+480
-381
lines changed

16 files changed

+480
-381
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ jobs:
3333
# - name: tests
3434
# run: |
3535
# ./run_tests.sh
36-

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 22.10.0
10+
hooks:
11+
- id: black

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ Performance counters are special hardware registers available on most modern CPU
6767
+ **rdmsr**: Reads the contents of a 64-bit model specific register (MSR) specified in the ECX register into registers EDX:EAX. This instruction must be executed at privilege level 0 or in real-address mode
6868

6969
+ **rdpmc**: Is slightly faster that the equivelent rdmsr instruction. rdpmc can also be configured to allow access to the counters from userspace, without being priviledged.
70-
+ **From Userspace** (Linux) : The Linux Performance Counter subsystem provides an abstraction of these hardware capabilities. It provides per task and per CPU counters, counter groups, and it provides event capabilities on top of those. It provides "virtual" 64-bit counters, regardless of the width of the underlying hardware counters. Performance counters are accessed via special file descriptors. There's one file descriptor per virtual counter used. The special file descriptor is opened via the perf_event_open() system call. These system call do not use rdpmc but rdpmc is not necessarily faster than other methods for reading event values.
70+
+ **From Userspace** (Linux) : The Linux Performance Counter subsystem provides an abstraction of these hardware capabilities. It provides per task and per CPU counters, counter groups, and it provides event capabilities on top of those. It provides "virtual" 64-bit counters, regardless of the width of the underlying hardware counters. Performance counters are accessed via special file descriptors. There's one file descriptor per virtual counter used. The special file descriptor is opened via the perf_event_open() system call. These system call do not use rdpmc but rdpmc is not necessarily faster than other methods for reading event values.

install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ sudo apt install g++ gcc swig libpfm4-dev python3-dev python3-pip
55
cd profiler/
66
python3 setup.py build
77
python3 setup.py install
8-

main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import numpy as np
44

55
try:
6-
evs_monitor= [["PERF_COUNT_HW_INSTRUCTIONS"],["SYSTEMWIDE:RAPL_ENERGY_PKG"]]
7-
program= Profiler(program_args=['./tests/simple_bench'], events_groups=evs_monitor)
8-
data= program.run(sample_period=0.01,reset_on_sample=False)
9-
df= pd.DataFrame(data, columns= ["inst","energy"] )
10-
df["energy"]*=2.3283064365386962890625e-10
6+
evs_monitor = [["PERF_COUNT_HW_INSTRUCTIONS"], ["SYSTEMWIDE:RAPL_ENERGY_PKG"]]
7+
program = Profiler(program_args=["./tests/simple_bench"], events_groups=evs_monitor)
8+
data = program.run(sample_period=0.01, reset_on_sample=False)
9+
df = pd.DataFrame(data, columns=["inst", "energy"])
10+
df["energy"] *= 2.3283064365386962890625e-10
1111
print(df)
1212
except RuntimeError as e:
13-
print(e.args[0])
13+
print(e.args[0])

profiler/MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
recursive-include perfmon/include/ *
22
include profiler/workload.cpp
33
include profiler/workload.h
4-
include ../README.md
4+
include ../README.md

profiler/perfmon/pmu.py

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,78 +25,83 @@
2525
import os
2626
from perfmon import *
2727

28+
2829
def public_members(self):
2930
s = "{ "
3031
for k, v in self.__dict__.items():
31-
if not k[0] == '_':
32-
s += "%s : %s, " % (k, v)
32+
if not k[0] == "_":
33+
s += "%s : %s, " % (k, v)
3334
s += " }"
3435
return s
3536

37+
3638
class System:
37-
# Use the os that gives us everything
38-
os = PFM_OS_PERF_EVENT_EXT
39-
40-
def __init__(self):
41-
self.ncpus = os.sysconf('SC_NPROCESSORS_ONLN')
42-
self.pmus = []
43-
for i in range(0, PFM_PMU_MAX):
44-
try:
45-
pmu = PMU(i)
46-
except:
47-
pass
48-
else:
49-
self.pmus.append(pmu)
50-
51-
def __repr__(self):
52-
return public_members(self)
39+
# Use the os that gives us everything
40+
os = PFM_OS_PERF_EVENT_EXT
41+
42+
def __init__(self):
43+
self.ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
44+
self.pmus = []
45+
for i in range(0, PFM_PMU_MAX):
46+
try:
47+
pmu = PMU(i)
48+
except:
49+
pass
50+
else:
51+
self.pmus.append(pmu)
52+
53+
def __repr__(self):
54+
return public_members(self)
55+
5356

5457
class Event:
55-
def __init__(self, info):
56-
self.info = info
57-
self.__attrs = []
58+
def __init__(self, info):
59+
self.info = info
60+
self.__attrs = []
61+
62+
def __repr__(self):
63+
return "\n" + public_members(self)
5864

59-
def __repr__(self):
60-
return '\n' + public_members(self)
65+
def __parse_attrs(self):
66+
info = self.info
67+
for index in range(0, info.nattrs):
68+
self.__attrs.append(pfm_get_event_attr_info(info.idx, index, System.os)[1])
6169

62-
def __parse_attrs(self):
63-
info = self.info
64-
for index in range(0, info.nattrs):
65-
self.__attrs.append(pfm_get_event_attr_info(info.idx, index,
66-
System.os)[1])
70+
def attrs(self):
71+
if not self.__attrs:
72+
self.__parse_attrs()
73+
return self.__attrs
6774

68-
def attrs(self):
69-
if not self.__attrs:
70-
self.__parse_attrs()
71-
return self.__attrs
7275

7376
class PMU:
74-
def __init__(self, i):
75-
self.info = pfm_get_pmu_info(i)[1]
76-
self.__events = []
77-
78-
def __parse_events(self):
79-
index = self.info.first_event
80-
while index != -1:
81-
self.__events.append(Event(pfm_get_event_info(index, System.os)[1]))
82-
index = pfm_get_event_next(index)
83-
84-
def events(self):
85-
if not self.__events:
86-
self.__parse_events()
87-
return self.__events
88-
89-
def __repr__(self):
90-
return public_members(self)
91-
92-
if __name__ == '__main__':
93-
from perfmon import *
94-
s = System()
95-
for pmu in s.pmus:
96-
info = pmu.info
97-
if info.flags.is_present:
98-
print(info.name, info.size, info.nevents)
99-
for e in pmu.events():
100-
print(e.info.name, e.info.code)
101-
for a in e.attrs():
102-
print('\t\t', a.name, a.code)
77+
def __init__(self, i):
78+
self.info = pfm_get_pmu_info(i)[1]
79+
self.__events = []
80+
81+
def __parse_events(self):
82+
index = self.info.first_event
83+
while index != -1:
84+
self.__events.append(Event(pfm_get_event_info(index, System.os)[1]))
85+
index = pfm_get_event_next(index)
86+
87+
def events(self):
88+
if not self.__events:
89+
self.__parse_events()
90+
return self.__events
91+
92+
def __repr__(self):
93+
return public_members(self)
94+
95+
96+
if __name__ == "__main__":
97+
from perfmon import *
98+
99+
s = System()
100+
for pmu in s.pmus:
101+
info = pmu.info
102+
if info.flags.is_present:
103+
print(info.name, info.size, info.nevents)
104+
for e in pmu.events():
105+
print(e.info.name, e.info.code)
106+
for a in e.attrs():
107+
print("\t\t", a.name, a.code)

profiler/perfmon/session.py

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,57 @@
2727

2828
# Common base class
2929
class Session:
30-
def __init__(self, events):
31-
self.system = System()
32-
self.event_names = events
33-
self.events = []
34-
self.fds = []
35-
for e in events:
36-
err, encoding = pfm_get_perf_event_encoding(e, PFM_PLM0 | PFM_PLM3,
37-
None, None)
38-
self.events.append(encoding)
30+
def __init__(self, events):
31+
self.system = System()
32+
self.event_names = events
33+
self.events = []
34+
self.fds = []
35+
for e in events:
36+
err, encoding = pfm_get_perf_event_encoding(
37+
e, PFM_PLM0 | PFM_PLM3, None, None
38+
)
39+
self.events.append(encoding)
3940

40-
def __del__(self):
41-
pass
41+
def __del__(self):
42+
pass
43+
44+
def read(self, fd):
45+
# TODO: determine counter width
46+
return os.read(fd, 8)
4247

43-
def read(self, fd):
44-
# TODO: determine counter width
45-
return os.read(fd, 8)
4648

4749
class SystemWideSession(Session):
48-
def __init__(self, cpus, events):
49-
self.cpus = cpus
50-
Session.__init__(self, events)
50+
def __init__(self, cpus, events):
51+
self.cpus = cpus
52+
Session.__init__(self, events)
53+
54+
def __del__(self):
55+
Session.__del__(self)
5156

52-
def __del__(self):
53-
Session.__del__(self)
57+
def start(self):
58+
self.cpu_fds = []
59+
for c in self.cpus:
60+
self.cpu_fds.append([])
61+
cur_cpu_fds = self.cpu_fds[-1]
62+
for e in self.events:
63+
cur_cpu_fds.append(perf_event_open(e, -1, c, -1, 0))
5464

55-
def start(self):
56-
self.cpu_fds = []
57-
for c in self.cpus:
58-
self.cpu_fds.append([])
59-
cur_cpu_fds = self.cpu_fds[-1]
60-
for e in self.events:
61-
cur_cpu_fds.append(perf_event_open(e, -1, c, -1, 0))
65+
def read(self, c, i):
66+
index = self.cpus.index(c)
67+
return Session.read(self, self.cpu_fds[index][i])
6268

63-
def read(self, c, i):
64-
index = self.cpus.index(c)
65-
return Session.read(self, self.cpu_fds[index][i])
6669

6770
class PerThreadSession(Session):
68-
def __init__(self, pid, events):
69-
self.pid = pid
70-
Session.__init__(self, events)
71+
def __init__(self, pid, events):
72+
self.pid = pid
73+
Session.__init__(self, events)
7174

72-
def __del__(self):
73-
Session.__del__(self)
75+
def __del__(self):
76+
Session.__del__(self)
7477

75-
def start(self):
76-
for e in self.events:
77-
self.fds.append(perf_event_open(e, self.pid, -1, -1, 0))
78+
def start(self):
79+
for e in self.events:
80+
self.fds.append(perf_event_open(e, self.pid, -1, -1, 0))
7881

79-
def read(self, i):
80-
return Session.read(self, self.fds[i])
82+
def read(self, i):
83+
return Session.read(self, self.fds[i])

profiler/profiler/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . profiler import *
2-
from . events import *
3-
from . compare import *
1+
from .profiler import *
2+
from .events import *
3+
from .compare import *

0 commit comments

Comments
 (0)