diff --git a/MANIFEST.in b/MANIFEST.in index 1958fbc..ff0eee1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,6 +2,7 @@ include HISTORY.rst include LICENSE include README.rst include djdt_flamegraph/flamegraph.pl +include djdt_flamegraph/static/djdt_flamegraph/djdt_flamegraph.js recursive-include tests * recursive-exclude * __pycache__ diff --git a/djdt_flamegraph/djdt_flamegraph.py b/djdt_flamegraph/djdt_flamegraph.py old mode 100755 new mode 100644 index 243a678..1a4a46a --- a/djdt_flamegraph/djdt_flamegraph.py +++ b/djdt_flamegraph/djdt_flamegraph.py @@ -28,17 +28,12 @@ init(); - - """ +from django.templatetags.static import static class FlamegraphPanel(Panel): title = 'Flamegraph' @@ -51,20 +46,24 @@ def enabled(self): @property def content(self): - ctx = { + return Template(template).render(Context({ 'flamegraph': flamegraph.stats_to_svg(self.sampler.get_stats()) - } - return Template(template).render(Context(ctx)) + })) + + @property + def scripts(self): + scripts = super().scripts + scripts.append(static("djdt_flamegraph/djdt_flamegraph.js")) + return scripts def enable_instrumentation(self): self.sampler = Sampler() def process_request(self, request): self.sampler.start() - return super().process_request(request) - - def process_response(self, request, response): + response = super().process_request(request) self.sampler.stop() + return response class Sampler(object): diff --git a/djdt_flamegraph/static/djdt_flamegraph/djdt_flamegraph.js b/djdt_flamegraph/static/djdt_flamegraph/djdt_flamegraph.js new file mode 100644 index 0000000..dc37429 --- /dev/null +++ b/djdt_flamegraph/static/djdt_flamegraph/djdt_flamegraph.js @@ -0,0 +1,5 @@ + (function(){ + const i = document.querySelector('#djdt-flamegraph-iframe'); + const tpl = document.querySelector('#djdt-flamegraph-tpl'); + i.contentWindow.document.write(tpl.innerHTML); + }())