aboutsummaryrefslogtreecommitdiffstats
path: root/testing/php7-tideways_xhprof/74.patch
blob: 40629a85c6e6a6c47a97deab5ffa0c472a14e92f (plain)
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
From 520315b6b12f9cd0e1f0d5532a60d80039a25e2d Mon Sep 17 00:00:00 2001
From: Benjamin Eberlei <kontakt@beberlei.de>
Date: Sun, 17 Feb 2019 22:25:26 +0100
Subject: [PATCH] Add ARM and s309 architectures to clock timing.

---
 timer.h | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/timer.h b/timer.h
index fd535e7..9c1f2ff 100644
--- a/timer.h
+++ b/timer.h
@@ -38,8 +38,14 @@ static zend_always_inline uint64 current_timestamp() {
  * @author cjiang
  */
 static zend_always_inline uint64 time_milliseconds(int source, double timebase_factor) {
-#ifdef __APPLE__
+#if defined(_APPLE__)
     return mach_absolute_time() / timebase_factor;
+#elif defined(__s390__) // Covers both s390 and s390x.
+    uint64_t tsc;
+    // Return the CPU clock.
+    asm("stck %0" : "=Q" (tsc) : : "cc");
+
+    return tsc;
 #elif defined(PHP_WIN32)
 
     LARGE_INTEGER count;
@@ -49,12 +55,14 @@ static zend_always_inline uint64 time_milliseconds(int source, double timebase_f
     }
 
     return (double)(count.QuadPart) / timebase_factor;
-#else
+#elif defined(__x86_64__) || defined(__amd64__)
     struct timespec s;
     uint32 a, d;
     uint64 val;
-#if defined(__i386__)
+#elif defined(__i386__)
     int64_t ret;
+#elif defined(__ARM_ARCH)
+    struct timeval tv;
 #endif
 
     switch (source) {
@@ -84,17 +92,19 @@ static zend_always_inline uint64 time_milliseconds(int source, double timebase_f
 #elif defined(__x86_64__) || defined(__amd64__)
             asm volatile("rdtsc" : "=a" (a), "=d" (d));
             (val) = ((uint64)a) | (((uint64)d)<<32);
+            return val / timebase_factor;
 #elif defined(__powerpc__) || defined(__ppc__)
             asm volatile ("mftb %0" : "=r" (val));
+            return val / timebase_factor;
+#elif defined(__ARM_ARCH)
+            gettimeofday(&tv, NULL);
+            return (tv.tv_sec) * 1000000 + tv.tv_usec;
 #else
-#error You need to define CycleTimer for your OS and CPU
+            return 0;
 #endif
-            return val / timebase_factor;
-
         default:
             return 0;
     }
-#endif
 }
 
 /**