Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
9 | public function collect(array $params = []) |
||
10 | { |
||
11 | // Worker Memory Stats |
||
12 | $labels = http_build_query([ |
||
13 | 'process_id' => $params['process_id'], |
||
14 | 'process_type' => $params['process_type'], |
||
15 | ]); |
||
16 | |||
17 | // Memory Usage |
||
18 | $memoryMetrics = [ |
||
19 | [ |
||
20 | 'name' => 'swoole_process_memory_usage', |
||
21 | 'type' => 'gauge', |
||
22 | 'value' => memory_get_usage(), |
||
23 | ], |
||
24 | [ |
||
25 | 'name' => 'swoole_process_memory_real_usage', |
||
26 | 'type' => 'gauge', |
||
27 | 'value' => memory_get_usage(true), |
||
28 | ], |
||
29 | ]; |
||
30 | |||
31 | // GC Status |
||
32 | $gcMetrics = []; |
||
33 | if (PHP_VERSION_ID >= 70300) { |
||
34 | $gcStatus = gc_status(); |
||
35 | $gcMetrics = [ |
||
36 | [ |
||
37 | 'name' => 'swoole_process_gc_runs', |
||
38 | 'type' => 'gauge', |
||
39 | 'value' => $gcStatus['runs'], |
||
40 | ], |
||
41 | [ |
||
42 | 'name' => 'swoole_process_gc_collected', |
||
43 | 'type' => 'gauge', |
||
44 | 'value' => $gcStatus['collected'], |
||
45 | ], |
||
46 | [ |
||
47 | 'name' => 'swoole_process_gc_threshold', |
||
48 | 'type' => 'gauge', |
||
49 | 'value' => $gcStatus['threshold'], |
||
50 | ], |
||
51 | [ |
||
52 | 'name' => 'swoole_process_gc_roots', |
||
53 | 'type' => 'gauge', |
||
54 | 'value' => $gcStatus['roots'], |
||
55 | ], |
||
56 | ]; |
||
57 | } |
||
58 | $apcuKey = implode($this->config['apcu_key_separator'], [$this->config['apcu_key_prefix'], 'swoole_process_stats', '', $labels]); |
||
59 | apcu_store($apcuKey, array_merge($memoryMetrics, $gcMetrics), $this->config['apcu_key_max_age']); |
||
60 | } |
||
61 | } |