diff --git a/branch/docs/examples-fix-attempt/_modules/pycallgraph/globbing_filter.html b/branch/docs/examples-fix-attempt/_modules/pycallgraph/globbing_filter.html new file mode 100644 index 0000000..245456c --- /dev/null +++ b/branch/docs/examples-fix-attempt/_modules/pycallgraph/globbing_filter.html @@ -0,0 +1,110 @@ + + + + + + + pycallgraph.globbing_filter — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + +
+
+
+
+ +

Source code for pycallgraph.globbing_filter

+from fnmatch import fnmatch
+
+
+
+[docs] +class GlobbingFilter(object): + '''Filter module names using a set of globs. + + Objects are matched against the exclude list first, then the include list. + Anything that passes through without matching either, is excluded. + ''' + + def __init__(self, include=None, exclude=None): + if include is None and exclude is None: + include = ['*'] + exclude = [] + elif include is None: + include = ['*'] + elif exclude is None: + exclude = [] + + self.include = include + self.exclude = exclude + + def __call__(self, full_name=None): + for pattern in self.exclude: + if fnmatch(full_name, pattern): + return False + + for pattern in self.include: + if fnmatch(full_name, pattern): + return True + + return False
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/_modules/pycallgraph/output/output.html b/branch/docs/examples-fix-attempt/_modules/pycallgraph/output/output.html new file mode 100644 index 0000000..b46b6bd --- /dev/null +++ b/branch/docs/examples-fix-attempt/_modules/pycallgraph/output/output.html @@ -0,0 +1,219 @@ + + + + + + + pycallgraph.output.output — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + +
+
+
+
+ +

Source code for pycallgraph.output.output

+import re
+import os
+from shutil import which
+
+from ..exceptions import PyCallGraphException
+from ..color import Color
+
+
+
+[docs] +class Output(object): + '''Base class for all outputters.''' + + def __init__(self, **kwargs): + self.node_color_func = self.node_color + self.edge_color_func = self.edge_color + self.node_label_func = self.node_label + self.edge_label_func = self.edge_label + + # Update the defaults with anything from kwargs + [setattr(self, k, v) for k, v in list(kwargs.items())] + +
+[docs] + def set_config(self, config): + ''' + This is a quick hack to move the config variables set in Config into + the output module config variables. + ''' + for k, v in list(config.__dict__.items()): + if hasattr(self, k) and \ + callable(getattr(self, k)): + continue + setattr(self, k, v)
+ + + def node_color(self, node): + value = float(node.time.fraction * 2 + node.calls.fraction) / 3 + return Color.hsv(value / 2 + .5, value, 0.9) + + def edge_color(self, edge): + value = float(edge.time.fraction * 2 + edge.calls.fraction) / 3 + return Color.hsv(value / 2 + .5, value, 0.7) + + def node_label(self, node): + parts = [ + '{0.name}', + 'calls: {0.calls.value:n}', + 'time: {0.time.value:f}s', + ] + + if self.processor.config.memory: + parts += [ + 'memory in: {0.memory_in.value_human_bibyte}', + 'memory out: {0.memory_out.value_human_bibyte}', + ] + + return r'\n'.join(parts).format(node) + + def edge_label(self, edge): + return '{0}'.format(edge.calls.value) + +
+[docs] + def sanity_check(self): + '''Basic checks for certain libraries or external applications. Raise + or warn if there is a problem. + ''' + pass
+ + + @classmethod + def add_arguments(cls, subparsers): + pass + + def reset(self): + pass + + def set_processor(self, processor): + self.processor = processor + +
+[docs] + def start(self): + '''Initialise variables after initial configuration.''' + pass
+ + +
+[docs] + def update(self): + '''Called periodically during a trace, but only when should_update is + set to True. + ''' + raise NotImplementedError('update')
+ + +
+[docs] + def should_update(self): + '''Return True if the update method should be called periodically.''' + return False
+ + +
+[docs] + def done(self): + '''Called when the trace is complete and ready to be saved.''' + raise NotImplementedError('done')
+ + + def ensure_binary(self, cmd): + if which(cmd): + return + + raise PyCallGraphException( + 'The command "{0}" is required to be in your path.'.format(cmd)) + + def normalize_path(self, path): + regex_user_expand = re.compile(r'\A~') + if regex_user_expand.match(path): + path = os.path.expanduser(path) + else: + path = os.path.expandvars(path) # expand, just in case + return path + + def prepare_output_file(self): + if self.fp is None: + self.output_file = self.normalize_path(self.output_file) + self.fp = open(self.output_file, 'wb') + + def verbose(self, text): + self.processor.config.log_verbose(text) + + def debug(self, text): + self.processor.config.log_debug(text) + + @classmethod + def add_output_file(cls, subparser, defaults, help): + subparser.add_argument( + '-o', '--output-file', type=str, default=defaults.output_file, + help=help, + )
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/_modules/pycallgraph/pycallgraph.html b/branch/docs/examples-fix-attempt/_modules/pycallgraph/pycallgraph.html new file mode 100644 index 0000000..79ef3dc --- /dev/null +++ b/branch/docs/examples-fix-attempt/_modules/pycallgraph/pycallgraph.html @@ -0,0 +1,188 @@ + + + + + + + pycallgraph.pycallgraph — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + +
+
+
+
+ +

Source code for pycallgraph.pycallgraph

+import locale
+
+from .output import Output
+from .config import Config
+from .tracer import AsyncronousTracer, SyncronousTracer
+from .exceptions import PyCallGraphException
+
+
+
+[docs] +class PyCallGraph(object): + def __init__(self, output=None, config=None): + '''output can be a single Output instance or an iterable with many + of them. Example usage: + + PyCallGraph(output=GraphvizOutput(), config=Config()) + ''' + locale.setlocale(locale.LC_ALL, '') + + if output is None: + self.output = [] + elif isinstance(output, Output): + self.output = [output] + else: + self.output = output + + self.config = config or Config() + + configured_ouput = self.config.get_output() + if configured_ouput: + self.output.append(configured_ouput) + + self.reset() + + def __enter__(self): + self.start() + + def __exit__(self, type, value, traceback): + self.done() + + def get_tracer_class(self): + if self.config.threaded: + return AsyncronousTracer + else: + return SyncronousTracer + +
+[docs] + def reset(self): + '''Resets all collected statistics. This is run automatically by + start(reset=True) and when the class is initialized. + ''' + self.tracer = self.get_tracer_class()(self.output, config=self.config) + + for output in self.output: + self.prepare_output(output)
+ + +
+[docs] + def start(self, reset=True): + '''Begins a trace. Setting reset to True will reset all previously + recorded trace data. + ''' + if not self.output: + raise PyCallGraphException( + 'No outputs declared. Please see the ' + 'examples in the online documentation.' + ) + + if reset: + self.reset() + + for output in self.output: + output.start() + + self.tracer.start()
+ + +
+[docs] + def stop(self): + '''Stops the currently running trace, if any.''' + self.tracer.stop()
+ + +
+[docs] + def done(self): + '''Stops the trace and tells the outputters to generate their + output. + ''' + self.stop() + + self.generate()
+ + + def generate(self): + # If in threaded mode, wait for the processor thread to complete + self.tracer.done() + + for output in self.output: + output.done() + + def add_output(self, output): + self.output.append(output) + self.prepare_output(output) + + def prepare_output(self, output): + output.sanity_check() + output.set_processor(self.tracer.processor) + output.reset()
+ +
+ +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/_sources/examples/basic.rst.txt b/branch/docs/examples-fix-attempt/_sources/examples/basic.rst.txt new file mode 100644 index 0000000..0388fe6 --- /dev/null +++ b/branch/docs/examples-fix-attempt/_sources/examples/basic.rst.txt @@ -0,0 +1,21 @@ +.. _basic_example: + +Basic +===== + +A simple Python example with two classes. + +Source Code +----------- + +.. literalinclude:: basic.py + +Generated Image +--------------- + +Below is the generated image from the code above. If you're having issues with the image below, try the :download:`direct link to image `. + +.. container:: example-image + + .. image:: basic.png + :target: ../_downloads/basic.png \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/_sources/examples/index.rst.txt b/branch/docs/examples-fix-attempt/_sources/examples/index.rst.txt new file mode 100644 index 0000000..4e64c66 --- /dev/null +++ b/branch/docs/examples-fix-attempt/_sources/examples/index.rst.txt @@ -0,0 +1,10 @@ + +Examples +======== + +.. toctree:: + :maxdepth: 3 + + basic + regexp_grouped + regexp_ungrouped diff --git a/branch/docs/examples-fix-attempt/_sources/examples/regexp_grouped.rst.txt b/branch/docs/examples-fix-attempt/_sources/examples/regexp_grouped.rst.txt new file mode 100644 index 0000000..7327d91 --- /dev/null +++ b/branch/docs/examples-fix-attempt/_sources/examples/regexp_grouped.rst.txt @@ -0,0 +1,21 @@ +.. _regexp_grouped_example: + +Regular Expressions (Grouped) +============================= + +See how a regular expression is constructed and matched. The example also shows the comparison between creating a regular expression object before matching, versus matching a "new" regular expression every iteration. See also :ref:`regexp_ungrouped_example`. + +Source Code +----------- + +.. literalinclude:: regexp.py + +Generated Image +--------------- + +Below is the generated image from the code above. If you're having issues with the image below, try the :download:`direct link to image `. + +.. container:: example-image + + .. image:: regexp_grouped.png + :target: ../_downloads/regexp_grouped.png \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/_sources/examples/regexp_ungrouped.rst.txt b/branch/docs/examples-fix-attempt/_sources/examples/regexp_ungrouped.rst.txt new file mode 100644 index 0000000..c582099 --- /dev/null +++ b/branch/docs/examples-fix-attempt/_sources/examples/regexp_ungrouped.rst.txt @@ -0,0 +1,21 @@ +.. _regexp_ungrouped_example: + +Regular Expressions (Ungrouped) +=============================== + +Similar to the :ref:`regexp_grouped_example` example, but without grouping turned on. + +Source Code +----------- + +.. literalinclude:: regexp.py + +Generated Image +--------------- + +Below is the generated image from the code above. If you're having issues with the image below, try the :download:`direct link to image `. + +.. container:: example-image + + .. image:: regexp_ungrouped.png + :target: ../_downloads/regexp_ungrouped.png \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/examples/basic.html b/branch/docs/examples-fix-attempt/examples/basic.html new file mode 100644 index 0000000..999567a --- /dev/null +++ b/branch/docs/examples-fix-attempt/examples/basic.html @@ -0,0 +1,176 @@ + + + + + + + + Basic — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + + + +
+
+
+
+ +
+

Basic

+

A simple Python example with two classes.

+
+

Source Code

+
#!/usr/bin/env python
+'''
+This example demonstrates a simple use of pycallgraph.
+'''
+from pycallgraph import PyCallGraph
+from pycallgraph.output import GraphvizOutput
+
+
+class Banana:
+
+    def eat(self):
+        pass
+
+
+class Person:
+
+    def __init__(self):
+        self.no_bananas()
+
+    def no_bananas(self):
+        self.bananas = []
+
+    def add_banana(self, banana):
+        self.bananas.append(banana)
+
+    def eat_bananas(self):
+        [banana.eat() for banana in self.bananas]
+        self.no_bananas()
+
+
+def main():
+    graphviz = GraphvizOutput()
+    graphviz.output_file = 'basic.png'
+
+    with PyCallGraph(output=graphviz):
+        person = Person()
+        for a in range(10):
+            person.add_banana(Banana())
+        person.eat_bananas()
+
+
+if __name__ == '__main__':
+    main()
+
+
+
+
+

Generated Image

+

Below is the generated image from the code above. If you’re having issues with the image below, try the direct link to image.

+
+../_images/basic.png +
+
+
+ + +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/examples/index.html b/branch/docs/examples-fix-attempt/examples/index.html new file mode 100644 index 0000000..dee14b1 --- /dev/null +++ b/branch/docs/examples-fix-attempt/examples/index.html @@ -0,0 +1,126 @@ + + + + + + + + Examples — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + + + +
+ + +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/examples/regexp_grouped.html b/branch/docs/examples-fix-attempt/examples/regexp_grouped.html new file mode 100644 index 0000000..65ee93b --- /dev/null +++ b/branch/docs/examples-fix-attempt/examples/regexp_grouped.html @@ -0,0 +1,189 @@ + + + + + + + + Regular Expressions (Grouped) — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + + + +
+
+
+
+ +
+

Regular Expressions (Grouped)

+

See how a regular expression is constructed and matched. The example also shows the comparison between creating a regular expression object before matching, versus matching a “new” regular expression every iteration. See also Regular Expressions (Ungrouped).

+
+

Source Code

+
#!/usr/bin/env python
+'''
+Runs a regular expression over the first few hundred words in a dictionary to
+find if any words start and end with the same letter, and having two of the
+same letters in a row.
+'''
+import argparse
+import re
+
+from pycallgraph import PyCallGraph
+from pycallgraph import Config
+from pycallgraph.output import GraphvizOutput
+
+
+class RegExp(object):
+
+    def main(self):
+        parser = argparse.ArgumentParser()
+        parser.add_argument('--grouped', action='store_true')
+        conf = parser.parse_args()
+
+        if conf.grouped:
+            self.run('regexp_grouped.png', Config(groups=True))
+        else:
+            self.run('regexp_ungrouped.png', Config(groups=False))
+
+    def run(self, output, config):
+        graphviz = GraphvizOutput()
+        graphviz.output_file = output
+        self.expression = r'^([^s]).*(.)\2.*\1$'
+
+        with PyCallGraph(config=config, output=graphviz):
+            self.precompiled()
+            self.onthefly()
+
+    def words(self):
+        a = 200
+        for word in open('/usr/share/dict/words'):
+            yield word.strip()
+            a -= 1
+            if not a:
+                return
+
+
+    def precompiled(self):
+        reo = re.compile(self.expression)
+        for word in self.words():
+            reo.match(word)
+
+    def onthefly(self):
+        for word in self.words():
+            re.match(self.expression, word)
+
+
+if __name__ == '__main__':
+    RegExp().main()
+
+
+
+
+

Generated Image

+

Below is the generated image from the code above. If you’re having issues with the image below, try the direct link to image.

+
+../_images/regexp_grouped.png +
+
+
+ + +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/branch/docs/examples-fix-attempt/examples/regexp_ungrouped.html b/branch/docs/examples-fix-attempt/examples/regexp_ungrouped.html new file mode 100644 index 0000000..221ac66 --- /dev/null +++ b/branch/docs/examples-fix-attempt/examples/regexp_ungrouped.html @@ -0,0 +1,189 @@ + + + + + + + + Regular Expressions (Ungrouped) — Python Call Graph 2.1.1 documentation + + + + + + + + + + + + + + + +
+
+
+
+ +
+

Regular Expressions (Ungrouped)

+

Similar to the Regular Expressions (Grouped) example, but without grouping turned on.

+
+

Source Code

+
#!/usr/bin/env python
+'''
+Runs a regular expression over the first few hundred words in a dictionary to
+find if any words start and end with the same letter, and having two of the
+same letters in a row.
+'''
+import argparse
+import re
+
+from pycallgraph import PyCallGraph
+from pycallgraph import Config
+from pycallgraph.output import GraphvizOutput
+
+
+class RegExp(object):
+
+    def main(self):
+        parser = argparse.ArgumentParser()
+        parser.add_argument('--grouped', action='store_true')
+        conf = parser.parse_args()
+
+        if conf.grouped:
+            self.run('regexp_grouped.png', Config(groups=True))
+        else:
+            self.run('regexp_ungrouped.png', Config(groups=False))
+
+    def run(self, output, config):
+        graphviz = GraphvizOutput()
+        graphviz.output_file = output
+        self.expression = r'^([^s]).*(.)\2.*\1$'
+
+        with PyCallGraph(config=config, output=graphviz):
+            self.precompiled()
+            self.onthefly()
+
+    def words(self):
+        a = 200
+        for word in open('/usr/share/dict/words'):
+            yield word.strip()
+            a -= 1
+            if not a:
+                return
+
+
+    def precompiled(self):
+        reo = re.compile(self.expression)
+        for word in self.words():
+            reo.match(word)
+
+    def onthefly(self):
+        for word in self.words():
+            re.match(self.expression, word)
+
+
+if __name__ == '__main__':
+    RegExp().main()
+
+
+
+
+

Generated Image

+

Below is the generated image from the code above. If you’re having issues with the image below, try the direct link to image.

+
+../_images/regexp_ungrouped.png +
+
+
+ + +
+
+
+
+ +
+
+ + + + \ No newline at end of file