annotate Modules/_hotshot.c @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents fd25030223b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 /*
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2 * This is the High Performance Python Profiler portion of HotShot.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
5 #include "Python.h"
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 32912
diff changeset
6 #include "code.h"
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
7 #include "eval.h"
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
8 #include "frameobject.h"
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
9 #include "structmember.h"
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 /*
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 * Which timer to use should be made more configurable, but that should not
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
13 * be difficult. This will do for now.
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 */
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
15 #ifdef MS_WINDOWS
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 #include <windows.h>
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
17
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
18 #ifdef HAVE_DIRECT_H
20400
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
19 #include <direct.h> /* for getcwd() */
38716
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
20 #endif
42808526511c Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 38489
diff changeset
21
20410
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
22 typedef __int64 hs_time;
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
23 #define GETTIMEOFDAY(P_HS_TIME) \
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
24 { LARGE_INTEGER _temp; \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
25 QueryPerformanceCounter(&_temp); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
26 *(P_HS_TIME) = _temp.QuadPart; }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
27
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
28
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 #else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 #ifndef HAVE_GETTIMEOFDAY
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 #error "This module requires gettimeofday() on non-Windows platforms!"
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 #endif
37713
91d16a87cbe8 Patch #1470300: Port _hotshot to QNX4.25 port.
Martin v. Löwis <martin@v.loewis.de>
parents: 37666
diff changeset
33 #if (defined(PYOS_OS2) && defined(PYCC_GCC)) || defined(__QNX__)
20641
c80dafce1b74 Got this to work in MacPython. The code is #ifdef macintosh style (to match the existing #ifdef MS_WINDOWS), but eventually ifdeffing on configure features is probably better.
Jack Jansen <jack.jansen@cwi.nl>
parents: 20447
diff changeset
34 #include <sys/time.h>
c80dafce1b74 Got this to work in MacPython. The code is #ifdef macintosh style (to match the existing #ifdef MS_WINDOWS), but eventually ifdeffing on configure features is probably better.
Jack Jansen <jack.jansen@cwi.nl>
parents: 20447
diff changeset
35 #else
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 #include <sys/resource.h>
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 #include <sys/times.h>
20641
c80dafce1b74 Got this to work in MacPython. The code is #ifdef macintosh style (to match the existing #ifdef MS_WINDOWS), but eventually ifdeffing on configure features is probably better.
Jack Jansen <jack.jansen@cwi.nl>
parents: 20447
diff changeset
38 #endif
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 typedef struct timeval hs_time;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 #if !defined(__cplusplus) && !defined(inline)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 #ifdef __GNUC__
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 #define inline __inline
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 #ifndef inline
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 #define inline
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52 #define BUFFERSIZE 10240
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21934
diff changeset
54 #if defined(PYOS_OS2) && defined(PYCC_GCC)
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21934
diff changeset
55 #define PATH_MAX 260
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21934
diff changeset
56 #endif
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21934
diff changeset
57
25327
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
58 #if defined(__sgi) && _COMPILER_VERSION>700 && !defined(PATH_MAX)
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
59 /* fix PATH_MAX not being defined with MIPSPro 7.x
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
60 if mode is ANSI C (default) */
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
61 #define PATH_MAX 1024
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
62 #endif
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25213
diff changeset
63
20400
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
64 #ifndef PATH_MAX
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
65 # ifdef MAX_PATH
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
66 # define PATH_MAX MAX_PATH
25497
b526e12b941b Patch #615069: Fix build problems on SCO Open Server 5. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 25327
diff changeset
67 # elif defined (_POSIX_PATH_MAX)
b526e12b941b Patch #615069: Fix build problems on SCO Open Server 5. Backported to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 25327
diff changeset
68 # define PATH_MAX _POSIX_PATH_MAX
20400
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
69 # else
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
70 # error "Need a defn. for PATH_MAX in _hotshot.c"
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
71 # endif
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
72 #endif
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
73
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74 typedef struct {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
75 PyObject_HEAD
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 PyObject *filemap;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77 PyObject *logfilename;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
78 Py_ssize_t index;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
79 unsigned char buffer[BUFFERSIZE];
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80 FILE *logfp;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
81 int lineevents;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
82 int linetimings;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
83 int frametimings;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
84 /* size_t filled; */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85 int active;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86 int next_fileno;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 hs_time prev_timeofday;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
88 } ProfilerObject;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 typedef struct {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
91 PyObject_HEAD
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
92 PyObject *info;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 FILE *logfp;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
94 int linetimings;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
95 int frametimings;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96 } LogReaderObject;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
97
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
98 static PyObject * ProfilerError = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
101 #ifndef MS_WINDOWS
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102 #ifdef GETTIMEOFDAY_NO_TZ
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
103 #define GETTIMEOFDAY(ptv) gettimeofday((ptv))
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104 #else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 #define GETTIMEOFDAY(ptv) gettimeofday((ptv), (struct timezone *)NULL)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 /* The log reader... */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
111
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
112 PyDoc_STRVAR(logreader_close__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
113 "close()\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
114 "Close the log file, preventing additional records from being read.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
117 logreader_close(LogReaderObject *self, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
119 if (self->logfp != NULL) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
120 fclose(self->logfp);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
121 self->logfp = NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
122 }
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
123 Py_INCREF(Py_None);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
124
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
125 return Py_None;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
126 }
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
127
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
128 PyDoc_STRVAR(logreader_fileno__doc__,
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
129 "fileno() -> file descriptor\n"
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
130 "Returns the file descriptor for the log file, if open.\n"
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
131 "Raises ValueError if the log file is closed.");
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
132
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
133 static PyObject *
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
134 logreader_fileno(LogReaderObject *self)
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
135 {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
136 if (self->logfp == NULL) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
137 PyErr_SetString(PyExc_ValueError,
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
138 "logreader's file object already closed");
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
139 return NULL;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
140 }
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
141 return PyInt_FromLong(fileno(self->logfp));
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
142 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
143
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
144
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
145 /* Log File Format
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
146 * ---------------
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
147 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
148 * The log file consists of a sequence of variable-length records.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
149 * Each record is identified with a record type identifier in two
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
150 * bits of the first byte. The two bits are the "least significant"
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
151 * bits of the byte.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
152 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
153 * Low bits: Opcode: Meaning:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
154 * 0x00 ENTER enter a frame
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
155 * 0x01 EXIT exit a frame
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24669
diff changeset
156 * 0x02 LINENO execution moved onto a different line
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
157 * 0x03 OTHER more bits are needed to deecode
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
158 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
159 * If the type is OTHER, the record is not packed so tightly, and the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
160 * remaining bits are used to disambiguate the record type. These
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
161 * records are not used as frequently so compaction is not an issue.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
162 * Each of the first three record types has a highly tailored
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
163 * structure that allows it to be packed tightly.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
164 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165 * The OTHER records have the following identifiers:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
166 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167 * First byte: Opcode: Meaning:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
168 * 0x13 ADD_INFO define a key/value pair
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169 * 0x23 DEFINE_FILE define an int->filename mapping
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
170 * 0x33 LINE_TIMES indicates if LINENO events have tdeltas
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
171 * 0x43 DEFINE_FUNC define a (fileno,lineno)->funcname mapping
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
172 * 0x53 FRAME_TIMES indicates if ENTER/EXIT events have tdeltas
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
173 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
174 * Packed Integers
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
175 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
176 * "Packed integers" are non-negative integer values encoded as a
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
177 * sequence of bytes. Each byte is encoded such that the most
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
178 * significant bit is set if the next byte is also part of the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
179 * integer. Each byte provides bits to the least-significant end of
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
180 * the result; the accumulated value must be shifted up to place the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
181 * new bits into the result.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
183 * "Modified packed integers" are packed integers where only a portion
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 * of the first byte is used. In the rest of the specification, these
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
185 * are referred to as "MPI(n,name)", where "n" is the number of bits
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186 * discarded from the least-signicant positions of the byte, and
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 * "name" is a name being given to those "discarded" bits, since they
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 * are a field themselves.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190 * ENTER records:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
191 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
192 * MPI(2,type) fileno -- type is 0x00
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
193 * PI lineno
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
194 * PI tdelta -- iff frame times are enabled
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
196 * EXIT records
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
197 *
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
198 * MPI(2,type) tdelta -- type is 0x01; tdelta will be 0
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
199 * if frame times are disabled
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
200 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
201 * LINENO records
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
202 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
203 * MPI(2,type) lineno -- type is 0x02
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
204 * PI tdelta -- iff LINENO includes it
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
205 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
206 * ADD_INFO records
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
207 *
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
208 * BYTE type -- always 0x13
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
209 * PI len1 -- length of first string
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210 * BYTE string1[len1] -- len1 bytes of string data
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
211 * PI len2 -- length of second string
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
212 * BYTE string2[len2] -- len2 bytes of string data
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
213 *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
214 * DEFINE_FILE records
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
215 *
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
216 * BYTE type -- always 0x23
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
217 * PI fileno
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218 * PI len -- length of filename
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
219 * BYTE filename[len] -- len bytes of string data
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
220 *
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
221 * DEFINE_FUNC records
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
222 *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
223 * BYTE type -- always 0x43
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
224 * PI fileno
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
225 * PI lineno
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
226 * PI len -- length of funcname
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
227 * BYTE funcname[len] -- len bytes of string data
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
228 *
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
229 * LINE_TIMES records
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
230 *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
231 * This record can be used only before the start of ENTER/EXIT/LINENO
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
232 * records. If have_tdelta is true, LINENO records will include the
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
233 * tdelta field, otherwise it will be omitted. If this record is not
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
234 * given, LINENO records will not contain the tdelta field.
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
235 *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
236 * BYTE type -- always 0x33
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237 * BYTE have_tdelta -- 0 if LINENO does *not* have
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
238 * timing information
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
239 * FRAME_TIMES records
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
240 *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
241 * This record can be used only before the start of ENTER/EXIT/LINENO
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
242 * records. If have_tdelta is true, ENTER and EXIT records will
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
243 * include the tdelta field, otherwise it will be omitted. If this
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
244 * record is not given, ENTER and EXIT records will contain the tdelta
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
245 * field.
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
246 *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
247 * BYTE type -- always 0x53
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
248 * BYTE have_tdelta -- 0 if ENTER/EXIT do *not* have
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
249 * timing information
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
250 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
251
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
252 #define WHAT_ENTER 0x00
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
253 #define WHAT_EXIT 0x01
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
254 #define WHAT_LINENO 0x02
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
255 #define WHAT_OTHER 0x03 /* only used in decoding */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
256 #define WHAT_ADD_INFO 0x13
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
257 #define WHAT_DEFINE_FILE 0x23
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
258 #define WHAT_LINE_TIMES 0x33
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
259 #define WHAT_DEFINE_FUNC 0x43
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
260 #define WHAT_FRAME_TIMES 0x53
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
261
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
262 #define ERR_NONE 0
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
263 #define ERR_EOF -1
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
264 #define ERR_EXCEPTION -2
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
265 #define ERR_BAD_RECTYPE -3
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
266
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
267 #define PISIZE (sizeof(int) + 1)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
268 #define MPISIZE (PISIZE + 1)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
269
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
270 /* Maximum size of "normal" events -- nothing that contains string data */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
271 #define MAXEVENTSIZE (MPISIZE + PISIZE*2)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
272
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
273
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
274 /* Unpack a packed integer; if "discard" is non-zero, unpack a modified
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
275 * packed integer with "discard" discarded bits.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
276 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
277 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
278 unpack_packed_int(LogReaderObject *self, int *pvalue, int discard)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
279 {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
280 int c;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
281 int accum = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
282 int bits = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
283 int cont;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
284
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
285 do {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
286 /* read byte */
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
287 if ((c = fgetc(self->logfp)) == EOF)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288 return ERR_EOF;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
289 accum |= ((c & 0x7F) >> discard) << bits;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
290 bits += (7 - discard);
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
291 cont = c & 0x80;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
292 discard = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
293 } while (cont);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
294
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
295 *pvalue = accum;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
296
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
297 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
298 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
299
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
300 /* Unpack a string, which is encoded as a packed integer giving the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
301 * length of the string, followed by the string data.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
302 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
303 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
304 unpack_string(LogReaderObject *self, PyObject **pvalue)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
305 {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
306 int i;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
307 int len;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
308 int err;
24339
a9b809c8b9db unpack_string(): avoid a compiler warning (about a real bug!) by
Guido van Rossum <guido@python.org>
parents: 24295
diff changeset
309 int ch;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
310 char *buf;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
311
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
312 if ((err = unpack_packed_int(self, &len, 0)))
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
313 return err;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
314
37666
5a9fcd676b3f C++ compiler changes. casts, rename variables with reserved names.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 36886
diff changeset
315 buf = (char *)malloc(len);
39445
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
316 if (!buf) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
317 PyErr_NoMemory();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
318 return ERR_EXCEPTION;
39445
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
319 }
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38716
diff changeset
320
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
321 for (i=0; i < len; i++) {
24339
a9b809c8b9db unpack_string(): avoid a compiler warning (about a real bug!) by
Guido van Rossum <guido@python.org>
parents: 24295
diff changeset
322 ch = fgetc(self->logfp);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
323 buf[i] = ch;
24339
a9b809c8b9db unpack_string(): avoid a compiler warning (about a real bug!) by
Guido van Rossum <guido@python.org>
parents: 24295
diff changeset
324 if (ch == EOF) {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
325 free(buf);
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
326 return ERR_EOF;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
327 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
328 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
329 *pvalue = PyString_FromStringAndSize(buf, len);
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
330 free(buf);
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
331 if (*pvalue == NULL) {
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
332 return ERR_EXCEPTION;
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
333 }
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
334 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
335 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
336
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
337
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
338 static int
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
339 unpack_add_info(LogReaderObject *self)
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
340 {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
341 PyObject *key;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
342 PyObject *value = NULL;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
343 int err;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
344
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
345 err = unpack_string(self, &key);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
346 if (!err) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
347 err = unpack_string(self, &value);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
348 if (err)
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
349 Py_DECREF(key);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
350 else {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
351 PyObject *list = PyDict_GetItem(self->info, key);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
352 if (list == NULL) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
353 list = PyList_New(0);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
354 if (list == NULL) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
355 err = ERR_EXCEPTION;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
356 goto finally;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
357 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
358 if (PyDict_SetItem(self->info, key, list)) {
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
359 Py_DECREF(list);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
360 err = ERR_EXCEPTION;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
361 goto finally;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
362 }
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
363 Py_DECREF(list);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
364 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
365 if (PyList_Append(list, value))
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
366 err = ERR_EXCEPTION;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
367 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
368 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
369 finally:
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
370 Py_XDECREF(key);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
371 Py_XDECREF(value);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
372 return err;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
373 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
374
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
375
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
376 static void
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
377 eof_error(LogReaderObject *self)
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
378 {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
379 fclose(self->logfp);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
380 self->logfp = NULL;
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
381 PyErr_SetString(PyExc_EOFError,
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
382 "end of file with incomplete profile record");
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
383 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
384
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
385 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
386 logreader_tp_iternext(LogReaderObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
387 {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
388 int c;
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
389 int what;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
390 int err = ERR_NONE;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
391 int lineno = -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
392 int fileno = -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
393 int tdelta = -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
394 PyObject *s1 = NULL, *s2 = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
395 PyObject *result = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
396 #if 0
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
397 unsigned char b0, b1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
398 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
399
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
400 if (self->logfp == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
401 PyErr_SetString(ProfilerError,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
402 "cannot iterate over closed LogReader object");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
403 return NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
404 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
405
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
406 restart:
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
407 /* decode the record type */
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
408 if ((c = fgetc(self->logfp)) == EOF) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
409 fclose(self->logfp);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
410 self->logfp = NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
411 return NULL;
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
412 }
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
413 what = c & WHAT_OTHER;
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
414 if (what == WHAT_OTHER)
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
415 what = c; /* need all the bits for type */
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
416 else
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
417 ungetc(c, self->logfp); /* type byte includes packed int */
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
418
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
419 switch (what) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
420 case WHAT_ENTER:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
421 err = unpack_packed_int(self, &fileno, 2);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
422 if (!err) {
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
423 err = unpack_packed_int(self, &lineno, 0);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
424 if (self->frametimings && !err)
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
425 err = unpack_packed_int(self, &tdelta, 0);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
426 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
427 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
428 case WHAT_EXIT:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
429 err = unpack_packed_int(self, &tdelta, 2);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
430 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
431 case WHAT_LINENO:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
432 err = unpack_packed_int(self, &lineno, 2);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
433 if (self->linetimings && !err)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
434 err = unpack_packed_int(self, &tdelta, 0);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
435 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
436 case WHAT_ADD_INFO:
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
437 err = unpack_add_info(self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
438 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
439 case WHAT_DEFINE_FILE:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
440 err = unpack_packed_int(self, &fileno, 0);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
441 if (!err) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
442 err = unpack_string(self, &s1);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
443 if (!err) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
444 Py_INCREF(Py_None);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
445 s2 = Py_None;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
446 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
447 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
448 break;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
449 case WHAT_DEFINE_FUNC:
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
450 err = unpack_packed_int(self, &fileno, 0);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
451 if (!err) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
452 err = unpack_packed_int(self, &lineno, 0);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
453 if (!err)
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
454 err = unpack_string(self, &s1);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
455 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
456 break;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
457 case WHAT_LINE_TIMES:
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
458 if ((c = fgetc(self->logfp)) == EOF)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
459 err = ERR_EOF;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
460 else {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
461 self->linetimings = c ? 1 : 0;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
462 goto restart;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
463 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
464 break;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
465 case WHAT_FRAME_TIMES:
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
466 if ((c = fgetc(self->logfp)) == EOF)
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
467 err = ERR_EOF;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
468 else {
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
469 self->frametimings = c ? 1 : 0;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
470 goto restart;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
471 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
472 break;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
473 default:
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
474 err = ERR_BAD_RECTYPE;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
475 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
476 if (err == ERR_BAD_RECTYPE) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
477 PyErr_SetString(PyExc_ValueError,
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
478 "unknown record type in log file");
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
479 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
480 else if (err == ERR_EOF) {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
481 eof_error(self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
482 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
483 else if (!err) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
484 result = PyTuple_New(4);
36861
895074e5ed3a Thanks to Coverity, these were all reported by their Prevent tool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
485 if (result == NULL)
895074e5ed3a Thanks to Coverity, these were all reported by their Prevent tool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
486 return NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
487 PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
488 PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
489 if (s1 == NULL)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
490 PyTuple_SET_ITEM(result, 1, PyInt_FromLong(tdelta));
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
491 else
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
492 PyTuple_SET_ITEM(result, 1, s1);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
493 if (s2 == NULL)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
494 PyTuple_SET_ITEM(result, 3, PyInt_FromLong(lineno));
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
495 else
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
496 PyTuple_SET_ITEM(result, 3, s2);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
497 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
498 /* The only other case is err == ERR_EXCEPTION, in which case the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
499 * exception is already set.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
500 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
501 #if 0
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
502 b0 = self->buffer[self->index];
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
503 b1 = self->buffer[self->index + 1];
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
504 if (b0 & 1) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
505 /* This is a line-number event. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
506 what = PyTrace_LINE;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
507 lineno = ((b0 & ~1) << 7) + b1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
508 self->index += 2;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
509 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
510 else {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
511 what = (b0 & 0x0E) >> 1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
512 tdelta = ((b0 & 0xF0) << 4) + b1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
513 if (what == PyTrace_CALL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
514 /* we know there's a 2-byte file ID & 2-byte line number */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
515 fileno = ((self->buffer[self->index + 2] << 8)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
516 + self->buffer[self->index + 3]);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
517 lineno = ((self->buffer[self->index + 4] << 8)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
518 + self->buffer[self->index + 5]);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
519 self->index += 6;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
520 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
521 else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
522 self->index += 2;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
523 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
524 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
525 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
526 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
527
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
528 static void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
529 logreader_dealloc(LogReaderObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
530 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
531 if (self->logfp != NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
532 fclose(self->logfp);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
533 self->logfp = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
534 }
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
535 Py_XDECREF(self->info);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
536 PyObject_Del(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
537 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
538
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
539 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
540 logreader_sq_item(LogReaderObject *self, Py_ssize_t index)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
541 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
542 PyObject *result = logreader_tp_iternext(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
543 if (result == NULL && !PyErr_Occurred()) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
544 PyErr_SetString(PyExc_IndexError, "no more events in log");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
545 return NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
546 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
547 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
548 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
549
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
550 static void
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
551 do_stop(ProfilerObject *self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
552
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
553 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
554 flush_data(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
555 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
556 /* Need to dump data to the log file... */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
557 size_t written = fwrite(self->buffer, 1, self->index, self->logfp);
20400
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
558 if (written == (size_t)self->index)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
559 self->index = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
560 else {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
561 memmove(self->buffer, &self->buffer[written],
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
562 self->index - written);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
563 self->index -= written;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
564 if (written == 0) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
565 char *s = PyString_AsString(self->logfilename);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
566 PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
567 do_stop(self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
568 return -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
569 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
570 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
571 if (written > 0) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
572 if (fflush(self->logfp)) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
573 char *s = PyString_AsString(self->logfilename);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
574 PyErr_SetFromErrnoWithFilename(PyExc_IOError, s);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
575 do_stop(self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
576 return -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
577 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
578 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
579 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
580 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
581
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
582 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
583 pack_packed_int(ProfilerObject *self, int value)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
584 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
585 unsigned char partial;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
586
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
587 do {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
588 partial = value & 0x7F;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
589 value >>= 7;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
590 if (value)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
591 partial |= 0x80;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
592 self->buffer[self->index] = partial;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
593 self->index++;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
594 } while (value);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
595 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
596 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
597
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
598 /* Encode a modified packed integer, with a subfield of modsize bits
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
599 * containing the value "subfield". The value of subfield is not
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
600 * checked to ensure it actually fits in modsize bits.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
601 */
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
602 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
603 pack_modified_packed_int(ProfilerObject *self, int value,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
604 int modsize, int subfield)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
605 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
606 const int maxvalues[] = {-1, 1, 3, 7, 15, 31, 63, 127};
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
607
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
608 int bits = 7 - modsize;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
609 int partial = value & maxvalues[bits];
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
610 unsigned char b = subfield | (partial << modsize);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
611
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
612 if (partial != value) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
613 b |= 0x80;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
614 self->buffer[self->index] = b;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
615 self->index++;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
616 return pack_packed_int(self, value >> bits);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
617 }
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
618 self->buffer[self->index] = b;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
619 self->index++;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
620 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
621 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
622
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
623 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
624 pack_string(ProfilerObject *self, const char *s, Py_ssize_t len)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
625 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
626 if (len + PISIZE + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
627 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
628 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
629 }
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
630 assert(len < INT_MAX);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
631 if (pack_packed_int(self, (int)len) < 0)
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
632 return -1;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
633 memcpy(self->buffer + self->index, s, len);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
634 self->index += len;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
635 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
636 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
637
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
638 static int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
639 pack_add_info(ProfilerObject *self, const char *s1, const char *s2)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
640 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
641 Py_ssize_t len1 = strlen(s1);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
642 Py_ssize_t len2 = strlen(s2);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
643
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
644 if (len1 + len2 + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
645 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
646 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
647 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
648 self->buffer[self->index] = WHAT_ADD_INFO;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
649 self->index++;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
650 if (pack_string(self, s1, len1) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
651 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
652 return pack_string(self, s2, len2);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
653 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
654
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
655 static int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
656 pack_define_file(ProfilerObject *self, int fileno, const char *filename)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
657 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
658 Py_ssize_t len = strlen(filename);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
659
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
660 if (len + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
661 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
662 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
663 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
664 self->buffer[self->index] = WHAT_DEFINE_FILE;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
665 self->index++;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
666 if (pack_packed_int(self, fileno) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
667 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
668 return pack_string(self, filename, len);
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
669 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
670
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
671 static int
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
672 pack_define_func(ProfilerObject *self, int fileno, int lineno,
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
673 const char *funcname)
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
674 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36090
diff changeset
675 Py_ssize_t len = strlen(funcname);
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
676
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
677 if (len + PISIZE*3 + 1 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
678 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
679 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
680 }
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
681 self->buffer[self->index] = WHAT_DEFINE_FUNC;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
682 self->index++;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
683 if (pack_packed_int(self, fileno) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
684 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
685 if (pack_packed_int(self, lineno) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
686 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
687 return pack_string(self, funcname, len);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
688 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
689
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
690 static int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
691 pack_line_times(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
692 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
693 if (2 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
694 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
695 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
696 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
697 self->buffer[self->index] = WHAT_LINE_TIMES;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
698 self->buffer[self->index + 1] = self->linetimings ? 1 : 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
699 self->index += 2;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
700 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
701 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
702
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
703 static int
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
704 pack_frame_times(ProfilerObject *self)
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
705 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
706 if (2 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
707 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
708 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
709 }
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
710 self->buffer[self->index] = WHAT_FRAME_TIMES;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
711 self->buffer[self->index + 1] = self->frametimings ? 1 : 0;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
712 self->index += 2;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
713 return 0;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
714 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
715
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
716 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
717 pack_enter(ProfilerObject *self, int fileno, int tdelta, int lineno)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
718 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
719 if (MPISIZE + PISIZE*2 + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
720 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
721 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
722 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
723 pack_modified_packed_int(self, fileno, 2, WHAT_ENTER);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
724 pack_packed_int(self, lineno);
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
725 if (self->frametimings)
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
726 return pack_packed_int(self, tdelta);
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
727 else
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
728 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
729 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
730
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
731 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
732 pack_exit(ProfilerObject *self, int tdelta)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
733 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
734 if (MPISIZE + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
735 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
736 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
737 }
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
738 if (self->frametimings)
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
739 return pack_modified_packed_int(self, tdelta, 2, WHAT_EXIT);
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
740 self->buffer[self->index] = WHAT_EXIT;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
741 self->index++;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
742 return 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
743 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
744
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
745 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
746 pack_lineno(ProfilerObject *self, int lineno)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
747 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
748 if (MPISIZE + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
749 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
750 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
751 }
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
752 return pack_modified_packed_int(self, lineno, 2, WHAT_LINENO);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
753 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
754
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
755 static inline int
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
756 pack_lineno_tdelta(ProfilerObject *self, int lineno, int tdelta)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
757 {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
758 if (MPISIZE + PISIZE + self->index >= BUFFERSIZE) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
759 if (flush_data(self) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
760 return 0;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
761 }
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
762 if (pack_modified_packed_int(self, lineno, 2, WHAT_LINENO) < 0)
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
763 return -1;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
764 return pack_packed_int(self, tdelta);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
765 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
766
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
767 static inline int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
768 get_fileno(ProfilerObject *self, PyCodeObject *fcode)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
769 {
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
770 /* This is only used for ENTER events. */
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
771
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
772 PyObject *obj;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
773 PyObject *dict;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
774 int fileno;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
775
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
776 obj = PyDict_GetItem(self->filemap, fcode->co_filename);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
777 if (obj == NULL) {
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
778 /* first sighting of this file */
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
779 dict = PyDict_New();
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
780 if (dict == NULL) {
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
781 return -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
782 }
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
783 fileno = self->next_fileno;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
784 obj = Py_BuildValue("iN", fileno, dict);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
785 if (obj == NULL) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
786 return -1;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
787 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
788 if (PyDict_SetItem(self->filemap, fcode->co_filename, obj)) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
789 Py_DECREF(obj);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
790 return -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
791 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
792 self->next_fileno++;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
793 Py_DECREF(obj);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
794 if (pack_define_file(self, fileno,
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
795 PyString_AS_STRING(fcode->co_filename)) < 0)
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
796 return -1;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
797 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
798 else {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
799 /* already know this ID */
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
800 fileno = PyInt_AS_LONG(PyTuple_GET_ITEM(obj, 0));
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
801 dict = PyTuple_GET_ITEM(obj, 1);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
802 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
803 /* make sure we save a function name for this (fileno, lineno) */
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
804 obj = PyInt_FromLong(fcode->co_firstlineno);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
805 if (obj == NULL) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
806 /* We just won't have it saved; too bad. */
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
807 PyErr_Clear();
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
808 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
809 else {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
810 PyObject *name = PyDict_GetItem(dict, obj);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
811 if (name == NULL) {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
812 if (pack_define_func(self, fileno, fcode->co_firstlineno,
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
813 PyString_AS_STRING(fcode->co_name)) < 0) {
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
814 Py_DECREF(obj);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
815 return -1;
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
816 }
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
817 if (PyDict_SetItem(dict, obj, fcode->co_name)) {
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
818 Py_DECREF(obj);
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
819 return -1;
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
820 }
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
821 }
32912
329d4906c33f SF bug #808756: refleaks in _hotshot.c.
Armin Rigo <arigo@tunes.org>
parents: 32345
diff changeset
822 Py_DECREF(obj);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
823 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
824 return fileno;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
825 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
826
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
827 static inline int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
828 get_tdelta(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
829 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
830 int tdelta;
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
831 #ifdef MS_WINDOWS
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
832 hs_time tv;
20410
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
833 hs_time diff;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
834
20410
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
835 GETTIMEOFDAY(&tv);
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
836 diff = tv - self->prev_timeofday;
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
837 tdelta = (int)diff;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
838 #else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
839 struct timeval tv;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
840
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
841 GETTIMEOFDAY(&tv);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
842
32345
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
843 tdelta = tv.tv_usec - self->prev_timeofday.tv_usec;
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
844 if (tv.tv_sec != self->prev_timeofday.tv_sec)
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
845 tdelta += (tv.tv_sec - self->prev_timeofday.tv_sec) * 1000000;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
846 #endif
32345
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
847 /* time can go backwards on some multiprocessor systems or by NTP */
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
848 if (tdelta < 0)
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
849 return 0;
8b2df9a07cd7 SF patch #969180, hotshot incorrectly computes elapsed time by Jason
Neal Norwitz <nnorwitz@gmail.com>
parents: 30979
diff changeset
850
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
851 self->prev_timeofday = tv;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
852 return tdelta;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
853 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
854
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
855
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
856 /* The workhorse: the profiler callback function. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
857
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
858 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
859 tracer_callback(ProfilerObject *self, PyFrameObject *frame, int what,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
860 PyObject *arg)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
861 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
862 int fileno;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
863
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
864 switch (what) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
865 case PyTrace_CALL:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
866 fileno = get_fileno(self, frame->f_code);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
867 if (fileno < 0)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
868 return -1;
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
869 return pack_enter(self, fileno,
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
870 self->frametimings ? get_tdelta(self) : -1,
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
871 frame->f_code->co_firstlineno);
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
872
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
873 case PyTrace_RETURN:
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
874 return pack_exit(self, get_tdelta(self));
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
875
35994
ab431b324a4b Nobody on python-dev seemed particularly bothered that Hotshot generates half-
Armin Rigo <arigo@tunes.org>
parents: 35766
diff changeset
876 case PyTrace_LINE: /* we only get these events if we asked for them */
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
877 if (self->linetimings)
25213
75cd4c203d8f Fix *really* embarrassing typo reported by Raymond Hettinger.
Michael W. Hudson <mwh@python.net>
parents: 25207
diff changeset
878 return pack_lineno_tdelta(self, frame->f_lineno,
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
879 get_tdelta(self));
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
880 else
25207
1e46da1e6522 A slight change to SET_LINENO-less tracing.
Michael W. Hudson <mwh@python.net>
parents: 24844
diff changeset
881 return pack_lineno(self, frame->f_lineno);
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
882
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
883 default:
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
884 /* ignore PyTrace_EXCEPTION */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
885 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
886 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
887 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
888 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
889
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
890
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
891 /* A couple of useful helper functions. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
892
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
893 #ifdef MS_WINDOWS
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
894 static LARGE_INTEGER frequency = {0, 0};
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
895 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
896
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
897 static unsigned long timeofday_diff = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
898 static unsigned long rusage_diff = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
899
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
900 static void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
901 calibrate(void)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
902 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
903 hs_time tv1, tv2;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
904
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
905 #ifdef MS_WINDOWS
20410
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
906 hs_time diff;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
907 QueryPerformanceFrequency(&frequency);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
908 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
909
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
910 GETTIMEOFDAY(&tv1);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
911 while (1) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
912 GETTIMEOFDAY(&tv2);
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
913 #ifdef MS_WINDOWS
20410
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
914 diff = tv2 - tv1;
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
915 if (diff != 0) {
2a4bb7d19b60 Speed the Windows code by using native 64-bit int compiler support instead
Tim Peters <tim.peters@gmail.com>
parents: 20404
diff changeset
916 timeofday_diff = (unsigned long)diff;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
917 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
918 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
919 #else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
920 if (tv1.tv_sec != tv2.tv_sec || tv1.tv_usec != tv2.tv_usec) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
921 if (tv1.tv_sec == tv2.tv_sec)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
922 timeofday_diff = tv2.tv_usec - tv1.tv_usec;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
923 else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
924 timeofday_diff = (1000000 - tv1.tv_usec) + tv2.tv_usec;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
925 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
926 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
927 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
928 }
30979
86fdf8fe7f17 Getting rid of all the code inside #ifdef macintosh too.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28320
diff changeset
929 #if defined(MS_WINDOWS) || defined(PYOS_OS2) || \
37713
91d16a87cbe8 Patch #1470300: Port _hotshot to QNX4.25 port.
Martin v. Löwis <martin@v.loewis.de>
parents: 37666
diff changeset
930 defined(__VMS) || defined (__QNX__)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
931 rusage_diff = -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
932 #else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
933 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
934 struct rusage ru1, ru2;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
935
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
936 getrusage(RUSAGE_SELF, &ru1);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
937 while (1) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
938 getrusage(RUSAGE_SELF, &ru2);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
939 if (ru1.ru_utime.tv_sec != ru2.ru_utime.tv_sec) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
940 rusage_diff = ((1000000 - ru1.ru_utime.tv_usec)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
941 + ru2.ru_utime.tv_usec);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
942 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
943 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
944 else if (ru1.ru_utime.tv_usec != ru2.ru_utime.tv_usec) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
945 rusage_diff = ru2.ru_utime.tv_usec - ru1.ru_utime.tv_usec;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
946 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
947 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
948 else if (ru1.ru_stime.tv_sec != ru2.ru_stime.tv_sec) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
949 rusage_diff = ((1000000 - ru1.ru_stime.tv_usec)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
950 + ru2.ru_stime.tv_usec);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
951 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
952 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
953 else if (ru1.ru_stime.tv_usec != ru2.ru_stime.tv_usec) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
954 rusage_diff = ru2.ru_stime.tv_usec - ru1.ru_stime.tv_usec;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
955 break;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
956 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
957 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
958 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
959 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
960 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
961
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
962 static void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
963 do_start(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
964 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
965 self->active = 1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
966 GETTIMEOFDAY(&self->prev_timeofday);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
967 if (self->lineevents)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
968 PyEval_SetTrace((Py_tracefunc) tracer_callback, (PyObject *)self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
969 else
35994
ab431b324a4b Nobody on python-dev seemed particularly bothered that Hotshot generates half-
Armin Rigo <arigo@tunes.org>
parents: 35766
diff changeset
970 PyEval_SetProfile((Py_tracefunc) tracer_callback, (PyObject *)self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
971 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
972
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
973 static void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
974 do_stop(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
975 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
976 if (self->active) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
977 self->active = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
978 if (self->lineevents)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
979 PyEval_SetTrace(NULL, NULL);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
980 else
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
981 PyEval_SetProfile(NULL, NULL);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
982 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
983 if (self->index > 0) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
984 /* Best effort to dump out any remaining data. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
985 flush_data(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
986 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
987 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
988
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
989 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
990 is_available(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
991 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
992 if (self->active) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
993 PyErr_SetString(ProfilerError, "profiler already active");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
994 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
995 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
996 if (self->logfp == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
997 PyErr_SetString(ProfilerError, "profiler already closed");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
998 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
999 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1000 return 1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1001 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1002
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1003
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1004 /* Profiler object interface methods. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1005
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1006 PyDoc_STRVAR(addinfo__doc__,
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1007 "addinfo(key, value)\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1008 "Insert an ADD_INFO record into the log.");
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1009
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1010 static PyObject *
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1011 profiler_addinfo(ProfilerObject *self, PyObject *args)
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1012 {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1013 PyObject *result = NULL;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1014 char *key, *value;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1015
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1016 if (PyArg_ParseTuple(args, "ss:addinfo", &key, &value)) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1017 if (self->logfp == NULL)
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1018 PyErr_SetString(ProfilerError, "profiler already closed");
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1019 else {
21203
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
1020 if (pack_add_info(self, key, value) == 0) {
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
1021 result = Py_None;
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
1022 Py_INCREF(result);
d95eb7ec4553 Make sure to propogate errors that arise when profiling data cannot be
Fred Drake <fdrake@acm.org>
parents: 21073
diff changeset
1023 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1024 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1025 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1026 return result;
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1027 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1028
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1029 PyDoc_STRVAR(close__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1030 "close()\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1031 "Shut down this profiler and close the log files, even if its active.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1032
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1033 static PyObject *
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1034 profiler_close(ProfilerObject *self)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1035 {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1036 do_stop(self);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1037 if (self->logfp != NULL) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1038 fclose(self->logfp);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1039 self->logfp = NULL;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1040 }
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1041 Py_INCREF(Py_None);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1042 return Py_None;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1043 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1044
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1045 #define fileno__doc__ logreader_fileno__doc__
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1046
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1047 static PyObject *
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1048 profiler_fileno(ProfilerObject *self)
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1049 {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1050 if (self->logfp == NULL) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1051 PyErr_SetString(PyExc_ValueError,
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1052 "profiler's file object already closed");
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1053 return NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1054 }
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1055 return PyInt_FromLong(fileno(self->logfp));
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1056 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1057
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1058 PyDoc_STRVAR(runcall__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1059 "runcall(callable[, args[, kw]]) -> callable()\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1060 "Profile a specific function call, returning the result of that call.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1061
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1062 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1063 profiler_runcall(ProfilerObject *self, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1064 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1065 PyObject *result = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1066 PyObject *callargs = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1067 PyObject *callkw = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1068 PyObject *callable;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1069
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1070 if (PyArg_UnpackTuple(args, "runcall", 1, 3,
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1071 &callable, &callargs, &callkw)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1072 if (is_available(self)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1073 do_start(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1074 result = PyEval_CallObjectWithKeywords(callable, callargs, callkw);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1075 do_stop(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1076 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1077 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1078 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1079 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1080
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1081 PyDoc_STRVAR(runcode__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1082 "runcode(code, globals[, locals])\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1083 "Execute a code object while collecting profile data. If locals is\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1084 "omitted, globals is used for the locals as well.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1085
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1086 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1087 profiler_runcode(ProfilerObject *self, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1088 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1089 PyObject *result = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1090 PyCodeObject *code;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1091 PyObject *globals;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1092 PyObject *locals = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1093
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1094 if (PyArg_ParseTuple(args, "O!O!|O:runcode",
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1095 &PyCode_Type, &code,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1096 &PyDict_Type, &globals,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1097 &locals)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1098 if (is_available(self)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1099 if (locals == NULL || locals == Py_None)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1100 locals = globals;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1101 else if (!PyDict_Check(locals)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1102 PyErr_SetString(PyExc_TypeError,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1103 "locals must be a dictionary or None");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1104 return NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1105 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1106 do_start(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1107 result = PyEval_EvalCode(code, globals, locals);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1108 do_stop(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1109 #if 0
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1110 if (!PyErr_Occurred()) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1111 result = Py_None;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1112 Py_INCREF(result);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1113 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1114 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1115 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1116 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1117 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1118 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1119
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1120 PyDoc_STRVAR(start__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1121 "start()\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1122 "Install this profiler for the current thread.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1123
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1124 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1125 profiler_start(ProfilerObject *self, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1126 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1127 PyObject *result = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1128
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1129 if (is_available(self)) {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1130 do_start(self);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1131 result = Py_None;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1132 Py_INCREF(result);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1133 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1134 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1135 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1136
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1137 PyDoc_STRVAR(stop__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1138 "stop()\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1139 "Remove this profiler from the current thread.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1140
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1141 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1142 profiler_stop(ProfilerObject *self, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1143 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1144 PyObject *result = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1145
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1146 if (!self->active)
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1147 PyErr_SetString(ProfilerError, "profiler not active");
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1148 else {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1149 do_stop(self);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1150 result = Py_None;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1151 Py_INCREF(result);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1152 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1153 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1154 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1155
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1156
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1157 /* Python API support. */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1158
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1159 static void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1160 profiler_dealloc(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1161 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1162 do_stop(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1163 if (self->logfp != NULL)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1164 fclose(self->logfp);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1165 Py_XDECREF(self->filemap);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1166 Py_XDECREF(self->logfilename);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1167 PyObject_Del((PyObject *)self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1168 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1169
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1170 static PyMethodDef profiler_methods[] = {
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1171 {"addinfo", (PyCFunction)profiler_addinfo, METH_VARARGS, addinfo__doc__},
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1172 {"close", (PyCFunction)profiler_close, METH_NOARGS, close__doc__},
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1173 {"fileno", (PyCFunction)profiler_fileno, METH_NOARGS, fileno__doc__},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1174 {"runcall", (PyCFunction)profiler_runcall, METH_VARARGS, runcall__doc__},
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1175 {"runcode", (PyCFunction)profiler_runcode, METH_VARARGS, runcode__doc__},
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1176 {"start", (PyCFunction)profiler_start, METH_NOARGS, start__doc__},
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1177 {"stop", (PyCFunction)profiler_stop, METH_NOARGS, stop__doc__},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1178 {NULL, NULL}
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1179 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1180
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1181 static PyMemberDef profiler_members[] = {
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1182 {"frametimings", T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1183 {"lineevents", T_LONG, offsetof(ProfilerObject, lineevents), READONLY},
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1184 {"linetimings", T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1185 {NULL}
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1186 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1187
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1188 static PyObject *
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1189 profiler_get_closed(ProfilerObject *self, void *closure)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1190 {
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1191 PyObject *result = (self->logfp == NULL) ? Py_True : Py_False;
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1192 Py_INCREF(result);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1193 return result;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1194 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1195
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1196 static PyGetSetDef profiler_getsets[] = {
24285
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1197 {"closed", (getter)profiler_get_closed, NULL,
24286
4e85306a9bbf Mark the closed attribute of the profiler with PyDoc_STR(), and added
Fred Drake <fdrake@acm.org>
parents: 24285
diff changeset
1198 PyDoc_STR("True if the profiler's output file has already been closed.")},
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1199 {NULL}
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1200 };
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1201
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1202
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1203 PyDoc_STRVAR(profiler_object__doc__,
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1204 "High-performance profiler object.\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1205 "\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1206 "Methods:\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1207 "\n"
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1208 "close(): Stop the profiler and close the log files.\n"
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1209 "fileno(): Returns the file descriptor of the log file.\n"
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1210 "runcall(): Run a single function call with profiling enabled.\n"
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1211 "runcode(): Execute a code object with profiling enabled.\n"
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1212 "start(): Install the profiler and return.\n"
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1213 "stop(): Remove the profiler.\n"
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1214 "\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1215 "Attributes (read-only):\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1216 "\n"
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1217 "closed: True if the profiler has already been closed.\n"
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1218 "frametimings: True if ENTER/EXIT events collect timing information.\n"
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24669
diff changeset
1219 "lineevents: True if line events are reported to the profiler.\n"
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24669
diff changeset
1220 "linetimings: True if line events collect timing information.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1221
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1222 static PyTypeObject ProfilerType = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
1223 PyVarObject_HEAD_INIT(NULL, 0)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1224 "_hotshot.ProfilerType", /* tp_name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1225 (int) sizeof(ProfilerObject), /* tp_basicsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1226 0, /* tp_itemsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1227 (destructor)profiler_dealloc, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1228 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1229 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1230 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1231 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1232 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1233 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1234 0, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1235 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1236 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1237 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1238 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1239 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1240 0, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1241 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1242 Py_TPFLAGS_DEFAULT, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1243 profiler_object__doc__, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1244 0, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1245 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1246 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1247 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1248 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1249 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1250 profiler_methods, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1251 profiler_members, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1252 profiler_getsets, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1253 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1254 0, /* tp_dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1255 0, /* tp_descr_get */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1256 0, /* tp_descr_set */
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1257 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1258
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1259
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1260 static PyMethodDef logreader_methods[] = {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1261 {"close", (PyCFunction)logreader_close, METH_NOARGS,
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1262 logreader_close__doc__},
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1263 {"fileno", (PyCFunction)logreader_fileno, METH_NOARGS,
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1264 logreader_fileno__doc__},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1265 {NULL, NULL}
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1266 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1267
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1268 static PyMemberDef logreader_members[] = {
24286
4e85306a9bbf Mark the closed attribute of the profiler with PyDoc_STR(), and added
Fred Drake <fdrake@acm.org>
parents: 24285
diff changeset
1269 {"info", T_OBJECT, offsetof(LogReaderObject, info), RO,
4e85306a9bbf Mark the closed attribute of the profiler with PyDoc_STR(), and added
Fred Drake <fdrake@acm.org>
parents: 24285
diff changeset
1270 PyDoc_STR("Dictionary mapping informational keys to lists of values.")},
24279
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1271 {NULL}
1a703f9bbdc0 Some modernization. Get rid of the redundant next() method. Always
Guido van Rossum <guido@python.org>
parents: 24071
diff changeset
1272 };
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1273
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1274
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1275 PyDoc_STRVAR(logreader__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1276 "logreader(filename) --> log-iterator\n\
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1277 Create a log-reader for the timing information file.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1278
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1279 static PySequenceMethods logreader_as_sequence = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1280 0, /* sq_length */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1281 0, /* sq_concat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1282 0, /* sq_repeat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1283 (ssizeargfunc)logreader_sq_item, /* sq_item */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1284 0, /* sq_slice */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1285 0, /* sq_ass_item */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1286 0, /* sq_ass_slice */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1287 0, /* sq_contains */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1288 0, /* sq_inplace_concat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1289 0, /* sq_inplace_repeat */
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1290 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1291
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1292 static PyObject *
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1293 logreader_get_closed(LogReaderObject *self, void *closure)
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1294 {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1295 PyObject *result = (self->logfp == NULL) ? Py_True : Py_False;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1296 Py_INCREF(result);
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1297 return result;
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1298 }
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1299
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1300 static PyGetSetDef logreader_getsets[] = {
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1301 {"closed", (getter)logreader_get_closed, NULL,
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1302 PyDoc_STR("True if the logreader's input file has already been closed.")},
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1303 {NULL}
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1304 };
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1305
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1306 static PyTypeObject LogReaderType = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
1307 PyVarObject_HEAD_INIT(NULL, 0)
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1308 "_hotshot.LogReaderType", /* tp_name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1309 (int) sizeof(LogReaderObject), /* tp_basicsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1310 0, /* tp_itemsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1311 (destructor)logreader_dealloc, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1312 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1313 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1314 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1315 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1316 0, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1317 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1318 &logreader_as_sequence, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1319 0, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1320 0, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1321 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1322 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1323 PyObject_GenericGetAttr, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1324 0, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1325 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1326 Py_TPFLAGS_DEFAULT, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1327 logreader__doc__, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1328 0, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1329 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1330 0, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1331 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1332 PyObject_SelfIter, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1333 (iternextfunc)logreader_tp_iternext,/* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1334 logreader_methods, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1335 logreader_members, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1336 logreader_getsets, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1337 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1338 0, /* tp_dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1339 0, /* tp_descr_get */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1340 0, /* tp_descr_set */
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1341 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1342
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1343 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1344 hotshot_logreader(PyObject *unused, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1345 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1346 LogReaderObject *self = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1347 char *filename;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1348 int c;
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1349 int err = 0;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1350
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1351 if (PyArg_ParseTuple(args, "s:logreader", &filename)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1352 self = PyObject_New(LogReaderObject, &LogReaderType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1353 if (self != NULL) {
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1354 self->frametimings = 1;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1355 self->linetimings = 0;
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1356 self->info = NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1357 self->logfp = fopen(filename, "rb");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1358 if (self->logfp == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1359 PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
50193
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1360 goto error;
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1361 }
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1362 self->info = PyDict_New();
50193
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1363 if (self->info == NULL)
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1364 goto error;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1365 /* read initial info */
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1366 for (;;) {
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1367 if ((c = fgetc(self->logfp)) == EOF) {
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1368 eof_error(self);
50193
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1369 goto error;
23568
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1370 }
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1371 if (c != WHAT_ADD_INFO) {
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1372 ungetc(c, self->logfp);
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1373 break;
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1374 }
ae0a3b14d2e8 The logreader object did not always refill the input buffer correctly
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22421
diff changeset
1375 err = unpack_add_info(self);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1376 if (err) {
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1377 if (err == ERR_EOF)
24295
a26ca8ab27f2 - When the log reader detects end-of-file, close the file.
Fred Drake <fdrake@acm.org>
parents: 24286
diff changeset
1378 eof_error(self);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1379 else
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1380 PyErr_SetString(PyExc_RuntimeError,
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1381 "unexpected error");
50193
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1382 goto error;
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1383 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1384 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1385 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1386 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1387 return (PyObject *) self;
50193
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1388 error:
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1389 Py_DECREF(self);
9541a2ecc4fb Merged revisions 67797 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47527
diff changeset
1390 return NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1391 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1392
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1393
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1394 /* Return a Python string that represents the version number without the
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1395 * extra cruft added by revision control, even if the right options were
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1396 * given to the "cvs export" command to make it not include the extra
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1397 * cruft.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1398 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1399 static char *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1400 get_version_string(void)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1401 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1402 static char *rcsid = "$Revision$";
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1403 char *rev = rcsid;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1404 char *buffer;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1405 int i = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1406
36090
8cb686dd6e64 Fix SF bug #1072182, problems with signed characters.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35994
diff changeset
1407 while (*rev && !isdigit(Py_CHARMASK(*rev)))
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1408 ++rev;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1409 while (rev[i] != ' ' && rev[i] != '\0')
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1410 ++i;
37666
5a9fcd676b3f C++ compiler changes. casts, rename variables with reserved names.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 36886
diff changeset
1411 buffer = (char *)malloc(i + 1);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1412 if (buffer != NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1413 memmove(buffer, rev, i);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1414 buffer[i] = '\0';
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1415 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1416 return buffer;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1417 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1418
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1419 /* Write out a RFC 822-style header with various useful bits of
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1420 * information to make the output easier to manage.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1421 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1422 static int
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1423 write_header(ProfilerObject *self)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1424 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1425 char *buffer;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1426 char cwdbuffer[PATH_MAX];
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1427 PyObject *temp;
37920
ce5585afc20f Fix more ssize_t issues.
Martin v. Löwis <martin@v.loewis.de>
parents: 37713
diff changeset
1428 Py_ssize_t i, len;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1429
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1430 buffer = get_version_string();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1431 if (buffer == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1432 PyErr_NoMemory();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1433 return -1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1434 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1435 pack_add_info(self, "hotshot-version", buffer);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1436 pack_add_info(self, "requested-frame-timings",
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1437 (self->frametimings ? "yes" : "no"));
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1438 pack_add_info(self, "requested-line-events",
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1439 (self->lineevents ? "yes" : "no"));
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1440 pack_add_info(self, "requested-line-timings",
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1441 (self->linetimings ? "yes" : "no"));
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1442 pack_add_info(self, "platform", Py_GetPlatform());
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1443 pack_add_info(self, "executable", Py_GetProgramFullPath());
20921
9e8885bbdbc9 Fix memory leak. This is (very!) similar to part of SF patch #478006.
Fred Drake <fdrake@acm.org>
parents: 20747
diff changeset
1444 free(buffer);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1445 buffer = (char *) Py_GetVersion();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1446 if (buffer == NULL)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1447 PyErr_Clear();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1448 else
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1449 pack_add_info(self, "executable-version", buffer);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1450
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
1451 #ifdef MS_WINDOWS
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
1452 PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%I64d", frequency.QuadPart);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1453 pack_add_info(self, "reported-performance-frequency", cwdbuffer);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1454 #else
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
1455 PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", rusage_diff);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1456 pack_add_info(self, "observed-interval-getrusage", cwdbuffer);
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 20921
diff changeset
1457 PyOS_snprintf(cwdbuffer, sizeof(cwdbuffer), "%lu", timeofday_diff);
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1458 pack_add_info(self, "observed-interval-gettimeofday", cwdbuffer);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1459 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1460
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1461 pack_add_info(self, "current-directory",
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1462 getcwd(cwdbuffer, sizeof cwdbuffer));
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1463
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1464 temp = PySys_GetObject("path");
36861
895074e5ed3a Thanks to Coverity, these were all reported by their Prevent tool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1465 if (temp == NULL || !PyList_Check(temp)) {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1466 PyErr_SetString(PyExc_RuntimeError, "sys.path must be a list");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1467 return -1;
36861
895074e5ed3a Thanks to Coverity, these were all reported by their Prevent tool.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36501
diff changeset
1468 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1469 len = PyList_GET_SIZE(temp);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1470 for (i = 0; i < len; ++i) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1471 PyObject *item = PyList_GET_ITEM(temp, i);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1472 buffer = PyString_AsString(item);
24285
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1473 if (buffer == NULL) {
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1474 pack_add_info(self, "sys-path-entry", "<non-string-path-entry>");
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1475 PyErr_Clear();
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1476 }
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1477 else {
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1478 pack_add_info(self, "sys-path-entry", buffer);
44522a75deec Added a docstring for the closed attribute.
Fred Drake <fdrake@acm.org>
parents: 24279
diff changeset
1479 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1480 }
20747
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1481 pack_frame_times(self);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1482 pack_line_times(self);
9f62955de4c3 Make the low-level log-reader object export a dictionary mapping keys
Fred Drake <fdrake@acm.org>
parents: 20641
diff changeset
1483
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1484 return 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1485 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1486
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1487 PyDoc_STRVAR(profiler__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1488 "profiler(logfilename[, lineevents[, linetimes]]) -> profiler\n\
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1489 Create a new profiler object.");
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1490
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1491 static PyObject *
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1492 hotshot_profiler(PyObject *unused, PyObject *args)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1493 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1494 char *logfilename;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1495 ProfilerObject *self = NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1496 int lineevents = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1497 int linetimings = 1;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1498
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1499 if (PyArg_ParseTuple(args, "s|ii:profiler", &logfilename,
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1500 &lineevents, &linetimings)) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1501 self = PyObject_New(ProfilerObject, &ProfilerType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1502 if (self == NULL)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1503 return NULL;
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1504 self->frametimings = 1;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1505 self->lineevents = lineevents ? 1 : 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1506 self->linetimings = (lineevents && linetimings) ? 1 : 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1507 self->index = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1508 self->active = 0;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1509 self->next_fileno = 0;
20400
65790562033c Get hotshot closer to compiling on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 20396
diff changeset
1510 self->logfp = NULL;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1511 self->logfilename = PyTuple_GET_ITEM(args, 0);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1512 Py_INCREF(self->logfilename);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1513 self->filemap = PyDict_New();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1514 if (self->filemap == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1515 Py_DECREF(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1516 return NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1517 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1518 self->logfp = fopen(logfilename, "wb");
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1519 if (self->logfp == NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1520 Py_DECREF(self);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1521 PyErr_SetFromErrnoWithFilename(PyExc_IOError, logfilename);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1522 return NULL;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1523 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1524 if (timeofday_diff == 0) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1525 /* Run this several times since sometimes the first
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1526 * doesn't give the lowest values, and we're really trying
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1527 * to determine the lowest.
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1528 */
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1529 calibrate();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1530 calibrate();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1531 calibrate();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1532 }
36886
d342b0dc4934 _hotshot hotshot_profiler(): If write_header() returned
Tim Peters <tim.peters@gmail.com>
parents: 36861
diff changeset
1533 if (write_header(self)) {
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1534 /* some error occurred, exception has been set */
36886
d342b0dc4934 _hotshot hotshot_profiler(): If write_header() returned
Tim Peters <tim.peters@gmail.com>
parents: 36861
diff changeset
1535 Py_DECREF(self);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1536 self = NULL;
36886
d342b0dc4934 _hotshot hotshot_profiler(): If write_header() returned
Tim Peters <tim.peters@gmail.com>
parents: 36861
diff changeset
1537 }
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1538 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1539 return (PyObject *) self;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1540 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1541
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1542 PyDoc_STRVAR(coverage__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1543 "coverage(logfilename) -> profiler\n\
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1544 Returns a profiler that doesn't collect any timing information, which is\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1545 useful in building a coverage analysis tool.");
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1546
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1547 static PyObject *
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1548 hotshot_coverage(PyObject *unused, PyObject *args)
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1549 {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1550 char *logfilename;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1551 PyObject *result = NULL;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1552
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1553 if (PyArg_ParseTuple(args, "s:coverage", &logfilename)) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1554 result = hotshot_profiler(unused, args);
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1555 if (result != NULL) {
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1556 ProfilerObject *self = (ProfilerObject *) result;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1557 self->frametimings = 0;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1558 self->linetimings = 0;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1559 self->lineevents = 1;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1560 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1561 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1562 return result;
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1563 }
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1564
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 50193
diff changeset
1565 PyDoc_VAR(resolution__doc__) =
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
1566 #ifdef MS_WINDOWS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1567 PyDoc_STR(
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1568 "resolution() -> (performance-counter-ticks, update-frequency)\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1569 "Return the resolution of the timer provided by the QueryPerformanceCounter()\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1570 "function. The first value is the smallest observed change, and the second\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1571 "is the result of QueryPerformanceFrequency()."
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1572 )
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1573 #else
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1574 PyDoc_STR(
20403
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1575 "resolution() -> (gettimeofday-usecs, getrusage-usecs)\n"
ed2eeab802d2 My editor can't deal with long backslash-continued strings. Changed 'em.
Tim Peters <tim.peters@gmail.com>
parents: 20400
diff changeset
1576 "Return the resolution of the timers provided by the gettimeofday() and\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1577 "getrusage() system calls, or -1 if the call is not supported."
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1578 )
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1579 #endif
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23568
diff changeset
1580 ;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1581
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1582 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1583 hotshot_resolution(PyObject *self, PyObject *unused)
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1584 {
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1585 if (timeofday_diff == 0) {
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1586 calibrate();
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1587 calibrate();
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1588 calibrate();
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1589 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
1590 #ifdef MS_WINDOWS
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1591 return Py_BuildValue("ii", timeofday_diff, frequency.LowPart);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1592 #else
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1593 return Py_BuildValue("ii", timeofday_diff, rusage_diff);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1594 #endif
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1595 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1596
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1597
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1598 static PyMethodDef functions[] = {
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1599 {"coverage", hotshot_coverage, METH_VARARGS, coverage__doc__},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1600 {"profiler", hotshot_profiler, METH_VARARGS, profiler__doc__},
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1601 {"logreader", hotshot_logreader, METH_VARARGS, logreader__doc__},
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 37920
diff changeset
1602 {"resolution", hotshot_resolution, METH_NOARGS, resolution__doc__},
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1603 {NULL, NULL}
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1604 };
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1605
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1606
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1607 void
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1608 init_hotshot(void)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1609 {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1610 PyObject *module;
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1611
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
1612 Py_TYPE(&LogReaderType) = &PyType_Type;
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
1613 Py_TYPE(&ProfilerType) = &PyType_Type;
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1614 module = Py_InitModule("_hotshot", functions);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1615 if (module != NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1616 char *s = get_version_string();
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1617
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1618 PyModule_AddStringConstant(module, "__version__", s);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1619 free(s);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1620 Py_INCREF(&LogReaderType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1621 PyModule_AddObject(module, "LogReaderType",
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1622 (PyObject *)&LogReaderType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1623 Py_INCREF(&ProfilerType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1624 PyModule_AddObject(module, "ProfilerType",
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1625 (PyObject *)&ProfilerType);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1626
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1627 if (ProfilerError == NULL)
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1628 ProfilerError = PyErr_NewException("hotshot.ProfilerError",
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1629 NULL, NULL);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1630 if (ProfilerError != NULL) {
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1631 Py_INCREF(ProfilerError);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1632 PyModule_AddObject(module, "ProfilerError", ProfilerError);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1633 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1634 PyModule_AddIntConstant(module, "WHAT_ENTER", WHAT_ENTER);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1635 PyModule_AddIntConstant(module, "WHAT_EXIT", WHAT_EXIT);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1636 PyModule_AddIntConstant(module, "WHAT_LINENO", WHAT_LINENO);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1637 PyModule_AddIntConstant(module, "WHAT_OTHER", WHAT_OTHER);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1638 PyModule_AddIntConstant(module, "WHAT_ADD_INFO", WHAT_ADD_INFO);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1639 PyModule_AddIntConstant(module, "WHAT_DEFINE_FILE", WHAT_DEFINE_FILE);
20447
353a3e9f8516 Removed useless code to count the number of calls into the profiler.
Fred Drake <fdrake@acm.org>
parents: 20410
diff changeset
1640 PyModule_AddIntConstant(module, "WHAT_DEFINE_FUNC", WHAT_DEFINE_FUNC);
20396
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1641 PyModule_AddIntConstant(module, "WHAT_LINE_TIMES", WHAT_LINE_TIMES);
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1642 }
7294932d74ec The HotShot core: look, ma, no hands!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1643 }