Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
ea6bb4da
Commit
ea6bb4da
authored
Dec 09, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates to the measure_loc tool
parent
9959d155
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
8 deletions
+49
-8
tools/measure_loc.py
tools/measure_loc.py
+35
-7
tools/measure_loc_ext/measure_loc.cpp
tools/measure_loc_ext/measure_loc.cpp
+14
-1
No files found.
tools/measure_loc.py
View file @
ea6bb4da
...
...
@@ -46,6 +46,7 @@ import os
import
runpy
import
signal
import
sys
import
time
import
traceback
class
SamplingProfiler
(
object
):
...
...
@@ -74,23 +75,44 @@ class SamplingProfiler(object):
signal
.
signal
(
sig
,
signal
.
SIG_DFL
)
return
self
.
dumper
()
# Try to prevent / notice if someone else sets a debugger.
# (Note: removing sys.settrace is not sufficient since one can set
# frame.f_trace)
sys_settrace
=
sys
.
settrace
sys
.
settrace
=
None
import
bdb
bdb
.
Bdb
.
set_trace
=
None
bdb
.
set_trace
=
None
import
pdb
pdb
.
set_trace
=
None
pdb
.
Pdb
.
set_trace
=
None
class
TracingProfiler
(
object
):
def
__init__
(
self
,
tracefunc
,
dumper
):
self
.
tracefunc
=
tracefunc
self
.
dumper
=
dumper
def
start
(
self
):
sys
.
settrace
(
self
.
tracefunc
)
sys
_
settrace
(
self
.
tracefunc
)
def
stop
(
self
):
assert
sys
.
gettrace
()
==
self
.
tracefunc
,
"Problem! Someone/something removed our tracer. It's now: %r"
%
sys
.
gettrace
()
sys
.
settrace
(
None
)
sys
_
settrace
(
None
)
return
self
.
dumper
()
times
=
{}
start_time
=
time
.
time
()
SKIP_WARMUP
=
0
def
signal_handler
(
sig
,
frame
):
loc
=
frame
.
f_code
.
co_filename
,
frame
.
f_lineno
times
[
loc
]
=
times
.
get
(
loc
,
0
)
+
1
if
time
.
time
()
>=
start_time
+
SKIP_WARMUP
:
print
"Starting sampling"
def
real_signal_handler
(
sig
,
frame
):
loc
=
frame
.
f_code
.
co_filename
,
frame
.
f_lineno
times
[
loc
]
=
times
.
get
(
loc
,
0
)
+
1
signal
.
signal
(
sig
,
real_signal_handler
)
real_signal_handler
(
sig
,
frame
)
return
def
trace_count
(
frame
,
event
,
arg
):
if
event
==
"line"
:
...
...
@@ -125,10 +147,13 @@ def run(sampler, kind):
except
KeyboardInterrupt
:
print
"Interrupted!"
traceback
.
print_exc
()
except
SystemExit
:
pass
except
:
print
"ERROR!"
traceback
.
print_exc
()
print
"Stopping timer and tallying statistics..."
times
=
sampler
.
stop
()
times
.
sort
(
key
=
lambda
(
l
,
t
):
t
,
reverse
=
True
)
...
...
@@ -177,7 +202,7 @@ def run(sampler, kind):
for
i
in
xrange
(
len
(
frac_counts
)):
print
"Picked %d lines out of %d to reach %.2f%%"
%
(
frac_counts
[
i
],
len
(
times
),
frac_fracs
[
i
]
/
total
*
100.0
)
python_sampler
=
SamplingProfiler
(
signal_handler
,
get_times
,
"real"
,
interval
=
0.000
0
1
)
python_sampler
=
SamplingProfiler
(
signal_handler
,
get_times
,
"real"
,
interval
=
0.0001
)
python_trace_counter
=
TracingProfiler
(
trace_count
,
get_times
)
try
:
import
measure_loc_ext
...
...
@@ -186,6 +211,9 @@ except ImportError:
print
"(extension module not available)"
if
__name__
==
"__main__"
:
run
(
python_sampler
,
"count"
)
if
sys
.
argv
[
1
]
==
'-t'
:
del
sys
.
argv
[
1
]
run
(
cext_trace_timer
,
"time"
)
else
:
run
(
python_sampler
,
"count"
)
# run(python_trace_counter, "count")
# run(cext_trace_timer, "time")
tools/measure_loc_ext/measure_loc.cpp
View file @
ea6bb4da
...
...
@@ -25,6 +25,7 @@ typedef std::pair<const char*, int> Position;
static
std
::
unordered_map
<
Position
,
double
>
times
;
static
double
*
next_time
=
NULL
;
static
double
prev_time
;
static
double
start_time
;
static
std
::
vector
<
Position
>
call_stack
;
...
...
@@ -38,12 +39,23 @@ static double time_to_log = 0.0;
// Run calibrate.py and divide the time accounted to calibrate.py:2 by the loop count (10M)
#define CALIBRATION_CONSTANT 0.0000001
// Some benchmarks remove their warmup time from their results, so make sure to match that:
#define WARMUP_TIME 0
static
PyObject
*
trace
(
PyObject
*
self
,
PyObject
*
args
)
{
double
curtime
=
floattime
();
#if WARMUP_TIME > 0
if
(
curtime
<
start_time
+
WARMUP_TIME
)
{
Py_INCREF
(
trace_func
);
return
trace_func
;
}
#endif
bool
log
=
false
;
if
(
next_time
)
{
double
f
=
(
floattime
()
-
prev_time
);
double
f
=
(
curtime
-
prev_time
);
f
-=
CALIBRATION_CONSTANT
;
*
next_time
+=
f
;
...
...
@@ -120,6 +132,7 @@ static PyMethodDef MeasureLocMethods[] = {
PyMODINIT_FUNC
initmeasure_loc_ext
(
void
)
{
start_time
=
floattime
();
PyObject
*
m
;
m
=
Py_InitModule
(
"measure_loc_ext"
,
MeasureLocMethods
);
...
...
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