• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 624

pending completion
624

push

travis-ci-com

NathanGibbs3
Merge branch 'devel'

562 of 562 new or added lines in 28 files covered. (100.0%)

3145 of 17504 relevant lines covered (17.97%)

23.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.92
/includes/base_log_timing.inc.php
1
<?php
2
// Basic Analysis and Security Engine (BASE)
3
// Copyright (C) 2019-2023 Nathan Gibbs
4
// Copyright (C) 2004 BASE Project Team
5
// Copyright (C) 2000 Carnegie Mellon University
6
//
7
//   For license info: See the file 'base_main.php'
8
//
9
//       Project Lead: Nathan Gibbs
10
// Built upon work by: Kevin Johnson & the BASE Project Team
11
//                     Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
//
13
//            Purpose: Generates timing information
14
//
15
//          Author(s): Nathan Gibbs
16
//                     Kevin Johnson
17
// Ensure the conf file has been loaded.  Prevent direct access to this file.
18
defined('_BASE_INC') or die('Accessing this file directly is not allowed.');
19

20
class EventTiming {
21
        var $start_time;
22
        var $num_events;
23
        var $event_log;
24
        var $verbose;
25

26
        function __construct( $verbose ){ // PHP 5+ constructor Shim.
27
                // Class/Method agnostic shim code.
28
                $SCname = get_class();
82✔
29
                if ( method_exists($this, $SCname) ){
82✔
30
                        $SCargs = func_get_args();
82✔
31
                        call_user_func_array(array($this, $SCname), $SCargs);
82✔
32
                }else{
26✔
33
                        // @codeCoverageIgnoreStart
34
                        // Should never execute.
35
                        trigger_error( // Will need to add this message to the TD.
36
                                "Class: $SCname No Legacy Constructor.\n",
37
                                E_USER_ERROR
38
                        );
39
                        // @codeCoverageIgnoreEnd
40
                }
41
        }
58✔
42

43
        function EventTiming( $verbose ){ // PHP 4x constructor.
44
                GLOBAL $BCR;
58✔
45
                $this->num_events = 0;
82✔
46
                $this->verbose = $verbose;
82✔
47
                $this->start_time = time();
82✔
48
                // Tie in to capabilities Registry.
49
                if ( isset($BCR) && is_object($BCR) ){
82✔
50
                        $tmp = 'BASE Kernel: ' . $BCR->GetCap('BASE_Kernel')
×
51
                        . ' Initialized. Runtime: ' . $BCR->GetCap('BASE_RTL');
×
52
                }else{
53
                        $tmp = 'Page Load';
82✔
54
                }
55
                $this->Mark("$tmp.");
82✔
56
        }
58✔
57
        function Mark( $desc = '' ){
58
                if ( !LoadedString($desc) ){
126✔
59
                        $desc = 'MARK';
22✔
60
                }
8✔
61
                $this->event_log[$this->num_events++] = array ( time(), $desc );
126✔
62
        }
90✔
63

64
        function PrintTiming(){
65
                if ( $this->verbose > 0 ){
82✔
66
                        $ttime = $this->start_time;
60✔
67
                        $rt = time() - $ttime;
60✔
68
                        $ESfx = '</span>';
60✔
69
                        $Sfx = ' '._SECONDS.']<br/>';
60✔
70
                        $tmp = $this->Classify($rt);
60✔
71
                        NLIO('<!-- Timing Information -->', 6);
60✔
72
                        NLIO("<div class='systemdebug'>", 6);
60✔
73
                        NLIO($tmp . _LOADEDIN . "$ESfx [$rt$Sfx", 7);
60✔
74
                        if ( $this->verbose > 1 ){
60✔
75
                                NLIO ('Event Log:<br/>', 7);
20✔
76
                                for ( $i = 0; $i < $this->num_events; $i++ ){
20✔
77
                                        $ct = $i + 1;
20✔
78
                                        if ( $i != 0 ){
20✔
79
                                                $ttime = $this->event_log[$i-1][0];
20✔
80
                                        }
6✔
81
                                        $ttime = $this->event_log[$i][0] - $ttime;
20✔
82
                                        $tmp = $this->Classify($ttime)
20✔
83
                                        . $this->event_log[$i][1] . $ESfx;
20✔
84
                                        NLIO("$ct $tmp [$ttime$Sfx", 7);
20✔
85
                                }
6✔
86
                        }
6✔
87
                        NLIO ('</div>', 6);
60✔
88
                }
18✔
89
        }
58✔
90

91
        function Classify( $Time ){
92
                $Ret = '';
82✔
93
                if ( is_int($Time) ){
82✔
94
                        $Ret = '<span';
82✔
95
                        $clr = '';
82✔
96
                        if ( $Time > 59 ){
82✔
97
                                $clr = 'red';
22✔
98
                        }elseif( $Time > 29 ){
82✔
99
                                $clr = 'yellow';
22✔
100
                        }elseif( $Time == 0 ){
82✔
101
                                $clr = 'green';
82✔
102
                        }
26✔
103
                        if ( LoadedString($clr) ){
82✔
104
                                $Ret .= " style='color: $clr;'";
82✔
105
                        }
26✔
106
                        $Ret .= '>';
82✔
107
                }
26✔
108
                return $Ret;
82✔
109
        }
110

111
}
112
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc