From 62f9d7c021d94caa4b6a6b02a1970adcd6e75981 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 8 Jun 2001 05:04:19 +0000 Subject: In the section on extending the profiler, add some additional discussion about setting up the dispatch table, and update the OldProfile and HotProfile classes to the current implementations, showing the adjusted construction for the dispatch table. --- Doc/lib/libprofile.tex | 55 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/Doc/lib/libprofile.tex b/Doc/lib/libprofile.tex index a8861c3..794f7d0 100644 --- a/Doc/lib/libprofile.tex +++ b/Doc/lib/libprofile.tex @@ -655,12 +655,40 @@ Be warned that you \emph{should} calibrate the profiler class for the timer function that you choose. For most machines, a timer that returns a lone integer value will provide the best results in terms of low overhead during profiling. (\function{os.times()} is -\emph{pretty} bad, 'cause it returns a tuple of floating point values, +\emph{pretty} bad, as it returns a tuple of floating point values, so all arithmetic is floating point in the profiler!). If you want to substitute a better timer in the cleanest fashion, you should derive a class, and simply put in the replacement dispatch method that better handles your timer call, along with the appropriate calibration -constant :-). +constant. + +Note that subclasses which override any of the +\method{trace_dispatch_call()}, \method{trace_dispatch_exception()}, +or \method{trace_dispatch_return()} methods also need to specify a +dispatch table as well. The table, named \member{dispatch}, should +have the three keys \code{'call'}, \code{'exception'}, and +\code{'return'}, each giving the function of the corresponding +handler. Note that best performance is achieved by using the +\emph{function} objects for the handlers and not bound methods. This +is preferred since calling a simple function object executes less code +in the runtime than calling either bound or unbound methods. For +example, if the derived profiler overrides only one method, the +\member{dispatch} table can be built like this: + +\begin{verbatim} +from profile import Profile + +class MyProfiler(Profile): + def trace_dispath_call(self, frame, t): + # do something interesting here + ... + + dispatch = { + 'call': trace_dispatch_call, + 'exception': Profile.__dict__['trace_dispatch_exception'], + 'return': Profile.__dict__['trace_dispatch_return'], + } +\end{verbatim} \subsection{OldProfile Class \label{profile-old}} @@ -684,7 +712,7 @@ class OldProfile(Profile): def trace_dispatch_call(self, frame, t): fn = `frame.f_code` - + self.cur = (t, 0, 0, fn, frame, self.cur) if self.timings.has_key(fn): tt, ct, callers = self.timings[fn] @@ -710,21 +738,24 @@ class OldProfile(Profile): return 1 + dispatch = { + "call": trace_dispatch_call, + "exception": trace_dispatch_exception, + "return": trace_dispatch_return, + } def snapshot_stats(self): self.stats = {} for func in self.timings.keys(): tt, ct, callers = self.timings[func] - nor_func = self.func_normalize(func) - nor_callers = {} + callers = callers.copy() nc = 0 for func_caller in callers.keys(): - nor_callers[self.func_normalize(func_caller)] = \ - callers[func_caller] nc = nc + callers[func_caller] - self.stats[nor_func] = nc, nc, tt, ct, nor_callers + self.stats[func] = nc, nc, tt, ct, callers \end{verbatim} + \subsection{HotProfile Class \label{profile-HotProfile}} This profiler is the fastest derived profile example. It does not @@ -763,11 +794,15 @@ class HotProfile(Profile): return 1 + dispatch = { + "call": trace_dispatch_call, + "exception": trace_dispatch_exception, + "return": trace_dispatch_return, + } def snapshot_stats(self): self.stats = {} for func in self.timings.keys(): nc, tt = self.timings[func] - nor_func = self.func_normalize(func) - self.stats[nor_func] = nc, nc, tt, 0, {} + self.stats[func] = nc, nc, tt, 0, {} \end{verbatim} -- cgit v0.12 lect name='dt' onchange='this.form.submit();'>
authorQt Continuous Integration System <qt-info@nokia.com>2010-03-18 02:58:03 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-03-18 02:58:03 (GMT)
commitcda81eebdd74de711953a69bdb4e9088380b2d95 (patch)
tree0f03759390d03e4f6ae9cedf4fd99bc1e95b18e0 /src/testlib
parent19c41b7de6596453f16d52f05953b153cd40e36e (diff)
parentffcd64e38529c6d93c632282a75a31731feeb0d2 (diff)
downloadQt-cda81eebdd74de711953a69bdb4e9088380b2d95.zip
Qt-cda81eebdd74de711953a69bdb4e9088380b2d95.tar.gz
Qt-cda81eebdd74de711953a69bdb4e9088380b2d95.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (42 commits) Make destructor virtual. Optimized QLocale to access system locale on demand. Remove unwanted code in f8d5f2594a9b268b9eeecf95b24b23fc940c71ce Compile fix on keypad-navigation systems Force qt-zlib to be used for host system when cross compiling. qmake: fix to create proper install target in Makefile at first run compile fix for Windows Fixed focus handling when Qt is embedded into Cocoa app. Do not beep on Mac when pressing some keys. Do not deliver the same key event multiple times in Cocoa. Implement Idle-priority threads for Linux. Improved qt_x11_wait_for_window_manager Doc: document QElapsedTimer Added missing "const" for mac. qdoc3: Fixed some ifdef typos and removed some whitespace. Manual test for QTBUG-8933. Cocoa: minisplitter has only 1px wide grab area "Strictly" Fullscreen Application in Mac OS Bugfix the Symbian implementation Add QDateTime::currentDateTimeUtc and QDateTime::currentMsecsSinceEpoch ...
Diffstat (limited to 'src/testlib')