@@ -37,6 +37,7 @@ final class Processor
3737 public function __construct (
3838 private readonly int $ interval ,
3939 private readonly int $ batchLimit ,
40+ private readonly TraceAggregatorAbstract $ aggregator ,
4041 private readonly SampleSenderInterface $ sender ,
4142 private readonly array $ plugins ,
4243 int $ sendSampleFutureLimit ,
@@ -52,7 +53,7 @@ public function __construct(
5253
5354 private function init (): void
5455 {
55- $ this ->results = [] ;
56+ $ this ->aggregator -> clear () ;
5657 $ this ->tsStart = time ();
5758 $ this ->tsEnd = $ this ->tsStart + $ this ->interval ;
5859 }
@@ -103,15 +104,15 @@ private function runProducer(): Future
103104 }
104105
105106 $ key = self ::stringifyTrace ($ tracePrepared );
106- $ this ->groupTrace ($ tags , $ key );
107+ $ this ->aggregator -> addTrace ($ tags , $ key );
107108
108109 $ currentTime = time ();
109110
110- if ($ currentTime < $ this ->tsEnd && $ this ->countResults () < $ this ->batchLimit ) {
111+ if ($ currentTime < $ this ->tsEnd && $ this ->aggregator -> countGrouppedTraces () < $ this ->batchLimit ) {
111112 continue ;
112113 }
113114
114- foreach ($ this ->results as $ tagSerialized => $ results ) {
115+ foreach ($ this ->aggregator -> getGrouppedTraces () as $ tagSerialized => $ results ) {
115116 $ this ->queue ->push (new Sample ($ this ->tsStart , $ currentTime , $ results , unserialize ($ tagSerialized )));
116117 }
117118
@@ -123,7 +124,7 @@ private function runProducer(): Future
123124 }
124125
125126 $ currentTime = time ();
126- foreach ($ this ->results as $ tagSerialized => $ results ) {
127+ foreach ($ this ->aggregator -> getGrouppedTraces () as $ tagSerialized => $ results ) {
127128 $ this ->queue ->push (new Sample ($ this ->tsStart , $ currentTime , $ results , unserialize ($ tagSerialized )));
128129 }
129130
@@ -184,7 +185,19 @@ private static function extractTags(array $sample): array
184185 if (count ($ item ) !== 4 ) {
185186 continue ;
186187 }
188+
189+ //# uri = /stat.php
187190 [$ hashtag , $ tag , $ equalsign , $ value ] = $ item ;
191+
192+ if ($ tag === 'ts ' ) {
193+ continue ;
194+ }
195+ if ($ tag === 'mem ' ) {
196+ // # mem 1653800 1659424
197+ [$ hashtag , $ tag , $ value , $ maxUsage ] = $ item ;
198+ $ value = (int ) $ value ;
199+ }
200+
188201 $ tags [$ tag ] = $ value ;
189202 }
190203 return $ tags ;
@@ -236,32 +249,6 @@ private function getLine(): Generator
236249 }
237250 }
238251
239- /**
240- * @param TagsArray $tags
241- * @param string $key
242- */
243- private function groupTrace (array $ tags , string $ key ): void
244- {
245- ksort ($ tags );
246- $ tagsKey = serialize ($ tags );
247- if (!array_key_exists ($ tagsKey , $ this ->results )) {
248- $ this ->results [$ tagsKey ] = [];
249- }
250- if (!array_key_exists ($ key , $ this ->results [$ tagsKey ])) {
251- $ this ->results [$ tagsKey ][$ key ] = 0 ;
252- }
253- $ this ->results [$ tagsKey ][$ key ]++;
254- }
255-
256- private function countResults (): int
257- {
258- $ count = 0 ;
259- foreach ($ this ->results as $ tagResuts ) {
260- $ count += count ($ tagResuts );
261- }
262- return $ count ;
263- }
264-
265252 private static function fixEvalLine (string $ line ): string
266253 {
267254
0 commit comments