Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 67
0.00% covered (danger)
0.00%
0 / 5
CRAP
n/a
0 / 0
zeroBSCRM_performanceTest_startTimer
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
zeroBSCRM_performanceTest_finishTimer
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_performanceTest_results
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
110
zeroBSCRM_performanceTest_debugOut
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
72
zeroBSCRM_performanceTest_closeGlobalTest
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/*
3 * Jetpack CRM
4 * https://jetpackcrm.com
5 */
6
7/*
8    (BASIC) PERFORMANCE TRACKING - include for use.
9
10*/
11
12    #} Store times
13    global $zbsTimes;
14if ( ! isset( $zbsTimes ) ) {
15    $zbsTimes = array();
16}
17
18function zeroBSCRM_performanceTest_startTimer( $key = '' ) {
19
20    if ( ! empty( $key ) ) {
21
22            global $zbsTimes;
23        if ( ! isset( $zbsTimes[ $key ] ) || ! is_array( $zbsTimes[ $key ] ) ) {
24            $zbsTimes[ $key ] = array(
25                'start' => -1,
26                'end'   => -1,
27            );
28        }
29
30            #} start it
31            $zbsTimes[ $key ]['start'] = microtime( true );
32
33    }
34
35    return false;
36}
37function zeroBSCRM_performanceTest_finishTimer( $key = '' ) {
38
39    if ( ! empty( $key ) ) {
40
41            global $zbsTimes;
42
43            #} end it - lazy, no cheeck
44            $zbsTimes[ $key ]['end'] = microtime( true );
45
46    }
47
48    return false;
49}
50
51    // returns singular results for 1 timer
52    // (used by debugger plugin)
53function zeroBSCRM_performanceTest_results( $key = '' ) {
54
55    if ( ! empty( $key ) ) {
56
57            global $zbsTimes;
58
59        if ( is_array( $zbsTimes ) && isset( $zbsTimes[ $key ] ) ) {
60
61            $v = $zbsTimes[ $key ];
62
63            $time_start = -1;
64            if ( isset( $v['start'] ) ) {
65                $time_start = $v['start'];
66            }
67            $time_end = -1;
68            if ( isset( $v['end'] ) ) {
69                $time_end = $v['end'];
70            }
71
72            $sTime      = -1;
73            $sTimeExtra = '';
74            if ( $time_start > -1 && $time_end > -1 ) {
75                    $sTime = round( ( $time_end - $time_start ), 3 );
76            } else {
77
78                // one hasn't been set
79                if ( $time_end == -1 && $time_start > -1 ) {
80
81                    $sTime      = round( ( microtime( true ) - $time_start ), 3 );
82                    $sTimeExtra = '+ (still running)';
83
84                } else {
85
86                    $sTimeExtra = '???';
87
88                }
89            }
90
91            return $sTime . $sTimeExtra;
92
93        }
94    }
95
96    return false;
97}
98
99function zeroBSCRM_performanceTest_debugOut() {
100
101    global $zbsTimes;
102
103    // debug
104    echo '<div><h1>CRM Performance Debug</h1>';
105    $scriptVer = 'console.log("=============== CRM Performance Debug ==============");';
106    foreach ( $zbsTimes as $k => $v ) {
107
108            $time_start = -1;
109        if ( isset( $v['start'] ) ) {
110            $time_start = $v['start'];
111        }
112            $time_end = -1;
113        if ( isset( $v['end'] ) ) {
114            $time_end = $v['end'];
115        }
116
117            $sTime  = -1;
118        $sTimeExtra = '';
119        if ( $time_start > -1 && $time_end > -1 ) {
120            $sTime = round( ( $time_end - $time_start ), 3 );
121        } else {
122
123            // one hasn't been set
124            if ( $time_end == -1 && $time_start > -1 ) {
125
126                $sTime      = round( ( microtime( true ) - $time_start ), 3 );
127                $sTimeExtra = '+ (still running)';
128
129            } else {
130
131                $sTimeExtra = '???';
132
133            }
134        }
135
136            echo '<h2>Time: ' . $k . '</h2>';
137            echo '<p>' . $sTime . $sTimeExtra . ' seconds</p>';
138            $retArr         = $v;
139            $retArr['took'] = $sTime;
140            $scriptVer     .= 'console.log("' . $k . ': ' . $sTime . $sTimeExtra . '",' . json_encode( $retArr ) . ');';
141
142    }
143    echo '</div>';
144    echo '<script type="text/javascript">' . $scriptVer . '</script>';
145}
146
147    #} Start a global timer :)
148    zeroBSCRM_performanceTest_startTimer( 'postinc' );
149
150    // ====================================================================
151    // ==================== General Perf Testing ==========================
152function zeroBSCRM_performanceTest_closeGlobalTest( $key = '' ) {
153
154    if ( defined( 'ZBSPERFTEST' ) ) {
155        if ( ! empty( $key ) ) {
156
157            // retrieve our global (may have had any number of test res added)
158            global $zbsPerfTest;
159
160            // finish timer
161            zeroBSCRM_performanceTest_finishTimer( $key );
162
163            // store in perf-reports
164            $zbsPerfTest['results'][ $key ] = zeroBSCRM_performanceTest_results( $key );
165
166        }
167    }
168}
169
170    /*
171    This got abbreviated with above:
172
173
174        // ====================================================================
175        // ==================== General Perf Testing ==========================
176        if (defined('ZBSPERFTEST')) {
177
178            // retrieve our global (may have had any number of test res added)
179            global $zbsPerfTest;
180
181            // start timer (will need a 'catch + add' for this at end of whatever this is timing)
182                zeroBSCRM_performanceTest_startTimer('includes');
183
184        }
185        // =================== / General Perf Testing =========================
186        // ====================================================================
187
188
189        // ====================================================================
190        // ==================== General Perf Testing ==========================
191        if (defined('ZBSPERFTEST')) {
192
193            // finish timer
194            zeroBSCRM_performanceTest_finishTimer('includes');
195
196            // store in perf-reports
197            $zbsPerfTest['results']['includes'] = zeroBSCRM_performanceTest_results('includes');
198
199        }
200        // =================== / General Perf Testing =========================
201        // ====================================================================
202
203
204
205
206        // ====================================================================
207        // ==================== General Perf Testing ==========================
208        if (defined('ZBSPERFTEST')) zeroBSCRM_performanceTest_startTimer('includes');
209        // =================== / General Perf Testing =========================
210        // ====================================================================
211
212
213        // ====================================================================
214        // ==================== General Perf Testing ==========================
215        if (defined('ZBSPERFTEST')) zeroBSCRM_performanceTest_closeGlobalTest('key');
216        // =================== / General Perf Testing =========================
217        // ====================================================================
218
219
220    */