Skip to content

Commit 9115d83

Browse files
gllghrDon Brady
authored andcommitted
Switch to Python 3 [Backport of #9 to 6.0.3.0]
1 parent fff5d57 commit 9115d83

File tree

13 files changed

+108
-82
lines changed

13 files changed

+108
-82
lines changed

.github/scripts/flake8_stbtrace.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#/bin/bash
2+
#
3+
# Copyright (c) 2020 by Delphix. All rights reserved.
4+
#
5+
# SPDX-License-Identifier: GPL-2.0-or-later
6+
#
7+
8+
#
9+
# This provides flake8 linting for the various stbtrace templates. It uses
10+
# stbtrace with the '--bcc' flag to produce and print Python code, and then
11+
# runs flake8 against that.
12+
#
13+
14+
set -o pipefail
15+
16+
function die() {
17+
echo "$(basename "$0"): $*" >&2
18+
exit 1
19+
}
20+
21+
prgms=$(find ./bpf/stbtrace -name '*.st' | xargs basename --suffix='.st') ||
22+
die "Failed to generate list of stbtrace programs"
23+
24+
for prgm in $prgms; do
25+
echo "Checking stbtrace program $prgm..."
26+
./cmd/stbtrace.py $prgm --bcc >/tmp/$prgm.py ||
27+
die "Failed to generate python source"
28+
flake8 /tmp/$prgm.py --show-source || die "flake8 errors found in" \
29+
"'bpf/stbtrace/$prgm.st'. Line numbers in error messages" \
30+
"correspond to the output of './cmd/stbtrace.py $prgm --bcc'"
31+
done
32+
33+
exit 0

.github/workflows/flake8.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ on: [pull_request, push]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8-
98
steps:
109
- uses: actions/checkout@v1
1110
- name: Set up Python
1211
uses: actions/setup-python@v1
1312
with:
14-
python-version: 2.7
13+
python-version: 3.6
1514
- name: flake8
1615
run: |
1716
python -m pip install --upgrade pip
1817
pip install flake8
1918
flake8 . --show-source --statistics
19+
./.github/scripts/flake8_stbtrace.sh

bpf/standalone/zil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2019 Delphix. All rights reserved.
44
#
@@ -304,7 +304,7 @@
304304
exit(0)
305305

306306
# Collect data until keyborad interrupt with output for each second
307-
while (1):
307+
while True:
308308
try:
309309
sleep(60)
310310
except KeyboardInterrupt:

bpf/stbtrace/io.st

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,7 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
2422

2523

2624
# BPF disk io program
@@ -125,7 +123,7 @@ int disk_io_done(struct pt_regs *ctx, struct request *reqp)
125123
io_base_data.delete((u64 *) &reqp);
126124
return 0;
127125
}
128-
"""
126+
""" # noqa: W293
129127
b = BPF(text=bpf_text)
130128

131129
if BPF.get_kprobe_functions(b'blk_start_request'):

bpf/stbtrace/iscsi.st

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,7 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
2422

2523
# BPF txg program
2624
bpf_text = """
@@ -63,7 +61,8 @@ BPF_HASH($hist.name$, iscsi_hist_key_t, u64);
6361
}$
6462

6563
// Probe functions to initialize thread local data
66-
int iscsi_target_start(struct pt_regs *ctx, struct iscsi_conn *conn, struct iscsi_cmd *cmd, struct iscsi_scsi_req *hdr)
64+
int iscsi_target_start(struct pt_regs *ctx, struct iscsi_conn *conn,
65+
struct iscsi_cmd *cmd, struct iscsi_scsi_req *hdr)
6766
{
6867
iscsi_data_t data = {};
6968
data.ts = bpf_ktime_get_ns();
@@ -122,7 +121,7 @@ int iscsi_target_end(struct pt_regs *ctx, struct iscsi_cmd *cmd)
122121
return 0;
123122
}
124123

125-
"""
124+
""" # noqa: W293
126125
b = BPF(text=bpf_text)
127126

128127
b.attach_kprobe(event="iscsit_process_scsi_cmd", fn_name="iscsi_target_start")

bpf/stbtrace/nfs.st

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,7 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
2422

2523
# BPF txg program
2624
bpf_text = """
@@ -167,8 +165,8 @@ int nfsd4_read_start(struct pt_regs *ctx, struct svc_rqst *rqstp, void *cstate,
167165
return 0;
168166
}
169167

170-
int nfsd4_write_start(struct pt_regs *ctx, struct svc_rqst *rqstp, void *cstate,
171-
nfsd4_write *nfs_write)
168+
int nfsd4_write_start(struct pt_regs *ctx, struct svc_rqst *rqstp,
169+
void *cstate, nfsd4_write *nfs_write)
172170
{
173171
u32 pid = bpf_get_current_pid_tgid();
174172
nfs_data_t data = {};
@@ -302,7 +300,7 @@ int nfsd4_write_done(struct pt_regs *ctx)
302300

303301
return 0;
304302
}
305-
"""
303+
""" # noqa: W293
306304
b = BPF(text=bpf_text)
307305

308306
b.attach_kprobe(event="nfsd_read", fn_name="nfsd3_read_start")

bpf/stbtrace/vfs.st

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,7 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
2422

2523
# BPF txg program
2624
bpf_text = """
@@ -68,7 +66,7 @@ BPF_HASH($hist.name$, vfs_hist_key_t, u64);
6866

6967
// Probe functions to initialize thread local data
7068
int vfs_start(struct pt_regs *ctx, void *file, void *user_buf,
71-
u64 count, void *ppos)
69+
u64 count, void *ppos)
7270
{
7371
u32 pid = bpf_get_current_pid_tgid();
7472
vfs_data_t data = {};
@@ -187,7 +185,7 @@ int vfs_write_done(struct pt_regs *ctx)
187185
u64 ts = bpf_ktime_get_ns();
188186
return vfs_aggregate_data(ts, WRITE_STR);
189187
}
190-
"""
188+
""" # noqa: W293
191189
b = BPF(text=bpf_text)
192190

193191
b.attach_kprobe(event="vfs_read", fn_name="vfs_start")

bpf/stbtrace/zio.st

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,7 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
2422

2523
# BPF txg program
2624
bpf_text = """
@@ -125,7 +123,7 @@ int vdev_queue_done(struct pt_regs *ctx, zio_t *zio)
125123
}
126124

127125

128-
"""
126+
""" # noqa: W293
129127

130128
KVER = os.popen('uname -r').read().rstrip()
131129
b = BPF(text=bpf_text, cflags=["-include",
@@ -134,7 +132,8 @@ b = BPF(text=bpf_text, cflags=["-include",
134132
"-I/usr/src/zfs-" + KVER + "/include/spl/",
135133
"-I/usr/src/zfs-" + KVER + "/include/linux"])
136134

137-
b.attach_kretprobe(event="vdev_queue_io_to_issue", fn_name="vdev_queue_issue_return")
135+
b.attach_kretprobe(event="vdev_queue_io_to_issue",
136+
fn_name="vdev_queue_issue_return")
138137
b.attach_kprobe(event="vdev_queue_io_done", fn_name="vdev_queue_done")
139138

140139
helper = BCCHelper(b, BCCHelper.ANALYTICS_PRINT_MODE)

bpf/stbtrace/zpl.st

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
from bcc import BPF
88
from time import sleep
9-
from time import time
10-
import datetime
11-
import ctypes as ct
129
import os
1310
import sys
11+
1412
#
1513
# Find BCCHelper. If we are being run from the repo, we should be able to find
1614
# it in the repo's lib/ directory. If we can't find that, look for BCCHelper
@@ -20,7 +18,8 @@ base_dir = os.path.dirname(__file__) + "/../"
2018
if not os.path.exists(base_dir + "lib/bcchelper.py"):
2119
base_dir = "/usr/share/performance-diagnostics/"
2220
sys.path.append(base_dir + 'lib/')
23-
from bcchelper import BCCHelper
21+
from bcchelper import BCCHelper # noqa: E402
22+
2423

2524
# BPF txg program
2625
bpf_text = """
@@ -170,7 +169,8 @@ int zfs_write_done(struct pt_regs *ctx)
170169
return zpl_aggregate_data(ts, WRITE_STR);
171170
}
172171

173-
"""
172+
""" # noqa: W293
173+
174174
KVER = os.popen('uname -r').read().rstrip()
175175
b = BPF(text=bpf_text,
176176
cflags=["-I/usr/src/zfs-" + KVER + "/include/spl"])

cmd/estat.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2019 Delphix. All rights reserved.
44
#
@@ -19,8 +19,6 @@
1919
# the performance data collector.
2020
#
2121

22-
from __future__ import print_function
23-
2422
from bcc import BPF
2523
import getopt
2624
from glob import glob
@@ -422,7 +420,7 @@ class Args:
422420
line + "'")
423421
probe_type = probe_spec[0]
424422
if probe_type == "kprobe":
425-
if BPF.get_kprobe_functions(probe_spec[1]):
423+
if BPF.get_kprobe_functions(probe_spec[1].encode('utf-8')):
426424
b.attach_kprobe(event=probe_spec[1], fn_name=probe_spec[2])
427425
probes.add("p_" + probe_spec[1] + "_bcc_" + str(os.getpid()))
428426
else:
@@ -480,20 +478,20 @@ class Args:
480478
# output
481479
if monitor:
482480
# TODO can we do this without shelling out to 'date'?
483-
ds__start = long(os.popen("date +%s%N").readlines()[0])
481+
ds__start = int(os.popen("date +%s%N").readlines()[0])
484482
while (1):
485483
try:
486484
sleep(duration)
487485
except KeyboardInterrupt:
488486
break
489487
try:
490-
ds__end = long(os.popen("date +%s%N").readlines()[0])
488+
ds__end = int(os.popen("date +%s%N").readlines()[0])
491489
ds__delta = ds__end - ds__start
492490
if not accum:
493491
ds__start = ds__end
494492
if args.summary and args.normalize:
495-
helper1.normalize("ops", ds__delta / 1000000000)
496-
helper3.normalize("opst", ds__delta / 1000000000)
493+
helper1.normalize("ops", ds__delta // 1000000000)
494+
helper3.normalize("opst", ds__delta // 1000000000)
497495
clear_data = not accum
498496
if args.latsize_hist:
499497
helper2.printall(clear_data)
@@ -502,26 +500,26 @@ class Args:
502500
if args.summary and args.total:
503501
helper3.printall(clear_data)
504502
print("%-16s\n" % strftime("%D - %H:%M:%S %Z"))
505-
except e:
503+
except Exception as e:
506504
die(e)
507505
else:
508-
ds__start = long(os.popen("date +%s%N").readlines()[0])
506+
ds__start = int(os.popen("date +%s%N").readlines()[0])
509507
try:
510508
sleep(duration)
511509
except KeyboardInterrupt:
512510
pass
513511
try:
514-
ds__delta = long(os.popen("date +%s%N").readlines()[0]) - ds__start
512+
ds__delta = int(os.popen("date +%s%N").readlines()[0]) - ds__start
515513
if args.summary and args.normalize:
516-
helper1.normalize("ops", ds__delta / 1000000000)
517-
helper3.normalize("opst", ds__delta / 1000000000)
514+
helper1.normalize("ops", ds__delta // 1000000000)
515+
helper3.normalize("opst", ds__delta // 1000000000)
518516
if args.latsize_hist:
519517
helper2.printall()
520518
if args.lat_hist or args.size_hist or args.summary:
521519
helper1.printall()
522520
if args.summary and args.total:
523521
helper3.printall()
524-
except e:
522+
except Exception as e:
525523
die(e)
526524

527525
#

0 commit comments

Comments
 (0)