Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
2322d919
Commit
2322d919
authored
Jan 24, 2021
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Jan 24, 2021
Browse files
Remove callstack sampler util which is not used in any code.
PiperOrigin-RevId: 353526459
parent
a2201bb8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
62 deletions
+0
-62
official/utils/misc/callstack_sampler.py
official/utils/misc/callstack_sampler.py
+0
-62
No files found.
official/utils/misc/callstack_sampler.py
deleted
100644 → 0
View file @
a2201bb8
"""A simple Python callstack sampler."""
import
contextlib
import
datetime
import
signal
import
traceback
class
CallstackSampler
(
object
):
"""A simple signal-based Python callstack sampler.
"""
def
__init__
(
self
,
interval
=
None
):
self
.
stacks
=
[]
self
.
interval
=
0.001
if
interval
is
None
else
interval
def
_sample
(
self
,
signum
,
frame
):
"""Samples the current stack."""
del
signum
stack
=
traceback
.
extract_stack
(
frame
)
formatted_stack
=
[]
formatted_stack
.
append
(
datetime
.
datetime
.
utcnow
())
for
filename
,
lineno
,
function_name
,
text
in
stack
:
formatted_frame
=
'{}:{}({})({})'
.
format
(
filename
,
lineno
,
function_name
,
text
)
formatted_stack
.
append
(
formatted_frame
)
self
.
stacks
.
append
(
formatted_stack
)
signal
.
setitimer
(
signal
.
ITIMER_VIRTUAL
,
self
.
interval
,
0
)
@
contextlib
.
contextmanager
def
profile
(
self
):
signal
.
signal
(
signal
.
SIGVTALRM
,
self
.
_sample
)
signal
.
setitimer
(
signal
.
ITIMER_VIRTUAL
,
self
.
interval
,
0
)
try
:
yield
finally
:
signal
.
setitimer
(
signal
.
ITIMER_VIRTUAL
,
0
)
def
save
(
self
,
fname
):
with
open
(
fname
,
'w'
)
as
f
:
for
s
in
self
.
stacks
:
for
l
in
s
:
f
.
write
(
'%s
\n
'
%
l
)
f
.
write
(
'
\n
'
)
@
contextlib
.
contextmanager
def
callstack_sampling
(
filename
,
interval
=
None
):
"""Periodically samples the Python callstack.
Args:
filename: the filename
interval: the sampling interval, in seconds. Defaults to 0.001.
Yields:
nothing
"""
sampler
=
CallstackSampler
(
interval
=
interval
)
with
sampler
.
profile
():
yield
sampler
.
save
(
filename
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment