GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing pythonhosted.org — Tutorial - Tracking Class Instances in SCons — Pympler 0.5 documentation Tutorial - Tracking Class Instances in SCons¶This tutorial demonstrates the class tracking facility to profile and optimize a non-trivial program. SCons is a next-generation build system with a quite elaborate architecture and thus an interesting candidate for profiling attempts. Before we begin, it should be identified what shall be tracked, i.e. what
classes we want to connect to and whose instances are to be sized and profiled.
In this tutorial, the effect of a patch is analyzed that tries to size-optimize the very
heart of SCons - the Installing hooks into SCons¶The first step is to find the proper spots for connecting to the classes that shall be tracked, taking snapshots, and printing the gathered profile data. SCons has a simple memory profiling tool that we will override. The SCons MemStats class provides all we need: from pympler.classtracker import ClassTracker class MemStats(Stats): def __init__(self): Stats.__init__(self) classes = [SCons.Node.Node, SCons.Node.FS.Base, SCons.Node.FS.File, SCons.Node.FS.Dir, SCons.Executor.Executor] self.tracker = ClassTracker() for c in classes: self.tracker.track_class(c) def do_append(self, label): self.tracker.create_snapshot(label) def do_print(self): stats = self.tracker.stats stats.print_summary() stats.dump_stats('pympler.stats') When SCons starts, Because of the large number of instances, only a summary is printed to the
console via Test run¶Time for a test. In the following examples, SCons builds a non-trivial program
with a fair number of nodes. Running SCons via scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... scons: `.' is up to date. scons: done building targets. ---- SUMMARY ------------------------------------------------------------------ before reading SConscript files: active 4.17 MB average pct SCons.Executor.Executor 7 7.53 KB 1.08 KB 0% SCons.Node.FS.Base 1 9.30 KB 9.30 KB 0% SCons.Node.FS.Dir 6 17.77 KB 2.96 KB 0% SCons.Node.FS.File 1 2.91 KB 2.91 KB 0% SCons.Node.Node 0 0 B 0 B 0% after reading SConscript files: active 13.06 MB average pct [...] before building targets: active 13.41 MB average pct [...] after building targets: active 34.77 MB average pct SCons.Executor.Executor 1311 3.57 MB 2.79 KB 10% SCons.Node.FS.Base 1102 4.84 MB 4.50 KB 13% SCons.Node.FS.Dir 108 5.67 MB 53.72 KB 16% SCons.Node.FS.File 2302 10.45 MB 4.65 KB 30% SCons.Node.Node 1 84.93 KB 84.93 KB 0% ------------------------------------------------------------------------------- Making sense of the data¶The console output may give a brief overview how much memory is allocated by
instances of the individual tracked classes. A more appealing and well arranged
representation of the data can be generated with the from pympler.classtracker_stats import HtmlStats stats = HtmlStats() stats.load_stats('pympler.stats') stats.create_html('pympler.html') If At first sight it might seem suspicious that the tracked classes appear to be the sole contributors to the total memory footprint of the application. Because the tracked objects are sized recursively, referenced objects which are not tracked themselves are added to the referrers account. Thus, a root object’s size will include the size of every leaf unless the leaf is also tracked by the ClassTracker. Optimization attempt¶After applying the patch by Jean Brouwers, SCons is rerun under the supervision
of the ClassTracker. The differences in the last snapshot show that the
changes indeed reduce the memory footprint of $ scons --debug=memory scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... scons: `.' is up to date. scons: done building targets. ---- SUMMARY ------------------------------------------------------------------ [...] after building targets: active 32.41 MB average pct SCons.Executor.Executor 1311 3.50 MB 2.73 KB 10% SCons.Node.FS.Base 1102 4.29 MB 3.98 KB 13% SCons.Node.FS.Dir 108 5.52 MB 52.30 KB 17% SCons.Node.FS.File 2302 8.82 MB 3.92 KB 27% SCons.Node.Node 1 84.32 KB 84.32 KB 0% ------------------------------------------------------------------------------- The total measured memory footprint dropped from 34.8MB to 32.4MB, Summary¶This tutorial illustrated how applications can be profiled with the ClassTracker facility. It has been shown how the memory impact of changes can be quantified. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |