@@ -17,6 +17,9 @@ final class PinbaClient extends Singleton
17
17
{
18
18
private static $ enabled = null ;
19
19
private $ timers = array ();
20
+ private $ queue = array ();
21
+ private $ treeLogEnabled = false ;
22
+
20
23
21
24
/**
22
25
* @return PinbaClient
@@ -34,11 +37,36 @@ public static function isEnabled()
34
37
return self ::$ enabled ;
35
38
}
36
39
40
+ public function setTreeLogEnabled ($ orly = true )
41
+ {
42
+ $ this ->treeLogEnabled = ($ orly === true );
43
+
44
+ return $ this ;
45
+ }
46
+
47
+ public function isTreeLogEnabled ()
48
+ {
49
+ return $ this ->treeLogEnabled ;
50
+ }
51
+
37
52
public function timerStart ($ name , array $ tags , array $ data = array ())
38
53
{
39
54
if (array_key_exists ($ name , $ this ->timers ))
40
55
throw new WrongArgumentException ('a timer with the same name allready exists ' );
41
56
57
+ if ($ this ->isTreeLogEnabeled ()) {
58
+
59
+ $ id = uniqid ();
60
+ $ tags ['treeId ' ] = $ id ;
61
+
62
+ if (!empty ($ this ->queue ))
63
+ list ($ tags ['treeParentId ' ]) = end ($ this ->queue );
64
+ else
65
+ $ tags ['treeParentId ' ] = 'root ' ;
66
+
67
+ $ this ->queue [] = $ id ;
68
+ }
69
+
42
70
$ this ->timers [$ name ] =
43
71
count ($ data )
44
72
? pinba_timer_start ($ tags , $ data )
@@ -49,6 +77,9 @@ public function timerStart($name, array $tags, array $data = array())
49
77
50
78
public function timerStop ($ name )
51
79
{
80
+ if ($ this ->isTreeLogEnabeled ())
81
+ array_pop ($ this ->queue );
82
+
52
83
if (!array_key_exists ($ name , $ this ->timers ))
53
84
throw new WrongArgumentException ('have no any timer with name ' .$ name );
54
85
0 commit comments