-
Notifications
You must be signed in to change notification settings - Fork 0
/
urk_trace.py
70 lines (46 loc) · 1.68 KB
/
urk_trace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import commands
import linecache
import time
last_mem = [0]
def traceit_memory(frame, event, arg):
if event == "line":
mem = int(" " + commands.getoutput(
"ps -eo cmd,rss | grep urk_trace.py | grep -v grep"
).split(" ")[-1])
if mem > last_mem[0]:
last_mem[0] = mem
mem = str(mem)
filename = frame.f_globals["__file__"]
if filename.endswith(".pyc") or filename.endswith(".pyo"):
filename = filename[:-1]
name = frame.f_globals["__name__"]
lineno = frame.f_lineno
line = linecache.getline(filename,lineno).rstrip()
data = "%s:%i: %s" % (name, lineno, line)
print "%s%s" % (data, mem.rjust(80 - len(data)))
return traceit_memory
lines = {}
def traceit(frame, event, arg):
if event == "line":
try:
filename = frame.f_globals["__file__"]
if filename.endswith(".pyc") or filename.endswith(".pyo"):
filename = filename[:-1]
name = frame.f_globals["__name__"]
lineno = frame.f_lineno
line = linecache.getline(filename,lineno).rstrip()
data = "%s:%i: %s" % (name, lineno, line)
print time.time(), data
#if data in lines:
# lines[data] += 1
#else:
# lines[data] = 1
except Exception, e:
print e
return traceit
def main():
import urk
urk.main()
sys.settrace(traceit)
main()