Skip to content

Commit a08a073

Browse files
committed
flake8 polishing
1 parent bb09990 commit a08a073

17 files changed

+305
-241
lines changed

futex.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,45 @@
1616
import argparse
1717
import ctypes as ct
1818
import signal
19-
import sys
2019

2120

2221
bpf_text = """
2322
#include <linux/ptrace.h>
2423
2524
struct futex_hash_bucket {
26-
atomic_t waiters;
27-
spinlock_t lock;
28-
struct plist_head chain;
25+
atomic_t waiters;
26+
spinlock_t lock;
27+
struct plist_head chain;
2928
};
3029
3130
union futex_key {
32-
struct {
33-
unsigned long pgoff;
34-
struct inode *inode;
35-
int offset;
36-
} shared;
37-
struct {
38-
unsigned long address;
39-
struct mm_struct *mm;
40-
int offset;
41-
} private;
42-
struct {
43-
unsigned long word;
44-
void *ptr;
45-
int offset;
46-
} both;
31+
struct {
32+
unsigned long pgoff;
33+
struct inode *inode;
34+
int offset;
35+
} shared;
36+
struct {
37+
unsigned long address;
38+
struct mm_struct *mm;
39+
int offset;
40+
} private;
41+
struct {
42+
unsigned long word;
43+
void *ptr;
44+
int offset;
45+
} both;
4746
};
4847
4948
struct futex_q {
50-
struct plist_node list;
51-
52-
struct task_struct *task;
53-
spinlock_t *lock_ptr;
54-
union futex_key key;
55-
struct futex_pi_state *pi_state;
56-
struct rt_mutex_waiter *rt_waiter;
57-
union futex_key *requeue_pi_key;
58-
u32 bitset;
49+
struct plist_node list;
50+
51+
struct task_struct *task;
52+
spinlock_t *lock_ptr;
53+
union futex_key key;
54+
struct futex_pi_state *pi_state;
55+
struct rt_mutex_waiter *rt_waiter;
56+
union futex_key *requeue_pi_key;
57+
u32 bitset;
5958
};
6059
6160
struct futex_data {
@@ -77,8 +76,8 @@
7776
*
7877
*/
7978
#define container_of(ptr, type, member) ({ \
80-
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
81-
(type *)( (char *)__mptr - offsetof(type,member) );})
79+
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
80+
(type *)( (char *)__mptr - offsetof(type,member) );})
8281
8382
void probe_unqueue_futex(struct pt_regs *ctx)
8483
{
@@ -164,10 +163,12 @@ def parse_args():
164163
parser = argparse.ArgumentParser(
165164
description="Hash bucket size for futexes",
166165
formatter_class=argparse.RawDescriptionHelpFormatter)
167-
parser.add_argument("-l", "--size-limit", type=int, default=0,
168-
help="Display only hash buckets with size more than this limit")
169-
parser.add_argument("-d", "--debug", action='store_true', default=False,
170-
help="debug mode")
166+
parser.add_argument(
167+
"-l", "--size-limit", type=int, default=0,
168+
help="Display only hash buckets with size more than this limit")
169+
parser.add_argument(
170+
"-d", "--debug", action='store_true', default=False,
171+
help="Debug mode")
171172

172173
return parser.parse_args()
173174

io_throttle.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
from __future__ import print_function
99
from time import sleep
10-
from bcc import BPF, USDT
10+
from bcc import BPF
1111

1212
import argparse
1313
import ctypes as ct
1414
import signal
15-
import sys
1615

1716

1817
text = """
@@ -61,11 +60,14 @@
6160

6261

6362
def attach(event_name, bpf, args):
64-
bpf.attach_kretprobe(event="blk_throtl_bio", fn_name="probe_blk_throtl_bio")
63+
bpf.attach_kretprobe(
64+
event="blk_throtl_bio",
65+
fn_name="probe_blk_throtl_bio"
66+
)
6567

6668

6769
# signal handler
68-
def signal_ignore(signal, frame):
70+
def signal_ignore(sig, frame):
6971
print()
7072

7173

io_timeouts.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env python
22
#
3-
# io_timeouts Track schedule_io_timeout inflicted by throttling from writeback.
3+
# io_timeouts Track schedule_io_timeout inflicted by throttling from
4+
# writeback.
45
#
56
# usage: io_timeouts [-p PID] [-d]
67

78

89
from __future__ import print_function
910
from time import sleep
10-
from bcc import BPF, USDT
11+
from bcc import BPF
1112

1213
import argparse
1314
import ctypes as ct
1415
import signal
15-
import sys
1616

1717

1818
text = """
@@ -107,7 +107,7 @@ def attach(bpf, args):
107107

108108

109109
# signal handler
110-
def signal_ignore(signal, frame):
110+
def signal_ignore(sig, frame):
111111
print()
112112

113113

@@ -120,7 +120,8 @@ class Data(ct.Structure):
120120

121121
def print_event(cpu, data, size):
122122
event = ct.cast(data, ct.POINTER(Data)).contents
123-
print("Event: pid {} query {} timeout {}".format(event.pid, event.query, event.timeout))
123+
print("Event: pid {} query {} timeout {}".format(
124+
event.pid, event.query, event.timeout))
124125

125126

126127
def run(args):
@@ -149,6 +150,7 @@ def run(args):
149150
for (k, v) in bpf.get_table('io_timeout').items():
150151
print("[{}] {}: {}".format(k.pid, k.query, v.value))
151152

153+
152154
def parse_args():
153155
parser = argparse.ArgumentParser(
154156
description="",

latency.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
from __future__ import print_function
1010
from time import sleep
11-
from bcc import BPF
1211

1312
import argparse
14-
import ctypes as ct
1513
import signal
16-
import sys
14+
15+
from bcc import BPF
1716

1817
import utils
1918

@@ -69,7 +68,7 @@
6968

7069

7170
# signal handler
72-
def signal_ignore(signal, frame):
71+
def signal_ignore(sig, frame):
7372
print()
7473

7574

@@ -89,9 +88,9 @@ def attach(bpf, args):
8988
pid=pid)
9089

9190

92-
def pre_process(text, args):
93-
text = utils.replace_namespace(text, args)
94-
return text
91+
def pre_process(bpf_text, args):
92+
bpf_text = utils.replace_namespace(bpf_text, args)
93+
return bpf_text
9594

9695

9796
def output(bpf, fmt="plain"):
@@ -134,19 +133,24 @@ def run(args):
134133

135134
def parse_args():
136135
parser = argparse.ArgumentParser(
137-
description="Summarize cache references and misses by postgres backend",
136+
description="Summarize cache references & misses by postgres backend",
138137
formatter_class=argparse.RawDescriptionHelpFormatter)
139138
parser.add_argument("path", type=str, help="path to PostgreSQL binary")
140-
parser.add_argument("-p", "--pid", type=int, default=-1,
141-
help="trace this PID only")
142-
parser.add_argument("-c", "--container", type=str,
143-
help="trace this container only")
144-
parser.add_argument("-n", "--namespace", type=int,
145-
help="trace this namespace only")
146-
parser.add_argument("-i", "--interval", type=int, default=5,
147-
help="after how many seconds output the result")
148-
parser.add_argument("-d", "--debug", action='store_true', default=False,
149-
help="debug mode")
139+
parser.add_argument(
140+
"-p", "--pid", type=int, default=-1,
141+
help="trace this PID only")
142+
parser.add_argument(
143+
"-c", "--container", type=str,
144+
help="trace this container only")
145+
parser.add_argument(
146+
"-n", "--namespace", type=int,
147+
help="trace this namespace only")
148+
parser.add_argument(
149+
"-i", "--interval", type=int, default=5,
150+
help="after how many seconds output the result")
151+
parser.add_argument(
152+
"-d", "--debug", action='store_true', default=False,
153+
help="debug mode")
150154

151155
return parser.parse_args()
152156

llcache_per_query.py

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22
#
3-
# llcache_per_query Summarize cache references and cache misses by postgres backend.
4-
# Cache reference and cache miss are corresponding events defined in
5-
# uapi/linux/perf_event.h, it varies to different architecture.
6-
# On x86-64, they mean LLC references and LLC misses. Postgres
7-
# backend provides a query string. Based on llstat.py from bcc.
3+
# llcache_per_query Summarize cache references and cache misses by
4+
# postgres backend. Cache reference and cache miss are
5+
# events defined in uapi/linux/perf_event.h, it varies
6+
# to different architecture. On x86-64, they mean LLC
7+
# references and LLC misses. Postgres backend provides
8+
# a query string. Based on llstat.py from bcc.
89
# For Linux, uses BCC.
910
#
1011
# SEE ALSO: perf top -e cache-misses -e cache-references -a -ns pid,cpu,comm
@@ -14,13 +15,15 @@
1415

1516
from __future__ import print_function
1617
import argparse
17-
from bcc import BPF, PerfType, PerfHWConfig
18+
1819
import signal
1920
from time import sleep
2021

22+
from bcc import BPF, PerfType, PerfHWConfig
23+
2124

2225
# load BPF program
23-
bpf_text="""
26+
bpf_text = """
2427
#include <linux/ptrace.h>
2528
#include <uapi/linux/bpf_perf_event.h>
2629
@@ -104,7 +107,7 @@
104107

105108

106109
# signal handler
107-
def signal_ignore(signal, frame):
110+
def signal_ignore(sig, frame):
108111
print()
109112

110113

@@ -137,15 +140,10 @@ def run(args):
137140
attach(bpf, args)
138141
exiting = False
139142

140-
if args.debug:
141-
bpf["events"].open_perf_buffer(print_event)
142-
143143
print("Listening...")
144144
while True:
145145
try:
146146
sleep(1)
147-
if args.debug:
148-
bpf.perf_buffer_poll()
149147
except KeyboardInterrupt:
150148
exiting = True
151149
# as cleanup can take many seconds, trap Ctrl-C:
@@ -174,28 +172,31 @@ def run(args):
174172
tot_miss += miss
175173
# This happens on some PIDs due to missed counts caused by sampling
176174
hit = (v.value - miss) if (v.value >= miss) else 0
177-
print('{:<8d} {:<16s} {:<100s} {:<4d} {:>12d} {:>12d} {:>6.2f}%'.format(
178-
k.pid, k.name.decode(), k.query.decode(), k.cpu, v.value, miss,
179-
(float(hit) / float(v.value)) * 100.0))
175+
msg = '{:<8d} {:<16s} {:<100s} {:<4d} {:>12d} {:>12d} {:>6.2f}%'
176+
print(msg.format(k.pid, k.name.decode(), k.query.decode(), k.cpu,
177+
v.value, miss, (float(hit) / float(v.value)) * 100.0))
180178

181179
if tot_ref != 0:
182180
print()
183-
print('Total References: {} Total Misses: {} Hit Rate: {:.2f}%'.format(
184-
tot_ref, tot_miss, (float(tot_ref - tot_miss) / float(tot_ref)) * 100.0))
181+
msg = 'Total References: {} Total Misses: {} Hit Rate: {:.2f}%'
182+
print(msg.format(tot_ref, tot_miss,
183+
(float(tot_ref - tot_miss) / float(tot_ref)) * 100.0))
185184

186185

187186
def parse_args():
188187
parser = argparse.ArgumentParser(
189-
description="Summarize cache references and misses by postgres backend",
188+
description="Summarize cache references & misses by postgres backend",
190189
formatter_class=argparse.RawDescriptionHelpFormatter)
191190
parser.add_argument("path", type=str, help="path to PostgreSQL binary")
192191
parser.add_argument(
193192
"-c", "--sample_period", type=int, default=100,
194193
help="Sample one in this many number of cache reference / miss events")
195-
parser.add_argument("-p", "--pid", type=int, default=-1,
196-
help="trace this PID only")
197-
parser.add_argument("-d", "--debug", action='store_true', default=False,
198-
help="debug mode")
194+
parser.add_argument(
195+
"-p", "--pid", type=int, default=-1,
196+
help="trace this PID only")
197+
parser.add_argument(
198+
"-d", "--debug", action='store_true', default=False,
199+
help="debug mode")
199200

200201
return parser.parse_args()
201202

0 commit comments

Comments
 (0)