-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathLogsInjectionBench.php
123 lines (110 loc) · 3.05 KB
/
LogsInjectionBench.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
declare(strict_types=1);
namespace Benchmarks\Integrations;
use DDTrace\Tests\Common\Utils;
use DDTrace\Tracer;
use Monolog\Logger;
use Psr\Log\NullLogger;
class LogsInjectionBench
{
public $logger;
public $tracer;
/**
* @BeforeMethods("disableLogsInjection")
* @Revs(1000)
* @Iterations(10)
* @OutputTimeUnit("microseconds")
* @RetryThreshold(10.0)
* @Warmup(1)
*/
public function benchLogsInfoBaseline()
{
$this->logger->info('not injecting logs');
}
/**
* @BeforeMethods({"enableLogsInjection"})
* @Revs(1000)
* @Iterations(10)
* @OutputTimeUnit("microseconds")
* @RetryThreshold(10.0)
* @Warmup(1)
*/
public function benchLogsInfoInjection()
{
$this->logger->info('injecting logs');
}
/**
* @BeforeMethods("disableLogsInjectionNullLogger")
* @Revs(100)
* @Iterations(10)
* @OutputTimeUnit("microseconds")
* @RetryThreshold(10.0)
* @Warmup(1)
*/
public function benchLogsNullBaseline()
{
for ($i = 0; $i < 1000; $i++) {
$this->logger->log("debug", 'not injecting logs');
}
}
/**
* @BeforeMethods({"enableLogsInjectionNullLogger"})
* @Revs(100)
* @Iterations(10)
* @OutputTimeUnit("microseconds")
* @RetryThreshold(10.0)
* @Warmup(1)
*/
public function benchLogsNullInjection()
{
for ($i = 0; $i < 1000; $i++) {
$this->logger->log("debug", 'injecting logs');
}
}
public function enableLogsInjection()
{
\dd_trace_serialize_closed_spans();
Utils::putEnvAndReloadConfig([
'DD_TRACE_APPEND_TRACE_IDS_TO_LOGS=0',
'DD_ENV=my-env',
'DD_SERVICE=my-service',
'DD_VERSION=4.2',
'DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED=1',
'DD_LOGS_INJECTION=1',
]);
$tracer = new Tracer();
$this->tracer = $tracer;
\dd_trace_serialize_closed_spans();
\DDTrace\start_span();
$logger = new Logger('test');
$noopHandler = new \Monolog\Handler\NoopHandler();
$logger->pushHandler($noopHandler);
$this->logger = $logger;
}
public function enableLogsInjectionNullLogger()
{
$this->enableLogsInjection();
$this->logger = new NullLogger();
}
public function disableLogsInjectionNullLogger()
{
$this->disableLogsInjection();
$this->logger = new NullLogger();
}
public function disableLogsInjection()
{
\dd_trace_serialize_closed_spans();
Utils::putEnvAndReloadConfig([
'DD_TRACE_APPEND_TRACE_IDS_TO_LOGS=0',
'DD_ENV=my-env',
'DD_SERVICE=my-service',
'DD_VERSION=4.2',
'DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED=1',
'DD_LOGS_INJECTION=0',
]);
$logger = new Logger('test');
$noopHandler = new \Monolog\Handler\NoopHandler();
$logger->pushHandler($noopHandler);
$this->logger = $logger;
}
}