Skip to content

Commit 31c0b0e

Browse files
authored
bug fixes (#18)
1 parent 4f43c40 commit 31c0b0e

File tree

8 files changed

+74
-38
lines changed

8 files changed

+74
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/*
22
dist/*
33
pmu-checker/pmu-checker
44
src/libtsc.so
5+
__pycache__

Makefile

+15-30
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ VERSION_FILE := _version.txt
44
VERSION_BASE := $(COMMIT_DATE)_$(COMMIT_ID)
55
VERSION_NUMBER := $(shell cat ${VERSION_FILE})
66
VERSION_PUBLIC := $(VERSION_NUMBER)
7-
PACKAGE_EXTERNAL := perfspect_$(VERSION_NUMBER).tgz
7+
PACKAGE_EXTERNAL := perfspect.tgz
88
BINARY_FINAL := perfspect
99
BINARY_COLLECT := perf-collect
1010
BINARY_POSTPROCESS := perf-postprocess
11-
default: all
11+
default: dist
1212

13-
.PHONY: all test default dist clean format format_check security_scan flakes source_check checkmake dist/version_file dist/$(SOURCE_PACKAGE)
13+
.PHONY: test default dist format format_check style_error_check check dist/version_file dist/$(SOURCE_PACKAGE)
1414

1515
clean_dir:
1616
rm -rf build/*
@@ -34,22 +34,9 @@ build-public/collect:
3434
mkdir -p $(TMPDIR)/src
3535
mkdir -p $(TMPDIR)/events
3636
cp src/* $(TMPDIR)/src && cp events/* $(TMPDIR)/events && cp *.py $(TMPDIR)
37-
sed -i 's/PerfSpect_DEV_VERSION/$(VERSION_PUBLIC)/g' $(TMPDIR)/src/perf_helpers.py
38-
cd $(TMPDIR) && pyinstaller -F perf-collect.py -n $(BINARY_COLLECT) \
39-
--add-data "./src/libtsc.so:." \
40-
--add-data "./events/bdx.txt:." \
41-
--add-data "./events/skx.txt:." \
42-
--add-data "./events/clx.txt:." \
43-
--add-data "./events/icx.txt:." \
44-
--add-data "./events/spr.txt:." \
45-
--add-data "./events/icx_aws.txt:." \
46-
--add-data "./events/spr_aws.txt:." \
47-
--add-data "./events/clx_aws.txt:." \
48-
--add-data "./events/skx_aws.txt:." \
49-
--add-binary "../build/pmu-checker:." \
50-
--runtime-tmpdir . \
51-
--exclude-module readline
52-
37+
sed -i 's/PerfSpect_DEV_VERSION/$(VERSION_PUBLIC)/g' $(TMPDIR)/src/perf_helpers.py
38+
cp perf-collect.spec $(TMPDIR)
39+
cd $(TMPDIR) && pyinstaller perf-collect.spec
5340
cp $(TMPDIR)/dist/$(BINARY_COLLECT) build/
5441
rm -rf $(TMPDIR)
5542

@@ -87,18 +74,16 @@ test:
8774
cd dist && tar -xvf perfspect.tgz && cp -r $(BINARY_FINAL) ../test/.
8875
cd test && pytest
8976

90-
format:
91-
black src
92-
black *.py
93-
9477
format_check:
95-
black --check src
96-
black --check perf-collect.py perf-postprocess.py
78+
black --check *.py src
79+
80+
format:
81+
black *.py src
9782

98-
error_check: # ignore false positives
99-
flake8 --ignore=E501,W503,F403,F405,E741 src
100-
flake8 --ignore=E203,E501,E722,W503,F403,F405 *.py --exclude simpleeval.py,perfmon.py,average.py
83+
style_error_check:
84+
# ignore long lines and conflicts with black, i.e., black wins
85+
flake8 *.py src --ignore=E501,W503,E203
10186

102-
source_check: security_scan format_check error_check
87+
check: format_check style_error_check
10388

104-
dist: source_check dist/$(PACKAGE_EXTERNAL)
89+
dist: check dist/$(PACKAGE_EXTERNAL)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Requires recent python and golang.
2525

2626
```
2727
pip3 install -r requirements.txt
28-
make dist
28+
make
2929
```
3030

3131
On successful build, binaries will be created in "dist" folder

perf-collect.py

+2
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,11 @@ def is_safe_file(fname, substr):
519519
False,
520520
)
521521

522+
# reset nmi_watchdog to what it was before running perfspect
522523
if (int(nmi_watchdog) != 0) and supervisor:
523524
f_nmi = open("/proc/sys/kernel/nmi_watchdog", "w")
524525
f_nmi.write(nmi_watchdog)
526+
f_nmi.close()
525527

526528
if (args.muxinterval > 0) and supervisor:
527529
perf_helpers.set_perf_event_mux_interval(True, 1, mux_intervals)

perf-collect.spec

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
block_cipher = None
5+
6+
7+
a = Analysis(
8+
['perf-collect.py'],
9+
pathex=[],
10+
binaries=[('../build/pmu-checker', '.')],
11+
datas=[('./src/libtsc.so', '.'), ('./events/bdx.txt', '.'), ('./events/skx.txt', '.'), ('./events/clx.txt', '.'), ('./events/icx.txt', '.'), ('./events/spr.txt', '.'), ('./events/icx_aws.txt', '.'), ('./events/spr_aws.txt', '.'), ('./events/clx_aws.txt', '.'), ('./events/skx_aws.txt', '.')],
12+
hiddenimports=[],
13+
hookspath=[],
14+
hooksconfig={},
15+
runtime_hooks=[],
16+
excludes=['readline'],
17+
win_no_prefer_redirects=False,
18+
win_private_assemblies=False,
19+
cipher=block_cipher,
20+
noarchive=False,
21+
)
22+
23+
# exclude libtinfo shared library from distributed binaries due to warning observed on Ubuntu 16.04:
24+
# "/bin/bash: ./_MEIuU3XMv/libtinfo.so.5: no version information available (required by /bin/bash)"
25+
a.binaries = [bin for bin in a.binaries if not bin[0].startswith('libtinfo')]
26+
27+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
28+
29+
exe = EXE(
30+
pyz,
31+
a.scripts,
32+
a.binaries,
33+
a.zipfiles,
34+
a.datas,
35+
[],
36+
name='perf-collect',
37+
debug=False,
38+
bootloader_ignore_signals=False,
39+
strip=False,
40+
upx=True,
41+
upx_exclude=[],
42+
runtime_tmpdir='.',
43+
console=True,
44+
disable_windowed_traceback=False,
45+
argv_emulation=False,
46+
target_arch=None,
47+
codesign_identity=None,
48+
entitlements_file=None,
49+
)

perf-postprocess.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,6 @@ def write_perf_tmp_output(use_epoch):
763763
epoch = int(words[-1])
764764
except ValueError:
765765
exit("Conversion error parsing timestamp")
766-
except:
767-
exit("Unkown error parsing timestamp")
768766
break
769767
# TO:DO remove "not_counted" and "not_supported" events from dat_file
770768

@@ -1433,7 +1431,7 @@ def is_safe_path(base_dir, path, follow_symlinks=True):
14331431
if (args.outfile).endswith("xlsx"):
14341432
try:
14351433
import xlsxwriter
1436-
except:
1434+
except ImportError:
14371435
raise SystemExit(
14381436
"xlsxwriter not found to generate excel output. Install xlsxwriter or use .csv"
14391437
)

pmu-checker/msr/msr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (dpt retMSR) read(msr int64) (uint64, error) {
5252
rc, err := syscall.Pread(dpt.fd, buf, msr)
5353
if err != nil {
5454
log.Fatal(err)
55-
panic(err)
55+
return 0, err
5656
}
5757

5858
if rc != 8 {

src/perf_helpers.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import collections
1515
import psutil
1616
import subprocess # nosec
17+
import logging
1718
from time import strptime
18-
from ctypes import * # flake8: noqa
19+
from ctypes import cdll, CDLL
1920
from datetime import datetime
2021
from dateutil import tz
2122

@@ -166,7 +167,7 @@ def get_version():
166167
try:
167168
fo = open("/proc/version", "r")
168169
except EnvironmentError as e:
169-
warnings.warn(str(e), UserWarning)
170+
logging.warn(str(e), UserWarning)
170171
else:
171172
version = fo.read()
172173
version = version.split("#")[0]
@@ -180,7 +181,7 @@ def get_cpuinfo():
180181
try:
181182
fo = open("/proc/cpuinfo", "r")
182183
except EnvironmentError as e:
183-
warnings.warn(str(e), UserWarning)
184+
logging.warn(str(e), UserWarning)
184185
else:
185186
for line in fo:
186187
try:

0 commit comments

Comments
 (0)