Skip to content

Commit 8544581

Browse files
committed
fixup! Add sampling profiler
1 parent 4a5dd5f commit 8544581

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

Lib/profile/sample.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def sample(self, duration_sec=10):
3434
try:
3535
stack_frames = self.unwinder.get_stack_trace()
3636
self.aggregate_stack_frames(result, stack_frames)
37-
except RuntimeError, UnicodeDecodeError:
37+
except RuntimeError, UnicodeDecodeError, OSError:
3838
errors += 1
3939

4040
num_samples += 1
@@ -114,7 +114,13 @@ def aggregate_stack_frames(self, result, stack_frames):
114114

115115

116116
def sample(
117-
pid, *, sort=-1, sample_interval_usec=100, duration_sec=10, filename=None
117+
pid,
118+
*,
119+
sort=-1,
120+
sample_interval_usec=100,
121+
duration_sec=10,
122+
filename=None,
123+
all_threads=False,
118124
):
119125
profile = SampleProfile(pid, sample_interval_usec, all_threads=False)
120126
profile.sample(duration_sec)
@@ -134,14 +140,20 @@ def main():
134140
"--interval",
135141
type=int,
136142
default=10,
137-
help="Sampling interval in microseconds (default: 10 usec).",
143+
help="Sampling interval in microseconds (default: 10 usec)",
138144
)
139145
parser.add_argument(
140146
"-d",
141147
"--duration",
142148
type=int,
143149
default=10,
144-
help="Sampling duration in seconds (default: 10 seconds).",
150+
help="Sampling duration in seconds (default: 10 seconds)",
151+
)
152+
parser.add_argument(
153+
"-a",
154+
"--all-threads",
155+
action="store_true",
156+
help="Sample all threads in the process",
145157
)
146158
parser.add_argument("-o", "--outfile", help="Save stats to <outfile>")
147159
args = parser.parse_args()
@@ -151,6 +163,7 @@ def main():
151163
sample_interval_usec=args.interval,
152164
duration_sec=args.duration,
153165
filename=args.outfile,
166+
all_threads=args.all_threads,
154167
)
155168

156169

0 commit comments

Comments
 (0)