Author: Maciej Fijalkowski <[email protected]>
Branch: dtrace-support
Changeset: r75919:1c6e04d35be2
Date: 2015-02-16 16:09 +0200
http://bitbucket.org/pypy/pypy/changeset/1c6e04d35be2/
Log: start writing dtrace support for basic events
diff --git a/rpython/config/translationoption.py
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -189,6 +189,9 @@
BoolOption("lldebug0",
"If true, makes an lldebug0 build", default=False,
cmdline="--lldebug0"),
+ BoolOption("dtrace",
+ "If true, enable emitting dtrace debug probes", default=False,
+ cmdline='--enable-dtrace'),
OptionDescription("backendopt", "Backend Optimization Options", [
# control inlining
diff --git a/rpython/translator/c/database.py b/rpython/translator/c/database.py
--- a/rpython/translator/c/database.py
+++ b/rpython/translator/c/database.py
@@ -16,6 +16,7 @@
from rpython.translator.c.extfunc import do_the_getting
from rpython.translator.c import gc
from rpython.tool.identity_dict import identity_dict
+from rpython.flowspace.model import Constant
class NoCorrespondingNode(Exception):
@@ -47,6 +48,7 @@
self.containerstats = {}
self.externalfuncs = {}
self.helper2ptr = {}
+ self.debug_nodes = set()
# late_initializations is for when the value you want to
# assign to a constant object is something C doesn't think is
@@ -232,6 +234,13 @@
else:
raise Exception("don't know about %r" % (obj,))
+ def seen_debug_start(self, op):
+ arg = op.args[0]
+ if not isinstance(arg, Constant):
+ return
+ name = ''.join(arg.value.chars)
+ self.debug_nodes.add(name)
+
def complete(self, show_progress=True):
assert not self.completed
if self.translator and self.translator.rtyper:
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -792,6 +792,7 @@
return x
def OP_DEBUG_START(self, op):
+ self.db.seen_debug_start(op)
return self._op_debug('PYPY_DEBUG_START', op.args[0])
def OP_DEBUG_STOP(self, op):
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -246,8 +246,22 @@
self.extrafiles = self.eventually_copy(extra)
self.gen_makefile(targetdir, exe_name=exe_name,
headers_to_precompile=headers_to_precompile)
+ if self.config.translation.dtrace:
+ self._generate_dtrace_probe_file(db.debug_nodes)
return cfile
+ def _generate_dtrace_probe_file(self, debug_nodes):
+ name = self.targetdir.join('pypy.p')
+ f = name.open('w')
+ f.write('provider pypy_probes {\n')
+ for debug_node in debug_nodes:
+ debug_node = debug_node.replace('-', '_')
+ f.write(' probe %s__start(void);' % debug_node)
+ f.write(' probe %s__done(void);' % debug_node)
+ f.write('};')
+ f.close()
+ # XXX run dtrace
+
def eventually_copy(self, cfiles):
extrafiles = []
for fn in cfiles:
diff --git a/rpython/translator/c/test/test_dtrace.py
b/rpython/translator/c/test/test_dtrace.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/c/test/test_dtrace.py
@@ -0,0 +1,19 @@
+
+from rpython.translator.c.test.test_standalone import StandaloneTests
+from rpython.rlib.debug import debug_start, debug_stop
+from rpython.config.translationoption import get_combined_translation_config
+
+class TestDTrace(StandaloneTests):
+ config = get_combined_translation_config(translating=True)
+ config.translation.dtrace = True
+
+ def test_dtrace_probes(self):
+ def f(argv):
+ debug_start("x")
+ for i in range(10000000):
+ pass
+ debug_stop("x")
+ return 0
+
+ _, cbuilder = self.compile(f)
+ cbuilder.cmdexec('')
diff --git a/rpython/translator/c/test/test_standalone.py
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1390,7 +1390,6 @@
and result.count('a') == 1
and result.count('d') == 6)
-
class TestShared(StandaloneTests):
def test_entrypoint(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit