Skip to content

Commit fe66065

Browse files
author
Thijs Metsch
committed
refactored
1 parent 2b48038 commit fe66065

17 files changed

Lines changed: 354 additions & 14 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
MANIFEST
12
.make.state.Debug
23
.dep.inc
34
Makefile

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>python-dtrace</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?>
3+
4+
<pydev_project>
5+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
6+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
7+
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
8+
<path>/python-dtrace</path>
9+
</pydev_pathproperty>
10+
</pydev_project>

LICENSE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Copyright (C) 2011 by Thijs Metsch
2+
3+
LICENSE TBD

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include setup.py
2+
include LICENSE
3+
recursive-include examples/ *.py

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
Python as a DTrace consumer
33
===========================
44

5-
This is a first shot into looking at getting something up and running like https://github.com/bcantrill/node-libdtrace for Python.
5+
This is a first shot into looking at getting something up and running like https://github.com/bcantrill/node-libdtrace for Python.
66

7-
Note: This is far from ready - documentation on writing own DTrace consumers is very rare :-) Therefore I started of with main.c which is a simple starting point to interface DTrace.
7+
Note: This is far from ready - documentation on writing own DTrace consumers is very rare :-)
88

9-
What does work: run a 'Hello World' - works for the C code (main.c) and python code (dtrace.py). Both programs should give a rough overview of how to access DTrace and write an own DTrace consumer.
10-
11-
Current ideas on how to progress include:
12-
13-
* Call libdtrace using ctypes directly (Might be hard because of the callbacks during aggregation)
14-
* Writing a simple C interface which is more 'pythonic' which than can be used in Python (maybe the way to go - but requires some work)
15-
* maybe even SWIG :-/
9+
The codes in the examples folder should give an overview of how to use Python as a DTrace consumer.

dtrace.py renamed to attic/dtrace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class dtrace_bufdata(Structure):
4545
As defined in dtrace.h:310
4646
'''
4747
_fields_ = [("dtbda_handle", c_void_p),
48-
("dtbda_buffered", c_char_p), # works
48+
("dtbda_buffered", c_char_p), # works
4949
("dtbda_probe", c_void_p),
5050
("dtbda_recdesc", c_void_p),
5151
("dtbda_aggdata", c_void_p),
@@ -70,7 +70,7 @@ class dtrace_probedata(Structure):
7070
_fields_ = [("dtpda_handle", c_void_p),
7171
("dtpda_edesc", c_void_p),
7272
("dtpda_pdesc", dtrace_probedesc),
73-
("dtpda_cpu", c_int), # works
73+
("dtpda_cpu", c_int), # works
7474
("dtpda_data", c_void_p),
7575
("dtpda_flow", c_void_p),
7676
("dtpda_prefix", c_void_p),
@@ -126,12 +126,12 @@ def chewrec_func(data, rec, arg):
126126
return 0
127127

128128

129-
def out(bufdata, arg):
129+
def buffered_stdout_writer(bufdata, arg):
130130
'''
131131
In case dtrace_work is given None as filename - this one is called.
132132
'''
133133
tmp = c_char_p(bufdata.contents.dtbda_buffered).value.strip()
134-
print ' +--> In out: ', tmp
134+
print ' +--> In buffered_stdout_writer: ', tmp
135135
return 0
136136

137137

@@ -167,7 +167,7 @@ def run_dtrace():
167167
raise Exception(c_char_p(txt).value)
168168

169169
# callbacks
170-
buf_func = BUFFERED_FUNC(out)
170+
buf_func = BUFFERED_FUNC(buffered_stdout_writer)
171171
LIBRARY.dtrace_handle_buffered(handle, buf_func, None)
172172

173173
# compile
File renamed without changes.

dtrace/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'''
2+
Package containing the DTrace consumer.
3+
4+
Created on Oct 10, 2011
5+
6+
@author: tmetsch
7+
'''

dtrace/__init__.pyc

255 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)