summaryrefslogtreecommitdiff
path: root/lang/tclX/files/patch-profile
blob: 395d1f7bd3d89d14c280f0e81a33eb9e412658c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Change TclXOSElapsedTime to better handles clock_t being too narrow
(32-bit on FreeBSD).

Getting it committed upstream...

	-mi

--- unix/tclXunixOS.c	2005-07-12 15:03:15.000000000 -0400
+++ unix/tclXunixOS.c	2009-11-27 02:00:57.000000000 -0500
@@ -550,4 +550,10 @@
  *   o realTime - Elapsed real time, in milliseconds is returned here.
  *   o cpuTime - Elapsed CPU time, in milliseconds is returned here.
+ *
+ * XXX In some cases, clock_t may not be wide enough, such as when it is
+ * XXX a signed 32-bit value, its maximum is 2^31 or 2147483648. There
+ * XXX are more milliseconds in 25 days: 25*1000*60*60*24 = 2160000000.
+ * XXX If a profile-session is to last longer than that, the API needs
+ * XXX to use 64-bit values. -mi Nov 27, 2009
  *-----------------------------------------------------------------------------
  */
@@ -557,4 +563,5 @@
     clock_t *cpuTime;
 {
+    struct tms cpuTimes;
 /*
  * If times returns elapsed real time, this is easy.  If it returns a status,
@@ -562,25 +569,34 @@
  */
 #ifndef TIMES_RETS_STATUS
-    struct tms cpuTimes;
+    static clock_t startTime;
+    clock_t currentTime;
 
-    *realTime = TclXOSTicksToMS (times (&cpuTimes));
-    *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime);
+    /*
+     * If this is the first call, get base time.
+     */
+    currentTime = times (&cpuTimes);
+    if (startTime == 0) {
+	startTime = currentTime;
+        *realTime = 0;
+    } else
+	*realTime = TclXOSTicksToMS (currentTime - startTime);
 #else
     static struct timeval startTime = {0, 0};
     struct timeval currentTime;
-    struct tms cpuTimes;
 
     /*
      * If this is the first call, get base time.
      */
-    if ((startTime.tv_sec == 0) && (startTime.tv_usec == 0))
+    if ((startTime.tv_sec == 0) && (startTime.tv_usec == 0)) {
         gettimeofday (&startTime, NULL);
-    
-    gettimeofday (&currentTime, NULL);
-    currentTime.tv_sec  = currentTime.tv_sec  - startTime.tv_sec;
-    currentTime.tv_usec = currentTime.tv_usec - startTime.tv_usec;
-    *realTime = (currentTime.tv_sec  * 1000) + (currentTime.tv_usec / 1000);
+	*realTime = 0;
+    } else {
+	gettimeofday (&currentTime, NULL);
+	currentTime.tv_sec  = currentTime.tv_sec  - startTime.tv_sec;
+	currentTime.tv_usec = currentTime.tv_usec - startTime.tv_usec;
+	*realTime = (currentTime.tv_sec  * 1000) + (currentTime.tv_usec / 1000);
+    }
     times (&cpuTimes);
-    *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime);
 #endif
+    *cpuTime = TclXOSTicksToMS (cpuTimes.tms_utime + cpuTimes.tms_stime);
 }
--- unix/tclXunixPort.h	2005-10-07 19:30:28.000000000 -0400
+++ unix/tclXunixPort.h	2009-11-27 02:31:15.000000000 -0500
@@ -66,4 +66,10 @@
  * Make sure CLK_TCK is defined.
  */
+#ifdef __FreeBSD__
+#	if defined(CLK_TCK) && CLK_TCK == 128
+#		undef CLK_TCK
+#		define CLK_TCK	sysconf(_SC_CLK_TCK)
+#	endif
+#endif
 #ifndef CLK_TCK
 #    ifdef HZ