summaryrefslogtreecommitdiffstatshomepage
path: root/core/tests/Drupal/Tests/PerformanceData.php
blob: a2f7bdd9718e0f0ea44a110c3b3838630a2b1ef9 (plain) (blame)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php

declare(strict_types=1);

namespace Drupal\Tests;

/**
 * Value object to store performance information collected from requests.
 *
 * @see \Drupal\Tests\PerformanceTestTrait::collectPerformanceData().
 */
class PerformanceData {

  /**
   * The number of stylesheets requested.
   */
  protected int $stylesheetCount = 0;

  /**
   * The number of scripts requested.
   */
  protected int $scriptCount = 0;

  /**
   * The total stylesheet bytes requested.
   */
  protected int $stylesheetBytes = 0;

  /**
   * The total script bytes requested.
   */
  protected int $scriptBytes = 0;

  /**
   * The number of database queries recorded.
   */
  protected int $queryCount = 0;

  /**
   * The individual database queries recorded.
   */
  protected array $queries = [];

  /**
   * The number of cache gets recorded.
   */
  protected int $cacheGetCount = 0;

  /**
   * The number of cache sets recorded.
   */
  protected int $cacheSetCount = 0;

  /**
   * The number of cache deletes recorded.
   */
  protected int $cacheDeleteCount = 0;

  /**
   * List of cids keyed by operation and bin.
   *
   * @var string[][]
   */
  protected array $cacheOperations = [];

  /**
   * The number of cache tag checksum checks.
   */
  protected int $cacheTagChecksumCount = 0;

  /**
   * The number of cache tag validity checks.
   */
  protected int $cacheTagIsValidCount = 0;

  /**
   * The number of cache tag invalidations.
   */
  protected int $cacheTagInvalidationCount = 0;

  /**
   * The grouped cache tag lookups.
   *
   * @var string[]
   */
  protected array $cacheTagGroupedLookups = [];

  /**
   * The original return value.
   *
   * @var mixed
   */
  protected $returnValue;

  /**
   * Sets the stylesheet request count.
   *
   * @param int $count
   *   The number of stylesheet requests recorded.
   */
  public function setStylesheetCount(int $count): void {
    $this->stylesheetCount = $count;
  }

  /**
   * Sets the stylesheet bytes.
   *
   * @param int $bytes
   *   The stylesheet bytes recorded.
   */
  public function setStylesheetBytes(int $bytes): void {
    $this->stylesheetBytes = $bytes;
  }

  /**
   * Gets the stylesheet request count.
   *
   * @return int
   *   The number of stylesheet requests recorded.
   */
  public function getStylesheetCount(): int {
    return $this->stylesheetCount;
  }

  /**
   * Gets the stylesheet bytes count.
   *
   * @return int
   *   The stylesheet bytes recorded.
   */
  public function getStylesheetBytes(): int {
    return $this->stylesheetBytes;
  }

  /**
   * Sets the script request count.
   *
   * @param int $count
   *   The number of script requests recorded.
   */
  public function setScriptCount(int $count) {
    $this->scriptCount = $count;
  }

  /**
   * Sets the script bytes.
   *
   * @param int $bytes
   *   The script bytes recorded.
   */
  public function setScriptBytes(int $bytes): void {
    $this->scriptBytes = $bytes;
  }

  /**
   * Gets the script request count.
   *
   * @return int
   *   The number of script requests recorded.
   */
  public function getScriptCount(): int {
    return $this->scriptCount;
  }

  /**
   * Gets the script bytes count.
   *
   * @return int
   *   The script bytes recorded.
   */
  public function getScriptBytes(): int {
    return $this->scriptBytes;
  }

  /**
   * Logs a database query.
   *
   * @param string $query
   *   The database query recorded.
   */
  public function logQuery(string $query): void {
    $this->queries[] = $query;
    $this->queryCount++;
  }

  /**
   * Gets the queries.
   *
   * @return string[]
   *   The database queries recorded.
   */
  public function getQueries(): array {
    return $this->queries;
  }

  /**
   * Gets the query count.
   *
   * @return int
   *   The number of database queries recorded.
   */
  public function getQueryCount(): int {
    return $this->queryCount;
  }

  /**
   * Sets the cache get count.
   *
   * @param int $count
   *   The number of cache gets recorded.
   */
  public function setCacheGetCount(int $count): void {
    $this->cacheGetCount = $count;
  }

  /**
   * Gets the cache get count.
   *
   * @return int
   *   The number of cache gets recorded.
   */
  public function getCacheGetCount(): int {
    return $this->cacheGetCount;
  }

  /**
   * Sets the cache operations.
   *
   * @param string[][] $cacheOperations
   *   List of cids keyed by operation and bin.
   *
   * @return void
   *   No return value.
   */
  public function setCacheOperations(array $cacheOperations): void {
    $this->cacheOperations = $cacheOperations;
  }

  /**
   * Gets the cache operations.
   *
   * @return string[][]
   *   List of cids keyed by operation and bin.
   */
  public function getCacheOperations(): array {
    return $this->cacheOperations;
  }

  /**
   * Returns the cache get operation count grouped by bin.
   *
   * @return int[]
   *   Count of cache get operations keyed by bin.
   */
  public function getCacheGetCountByBin(): array {
    return array_map(fn (array $cids) => count($cids), $this->cacheOperations['get'] ?? []);
  }

  /**
   * Returns the cache set operation count grouped by bin.
   *
   * @return int[]
   *   Count of cache set operations keyed by bin.
   */
  public function getCacheSetCountByBin(): array {
    return array_map(fn (array $cids) => count($cids), $this->cacheOperations['set'] ?? []);
  }

  /**
   * Returns the cache delete operation count grouped by bin.
   *
   * @return int[]
   *   Count of cache delete operations keyed by bin.
   */
  public function getCacheDeleteCountByBin(): array {
    return array_map(fn (array $cids) => count($cids), $this->cacheOperations['delete'] ?? []);
  }

  /**
   * Sets the cache set count.
   *
   * @param int $count
   *   The number of cache sets recorded.
   */
  public function setCacheSetCount(int $count): void {
    $this->cacheSetCount = $count;
  }

  /**
   * Gets the cache set count.
   *
   * @return int
   *   The number of cache sets recorded.
   */
  public function getCacheSetCount(): int {
    return $this->cacheSetCount;
  }

  /**
   * Sets the cache delete count.
   *
   * @param int $count
   *   The number of cache deletes recorded.
   */
  public function setCacheDeleteCount(int $count): void {
    $this->cacheDeleteCount = $count;
  }

  /**
   * Gets the cache delete count.
   *
   * @return int
   *   The number of cache deletes recorded.
   */
  public function getCacheDeleteCount(): int {
    return $this->cacheDeleteCount;
  }

  /**
   * Sets the cache tag checksum count.
   *
   * @param int $count
   *   The number of cache tag checksum checks recorded.
   */
  public function setCacheTagChecksumCount(int $count): void {
    $this->cacheTagChecksumCount = $count;
  }

  /**
   * Gets the cache tag checksum count.
   *
   * @return int
   *   The number of cache tag checksum checks recorded.
   *
   * @deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is
   *   no direct replacement.
   *
   * @see https://www.drupal.org/node/3511149
   */
  public function getCacheTagChecksumCount(): int {
    @trigger_error(__METHOD__ . 'is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3511149', E_DEPRECATED);

    return $this->cacheTagChecksumCount;
  }

  /**
   * Sets the cache tag isValid count.
   *
   * @param int $count
   *   The number of cache tag isValid checks recorded.
   */
  public function setCacheTagIsValidCount(int $count): void {
    $this->cacheTagIsValidCount = $count;
  }

  /**
   * Gets the cache tag isValid count.
   *
   * @return int
   *   The number of cache tag isValid checks recorded.
   *
   * @deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is
   * no direct replacement.
   *
   * @see https://www.drupal.org/node/3511149
   */
  public function getCacheTagIsValidCount(): int {
    @trigger_error(__METHOD__ . 'is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3511149', E_DEPRECATED);
    return $this->cacheTagIsValidCount;
  }

  /**
   * Sets the cache tag invalidation count.
   *
   * @param int $count
   *   The number of cache tag invalidations recorded.
   */
  public function setCacheTagInvalidationCount(int $count): void {
    $this->cacheTagInvalidationCount = $count;
  }

  /**
   * Gets the cache tag invalidation count.
   *
   * @return int
   *   The number of cache tag invalidations recorded.
   */
  public function getCacheTagInvalidationCount(): int {
    return $this->cacheTagInvalidationCount;
  }

  /**
   * Sets the grouped cache tag lookups.
   *
   * @param string[] $groupedLookups
   *   Grouped cache tag lookups by query.
   */
  public function setCacheTagGroupedLookups(array $groupedLookups): void {
    $this->cacheTagGroupedLookups = $groupedLookups;
  }

  /**
   * Gets the grouped cache tag lookups.
   *
   * @@return string[]
   *   Grouped cache tag lookups by query.
   */
  public function getCacheTagGroupedLookups(): array {
    return $this->cacheTagGroupedLookups;
  }

  /**
   * Gets the cache tag lookup query count.
   *
   * @return int
   *   The number of cache tag lookup queries recorded.
   */
  public function getCacheTagLookupQueryCount(): int {
    return count($this->cacheTagGroupedLookups);
  }

  /**
   * Sets the original return value.
   *
   * @param mixed $return
   *   The original return value.
   */
  public function setReturnValue($return): void {
    $this->returnValue = $return;
  }

  /**
   * Gets the original return value.
   *
   * PerformanceTestTrait::collectPerformanceData() takes a callable as its
   * argument. This method allows the original return value of the callable to
   * be retrieved.
   *
   * @return mixed
   *   The original return value.
   */
  public function getReturnValue() {
    return $this->returnValue;
  }

}