]> khamidou — GitHub mirrors - lptrace.git/commitdiff
Better output
authorKarim Hamidou <khamidou@gmail.com>
Wed, 19 Oct 2016 14:18:54 +0000 (07:18 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Wed, 19 Oct 2016 14:19:23 +0000 (07:19 -0700)
README.md
lptrace.py

index fa0002722d446589b9ee832fd870448379a705e6..fcfd848b39f58379dbcda684da6f7a5a6a8eec2e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,42 +4,46 @@ lptrace is strace for Python programs. It lets you see in real-time
 what functions a Python program is running. It's particularly useful
 to debug weird issues on production.
 
-For example, let's take the following toy Python program:
+For example, let's debugging a non-trivial program, the Python SimpleHTTPServer.
+First, let's run the server:
 
-```python
-import time
-
-def f():
-    time.sleep(1)
-    g()
-
-def g():
-    time.sleep(1)
-    f()
-
-f()
+```
+vagrant@precise32:/vagrant$ python -m SimpleHTTPServer 8080 &
+[1] 1818
+vagrant@precise32:/vagrant$ Serving HTTP on 0.0.0.0 port 8080 ...
 ```
 
-Let's run it and connect lptrace to it:
+Now let's connect lptrace to it:
 
 ```
-vagrant@precise32:/vagrant$ python /tmp/t.py &
-[1] 1765
-vagrant@precise32:/vagrant$ sudo python ttrace.py -p 1765
-f (/tmp/t.py:3)
-g (/tmp/t.py:7)
-f (/tmp/t.py:3)
-g (/tmp/t.py:7)
-f (/tmp/t.py:3)
-g (/tmp/t.py:7)
-f (/tmp/t.py:3)
-g (/tmp/t.py:7)
-f (/tmp/t.py:3)
+vagrant@precise32:/vagrant$ sudo python ttrace.py -p 1818
+...
+fileno (/usr/lib/python2.7/SocketServer.py:438)
+meth (/usr/lib/python2.7/socket.py:223)
+
+fileno (/usr/lib/python2.7/SocketServer.py:438)
+meth (/usr/lib/python2.7/socket.py:223)
+
+_handle_request_noblock (/usr/lib/python2.7/SocketServer.py:271)
+get_request (/usr/lib/python2.7/SocketServer.py:446)
+accept (/usr/lib/python2.7/socket.py:201)
+__init__ (/usr/lib/python2.7/socket.py:185)
+verify_request (/usr/lib/python2.7/SocketServer.py:296)
+process_request (/usr/lib/python2.7/SocketServer.py:304)
+finish_request (/usr/lib/python2.7/SocketServer.py:321)
+__init__ (/usr/lib/python2.7/SocketServer.py:632)
+setup (/usr/lib/python2.7/SocketServer.py:681)
+makefile (/usr/lib/python2.7/socket.py:212)
+__init__ (/usr/lib/python2.7/socket.py:246)
+makefile (/usr/lib/python2.7/socket.py:212)
+__init__ (/usr/lib/python2.7/socket.py:246)
+handle (/usr/lib/python2.7/BaseHTTPServer.py:336)
+handle_one_request (/usr/lib/python2.7/BaseHTTPServer.py:301)
 ^CReceived Ctrl-C, quitting
 vagrant@precise32:/vagrant$
 ```
 
-That's it! After pressing Ctrl-C, the trace is removed and the program
+You can see that the server is handling the request normally! After pressing Ctrl-C, the trace is removed and the program
 execution resumes normally.
 
 # Running lptrace
index 207499cf7cc318524326eef46ea2ee4065900b5a..38d8e30f4c22889a9e6d7ac42c2775ca1df451ea 100644 (file)
@@ -1,3 +1,6 @@
+# lptrace - Copyright (c) 2016 Karim Hamidou.
+# Portions inspired by Pyrasite.
+
 import os
 import sys
 import signal
@@ -12,7 +15,7 @@ trace_fn = """def __lptrace_trace_calls__(frame, event, arg):
 
     code = frame.f_code
     with open(__LPTRACE_FIFO_NAME__, 'w') as fifo:
-        fifo.write("{} ({}:{})".format(code.co_name,
+        fifo.write("{} ({}:{})\\n".format(code.co_name,
                                        code.co_filename, frame.f_lineno))
 
 __LPTRACE_FIFO_NAME__ = "%s"