Skip to content

Commit ee8a14e

Browse files
committed
Merge branch 'master' into new-jit-log
2 parents 05c044d + 4dfb295 commit ee8a14e

44 files changed

Lines changed: 497 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ docs/_build/
5959
target/
6060

6161
*.dat
62+
*.swp
63+
*.swo
6264

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ install:
2020
- pip install .
2121

2222
script:
23-
- py.test tests/ -vrs
2423
- py.test vmprof/ -vrs
24+
- py.test jitlog/ -vrs
2525

2626
notifications:
2727
irc:

‎MANIFEST.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
recursive-include src *.h *.c
22
include LICENSE
3+
recursive-exclude vmprof/test *
4+
recursive-exclude vmprof/log/test *

‎README.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,43 @@ oberstet@thinkpad-t430s:~/scm/vmprof-python$ vmprofshow vmprof_cpuburn.dat
6767
0.5% ........ _next_rand 0.5% tests/cpuburn.py:14
6868
0.0% ........ JIT code 0.0% 0x7fa7dba583b0
6969
```
70+
71+
72+
## Line profiling
73+
74+
vmprof supports line profiling mode, which enables collecting and showing the statistics for separate lines
75+
inside functions.
76+
77+
To enable collection of lines statistics add `--lines` argument to vmprof:
78+
79+
```console
80+
python -m vmprof --lines -o <output-file> <your program> <your program args>
81+
```
82+
83+
Or pass `lines=True` argument to `vmprof.enable` function, when calling vmprof from code.
84+
85+
To see line statistics for all functions add the `--lines` argument to `vmprofshow`:
86+
```console
87+
vmprofshow --lines <output-file>
88+
```
89+
90+
To see line statistics for a specific function use the `--filter` argument with the function name:
91+
```console
92+
vmprofshow --lines --filter <function-name> <output-file>
93+
```
94+
95+
You will see the result:
96+
```console
97+
macbook-pro-4:vmprof-python traff$ vmprofshow --lines --filter _next_rand vmprof_cpuburn.dat
98+
Total hits: 1170 s
99+
File: tests/cpuburn.py
100+
Function: _next_rand at line 14
101+
102+
Line # Hits % Hits Line Contents
103+
=======================================
104+
14 38 3.2 def _next_rand(self):
105+
15 # http://rosettacode.org/wiki/Linear_congruential_generator
106+
16 835 71.4 self._rand = (1103515245 * self._rand + 12345) & 0x7fffffff
107+
17 297 25.4 return self._rand
108+
```
109+

‎docs/index.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ After ``-m vmprof`` you can specify some options:
122122
* ``-n`` - enable all C frames, only useful if you have a debug build of
123123
PyPy or CPython.
124124

125+
* ``--lines`` - enable line profiling mode. This mode adds some overhead to profiling, but in addition to function calls
126+
it marks the execution of the specific lines inside functions.
127+
125128
* ``-o file`` - save logs for later
126129

127130
* ``--help`` - display help

‎jitlog/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from jitlog.upload import upload

‎jitlog/__main__.py‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import runpy
2+
import sys, os
3+
import tempfile
4+
5+
try:
6+
import _jitlog
7+
except ImportError:
8+
_jitlog = None
9+
10+
def upload_stats(stats, forest, args):
11+
import vmprof.upload
12+
name = args.program
13+
argv = " ".join(args.args)
14+
host = args.web_url
15+
auth = args.web_auth
16+
#
17+
sys.stderr.write("Compiling and uploading to %s...\n" % (args.web_url,))
18+
vmprof.upload.upload(stats, name, argv, host, auth, forest)
19+
20+
def build_argparser():
21+
parser = argparse.ArgumentParser(
22+
description='Jitlog',
23+
prog="jitlog"
24+
)
25+
parser.add_argument(
26+
'program',
27+
help='program'
28+
)
29+
parser.add_argument(
30+
'args',
31+
nargs=argparse.REMAINDER,
32+
help='program arguments'
33+
)
34+
35+
parser.add_argument(
36+
'--web-auth',
37+
help='Authtoken for your acount on the server, works only when --web is used'
38+
)
39+
40+
parser.add_argument(
41+
'--web-url',
42+
metavar='url',
43+
default='http://vmprof.com',
44+
help='Provide URL instead of the default vmprof.com)'
45+
)
46+
output_mode_args = parser.add_mutually_exclusive_group()
47+
output_mode_args.add_argument(
48+
'--web',
49+
action='store_true',
50+
help='Upload profiling stats to a remote server (defaults to vmprof.com)'
51+
)
52+
output_mode_args.add_argument(
53+
'--output', '-o',
54+
metavar='file.prof',
55+
type=argparse.FileType('w+b'),
56+
help='Save profiling data to file'
57+
)
58+
59+
return parser
60+
61+
def main():
62+
parser = build_argparser()
63+
args = parser.parse_args(sys.argv[1:])
64+
65+
if args.web:
66+
output_mode = OUTPUT_WEB
67+
elif args.output:
68+
output_mode = OUTPUT_FILE
69+
70+
if output_mode == OUTPUT_FILE:
71+
prof_file = args.output
72+
prof_name = prof_file.name
73+
else:
74+
prof_file = tempfile.NamedTemporaryFile(delete=False)
75+
prof_name = prof_file.name
76+
77+
78+
vmprof.enable(prof_file.fileno(), args.period, args.mem, args.lines)
79+
fd = os.open(prof_name, os.O_WRONLY | os.O_TRUNC | os.O_CREAT)
80+
_jitlog.enable(fd)
81+
# not need to close fd, will be closed in _jitlog.disable()
82+
83+
try:
84+
sys.argv = [args.program] + args.args
85+
sys.path.insert(0, os.path.dirname(args.program))
86+
runpy.run_path(args.program, run_name='__main__')
87+
except BaseException as e:
88+
if not isinstance(e, (KeyboardInterrupt, SystemExit)):
89+
raise
90+
_jitlog.disable()
91+
if output_mode == OUTPUT_WEB:
92+
upload(prof_name, output_mode, args)
93+
if output_mode != OUTPUT_FILE:
94+
os.unlink(prof_name)
95+
96+
main()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import print_function
2-
from vmprof.log import constants as const
3-
from vmprof.log import merge_point
4-
from vmprof.log.objects import FlatOp, MergePoint
2+
from jitlog import constants as const
3+
from jitlog import merge_point
4+
from jitlog.objects import FlatOp, MergePoint
55
from vmprof.binary import (read_word, read_string,
66
read_le_u16, read_le_addr, read_le_u64,
77
read_le_s64, read_bytes, read_byte,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from vmprof.log import constants as const
1+
from jitlog import constants as const
22
from vmprof.binary import read_string, read_le_u64
33

44
class MergePointDecoder(object):

0 commit comments

Comments
 (0)