Lines 1-103
Link Here
|
1 |
This first patch fixes a seg-fault at `make test' time -- profile.test crashes |
|
|
2 |
without this change. |
3 |
|
4 |
Submitted to maintainers: |
5 |
|
6 |
https://sourceforge.net/tracker/index.php?func=detail&aid=1925400&group_id=13247&atid=113247 |
7 |
|
8 |
and committed upstream. |
9 |
|
10 |
The second changes TclXOSElapsedTime to better handles clock_t being too |
11 |
narrow (32-bit on FreeBSD). |
12 |
|
13 |
Getting it committed upstream... |
14 |
|
15 |
-mi |
16 |
|
17 |
--- generic/tclXprofile.c 2004-11-22 19:12:54.000000000 -0500 |
18 |
+++ generic/tclXprofile.c 2009-07-31 02:44:11.000000000 -0400 |
19 |
@@ -674,5 +674,5 @@ |
20 |
CallFrame *framePtr; |
21 |
{ |
22 |
- if (framePtr == NULL) |
23 |
+ if (framePtr == NULL || framePtr->objv == NULL) |
24 |
return; |
25 |
InitializeProcStack (infoPtr, framePtr->callerPtr); |
26 |
--- unix/tclXunixOS.c 2005-07-12 15:03:15.000000000 -0400 |
27 |
+++ unix/tclXunixOS.c 2009-11-27 02:00:57.000000000 -0500 |
28 |
@@ -550,4 +550,10 @@ |
29 |
* o realTime - Elapsed real time, in milliseconds is returned here. |
30 |
* o cpuTime - Elapsed CPU time, in milliseconds is returned here. |
31 |
+ * |
32 |
+ * XXX In some cases, clock_t may not be wide enough, such as when it is |
33 |
+ * XXX a signed 32-bit value, its maximum is 2^31 or 2147483648. There |
34 |
+ * XXX are more milliseconds in 25 days: 25*1000*60*60*24 = 2160000000. |
35 |
+ * XXX If a profile-session is to last longer than that, the API needs |
36 |
+ * XXX to use 64-bit values. -mi Nov 27, 2009 |
37 |
*----------------------------------------------------------------------------- |
38 |
*/ |
39 |
@@ -557,4 +563,5 @@ |
40 |
clock_t *cpuTime; |
41 |
{ |
42 |
+ struct tms cpuTimes; |
43 |
/* |
44 |
* If times returns elapsed real time, this is easy. If it returns a status, |
45 |
@@ -562,25 +569,34 @@ |
46 |
*/ |
47 |
#ifndef TIMES_RETS_STATUS |
48 |
- struct tms cpuTimes; |
49 |
+ static clock_t startTime; |
50 |
+ clock_t currentTime; |
51 |
|
52 |
- *realTime = TclXOSTicksToMS (times (&cpuTimes)); |
53 |
- *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime); |
54 |
+ /* |
55 |
+ * If this is the first call, get base time. |
56 |
+ */ |
57 |
+ currentTime = times (&cpuTimes); |
58 |
+ if (startTime == 0) { |
59 |
+ startTime = currentTime; |
60 |
+ *realTime = 0; |
61 |
+ } else |
62 |
+ *realTime = TclXOSTicksToMS (currentTime - startTime); |
63 |
#else |
64 |
static struct timeval startTime = {0, 0}; |
65 |
struct timeval currentTime; |
66 |
- struct tms cpuTimes; |
67 |
|
68 |
/* |
69 |
* If this is the first call, get base time. |
70 |
*/ |
71 |
- if ((startTime.tv_sec == 0) && (startTime.tv_usec == 0)) |
72 |
+ if ((startTime.tv_sec == 0) && (startTime.tv_usec == 0)) { |
73 |
gettimeofday (&startTime, NULL); |
74 |
- |
75 |
- gettimeofday (¤tTime, NULL); |
76 |
- currentTime.tv_sec = currentTime.tv_sec - startTime.tv_sec; |
77 |
- currentTime.tv_usec = currentTime.tv_usec - startTime.tv_usec; |
78 |
- *realTime = (currentTime.tv_sec * 1000) + (currentTime.tv_usec / 1000); |
79 |
+ *realTime = 0; |
80 |
+ } else { |
81 |
+ gettimeofday (¤tTime, NULL); |
82 |
+ currentTime.tv_sec = currentTime.tv_sec - startTime.tv_sec; |
83 |
+ currentTime.tv_usec = currentTime.tv_usec - startTime.tv_usec; |
84 |
+ *realTime = (currentTime.tv_sec * 1000) + (currentTime.tv_usec / 1000); |
85 |
+ } |
86 |
times (&cpuTimes); |
87 |
- *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime); |
88 |
#endif |
89 |
+ *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime); |
90 |
} |
91 |
--- unix/tclXunixPort.h 2005-10-07 19:30:28.000000000 -0400 |
92 |
+++ unix/tclXunixPort.h 2009-11-27 02:31:15.000000000 -0500 |
93 |
@@ -66,4 +66,10 @@ |
94 |
* Make sure CLK_TCK is defined. |
95 |
*/ |
96 |
+#ifdef __FreeBSD__ |
97 |
+# if defined(CLK_TCK) && CLK_TCK == 128 |
98 |
+# undef CLK_TCK |
99 |
+# define CLK_TCK sysconf(_SC_CLK_TCK) |
100 |
+# endif |
101 |
+#endif |
102 |
#ifndef CLK_TCK |
103 |
# ifdef HZ |