1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
measure.php
См. документацию.
1<?php
2
4
6
8{
9 protected static function noOp(&$k)
10 {
11 }
12
13 protected static function oneOp(&$k)
14 {
15 $k++;
16 $k--;
17 $k++;
18 $k--;
19 }
20
21 public static function GetPHPCPUMark()
22 {
23 $k = 0;
24 $res = [];
25 for ($j = 0; $j < 4; $j++)
26 {
27 $m1 = microtime(true);
28 for ($i = 0; $i < 100000; $i++)
29 {
30 static::noOp($k);
31 }
32
33 $m2 = microtime(true);
34 for ($i = 0; $i < 100000; $i++)
35 {
36 static::oneOp($k);
37 }
38
39 $m3 = microtime(true);
40 if ($m1 <= $m2 && $m2 <= $m3)
41 {
42 $N1 = $m2 - $m1;
43 $N2 = $m3 - $m2;
44
45 if ($N2 > $N1)
46 {
47 $res[] = 1 / ($N2 - $N1);
48 }
49 }
50 }
51
52 if (count($res))
53 {
54 return array_sum($res) / doubleval(count($res));
55 }
56
57 return 0;
58 }
59
60 public static function GetPHPFilesMark()
61 {
62 $res = [];
63 $file_name = $_SERVER['DOCUMENT_ROOT'] . '/' . \Bitrix\Main\Config\Option::get('main', 'upload_dir', '/upload/') . '/perfmon#i#.php';
64 $content = "<?\$s='" . str_repeat('x', 1024) . "';?><?/*" . str_repeat('y', 1024) . "*/?><?\$r='" . str_repeat('z', 1024) . "';?>";
65
66 for ($j = 0; $j < 4; $j++)
67 {
68 $s1 = microtime(true);
69 for ($i = 0; $i < 100; $i++)
70 {
71 $fn = str_replace('#i#', $i, $file_name);
72 }
73 $e1 = microtime(true);
74 $N1 = $e1 - $s1;
75
76 $s2 = microtime(true);
77 for ($i = 0; $i < 100; $i++)
78 {
79 //This is one op
80 $fn = str_replace('#i#', $i, $file_name);
81 $fh = fopen($fn, 'wb');
82 fwrite($fh, $content);
83 fclose($fh);
84 include $fn;
85 unlink($fn);
86 }
87 $e2 = microtime(true);
88 $N2 = $e2 - $s2;
89
90 if ($N2 > $N1)
91 {
92 $res[] = 100 / ($N2 - $N1);
93 }
94 }
95
96 if (count($res))
97 {
98 return array_sum($res) / doubleval(count($res));
99 }
100
101 return 0;
102 }
103
104 public static function GetPHPMailMark()
105 {
106 $addr = 'hosting_test@bitrix.ru';
107 $subj = 'Bitrix server test';
108 $body = 'This is test message. Delete it.';
109
110 $s1 = microtime(true);
111 bxmail($addr, $subj, $body);
112 $e1 = microtime(true);
113
114 return $e1 - $s1;
115 }
116
117 public static function GetDBMark($type)
118 {
119 global $DB;
120
121 $res = [];
122 switch ($type)
123 {
124 case 'read':
125 $strSql = 'select * from b_perf_test WHERE ID = #i#';
126 $bFetch = true;
127 break;
128 case 'update':
129 $strSql = "update b_perf_test set REFERENCE_ID = ID+1, NAME = '" . str_repeat('y', 200) . "' WHERE ID = #i#";
130 $bFetch = false;
131 break;
132 default:
133 $DB->Query('truncate table b_perf_test');
134 $strSql = "insert into b_perf_test (REFERENCE_ID, NAME) values (#i#-1, '" . str_repeat('x', 200) . "')";
135 $bFetch = false;
136 }
137
138 for ($j = 0; $j < 4; $j++)
139 {
140 $s1 = microtime(true);
141 for ($i = 0; $i < 100; $i++)
142 {
143 $sql = str_replace('#i#', $i, $strSql);
144 }
145 $e1 = microtime(true);
146 $N1 = $e1 - $s1;
147
148 $s2 = microtime(true);
149 for ($i = 0; $i < 100; $i++)
150 {
151 //This is one op
152 $sql = str_replace('#i#', $i, $strSql);
153 $rs = $DB->Query($sql);
154 if ($bFetch)
155 {
156 $rs->Fetch();
157 }
158 }
159 $e2 = microtime(true);
160 $N2 = $e2 - $s2;
161
162 if ($N2 > $N1)
163 {
164 $res[] = 100 / ($N2 - $N1);
165 }
166 }
167
168 if (count($res))
169 {
170 return array_sum($res) / doubleval(count($res));
171 }
172 }
173
174 public static function GetAccelerator()
175 {
176 $accelerators = self::GetAllAccelerators();
177 if ($accelerators)
178 {
179 return $accelerators[0];
180 }
181
182 return false;
183 }
184
185 public static function GetAllAccelerators()
186 {
187 $result = [];
188 if (extension_loaded('Zend OPcache'))
189 {
191 }
192
193 return $result;
194 }
195}
196
198{
199 public $enabled;
206
208 {
209 $this->enabled = $enabled;
210 $this->cache_ttl = $cache_ttl;
211 $this->max_file_size = $max_file_size;
212 $this->check_mtime = $check_mtime;
213 $this->memory_total = $memory_total;
214 $this->memory_used = $memory_used;
215 $this->cache_limit = $cache_limit;
216 }
217
218 public function GetParams()
219 {
220 return [];
221 }
222
223 public function IsWorking()
224 {
225 if (!$this->enabled)
226 {
227 return false;
228 }
229
230 if ($this->cache_ttl == 0)
231 {
232 return false;
233 }
234
235 if ($this->max_file_size >= 0)
236 {
237 if ($this->max_file_size < 4 * 1024 * 1024)
238 {
239 return false;
240 }
241 }
242
243 if (!$this->check_mtime)
244 {
245 return false;
246 }
247
248 if ($this->memory_used >= 0)
249 {
250 //Check for 10% free
251 if (($this->memory_used / $this->memory_total) > 0.9)
252 {
253 return false;
254 }
255 }
256 else
257 {
258 //Or at least 40M total when no used memory stat available
259 if ($this->memory_total < 40 * 1024 * 1024)
260 {
261 return false;
262 }
263 }
264
265 if ($this->cache_limit == 0)
266 {
267 return false;
268 }
269
270 return true;
271 }
272
273 public function GetRecommendations()
274 {
275 $arResult = [];
276 $arParams = $this->GetParams();
277
278 if (array_key_exists('enabled', $arParams))
279 {
280 $is_ok = $this->enabled;
281 foreach ($arParams['enabled'] as $ar)
282 {
283 if (!isset($ar['IS_OK']))
284 {
285 $ar['IS_OK'] = $is_ok;
286 }
287 $arResult[] = $ar;
288 }
289 }
290
291 if (array_key_exists('cache_ttl', $arParams))
292 {
293 $is_ok = $this->cache_ttl != 0;
294 foreach ($arParams['cache_ttl'] as $ar)
295 {
296 if (!isset($ar['IS_OK']))
297 {
298 $ar['IS_OK'] = $is_ok;
299 }
300 $arResult[] = $ar;
301 }
302 }
303
304 if (array_key_exists('max_file_size', $arParams) && $this->max_file_size >= 0)
305 {
306 $is_ok = $this->max_file_size >= 4 * 1024 * 1024;
307 foreach ($arParams['max_file_size'] as $ar)
308 {
309 if (!isset($ar['IS_OK']))
310 {
311 $ar['IS_OK'] = $is_ok;
312 }
313 $arResult[] = $ar;
314 }
315 }
316
317 if (array_key_exists('check_mtime', $arParams))
318 {
319 $is_ok = $this->check_mtime;
320 foreach ($arParams['check_mtime'] as $ar)
321 {
322 if (!isset($ar['IS_OK']))
323 {
324 $ar['IS_OK'] = $is_ok;
325 }
326 $arResult[] = $ar;
327 }
328 }
329
330 if (array_key_exists('memory_pct', $arParams) && $this->memory_used >= 0)
331 {
332 if ($this->memory_total > 0)
333 {
334 //Check for 10% free
335 $is_ok = ($this->memory_used / $this->memory_total) <= 0.9;
336 foreach ($arParams['memory_pct'] as $ar)
337 {
338 $arResult[] = [
339 'PARAMETER' => $ar['PARAMETER'],
340 'VALUE' => Loc::getMessage(
341 'PERFMON_MEASURE_MEMORY_USAGE',
342 ['#percent#' => number_format(($this->memory_used / $this->memory_total) * 100, 2)]
343 ),
344 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_CACHE_REC'),
345 'IS_OK' => $is_ok,
346 ];
347 }
348 }
349 else
350 {
351 foreach ($arParams['memory_pct'] as $ar)
352 {
353 $arResult[] = [
354 'PARAMETER' => $ar['PARAMETER'],
355 'VALUE' => '',
356 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_GREATER_THAN_ZERO_REC'),
357 'IS_OK' => false,
358 ];
359 }
360 }
361 }
362 elseif (array_key_exists('memory_abs', $arParams))
363 {
364 //Or at least 40M total when no used memory stat available
365 $is_ok = $this->memory_total >= 40 * 1024 * 1024;
366 foreach ($arParams['memory_abs'] as $ar)
367 {
368 if (!isset($ar['IS_OK']))
369 {
370 $ar['IS_OK'] = $is_ok;
371 }
372 $arResult[] = $ar;
373 }
374 }
375
376 if (array_key_exists('cache_limit', $arParams))
377 {
378 $is_ok = $this->cache_limit != 0;
379 foreach ($arParams['cache_limit'] as $ar)
380 {
381 if (!isset($ar['IS_OK']))
382 {
383 $ar['IS_OK'] = $is_ok;
384 }
385 $arResult[] = $ar;
386 }
387 }
388
389 return $arResult;
390 }
391
392 public static function unformat($str)
393 {
394 $str = mb_strtolower($str);
395 $res = intval($str);
396 $suffix = mb_substr($str, -1);
397 if ($suffix === 'k')
398 {
399 $res *= 1024;
400 }
401 elseif ($suffix === 'm')
402 {
403 $res *= 1048576;
404 }
405 elseif ($suffix === 'g')
406 {
407 $res *= 1048576 * 1024;
408 }
409
410 return $res;
411 }
412}
413
415{
416 public function __construct()
417 {
418 $memory = [
419 'memorySize' => intval(ini_get('opcache.memory_consumption')) * 1024 * 1024,
420 'memoryAllocated' => -1,
421 ];
422
423 parent::__construct(
424 ini_get('opcache.enable') != '0',
425 -1,
426 -1,
427 ini_get('opcache.validate_timestamps') != '0',
428 $memory['memorySize'],
429 $memory['memoryAllocated'],
430 -1
431 );
432 }
433
434 public function GetRecommendations()
435 {
436 $arResult = parent::GetRecommendations();
437
438 if (extension_loaded('Zend OPcache'))
439 {
440 $max_accelerated_files = intval(ini_get('opcache.max_accelerated_files'));
441 $rec_accelerated_files = 100000;
442 $is_ok = ($max_accelerated_files >= $rec_accelerated_files);
443
444 array_unshift($arResult, [
445 'PARAMETER' => 'opcache.max_accelerated_files',
446 'IS_OK' => $is_ok,
447 'VALUE' => $max_accelerated_files,
448 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_EQUAL_OR_GREATER_THAN_REC', ['#value#' => $rec_accelerated_files]),
449 ]);
450
451 if (function_exists('opcache_get_status'))
452 {
453 $cacheStatus = opcache_get_status(false);
454 $cachedKeys = intval($cacheStatus['opcache_statistics']['num_cached_keys']);
455 $maxKeys = intval($cacheStatus['opcache_statistics']['max_cached_keys']);
456 $is_ok = ($cachedKeys <= 0) || ($maxKeys <= 0) || ($cachedKeys < $maxKeys);
457
458 if (!$is_ok)
459 {
460 array_unshift($arResult, [
461 'PARAMETER' => 'opcache.max_accelerated_files',
462 'IS_OK' => $is_ok,
463 'VALUE' => $maxKeys,
464 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_EQUAL_OR_GREATER_THAN_REC', ['#value#' => $cachedKeys]),
465 ]);
466 }
467 }
468 }
469
470 return $arResult;
471 }
472
473 public function GetParams()
474 {
475 $res = [
476 'enabled' => [
477 [
478 'PARAMETER' => 'opcache.enable',
479 'VALUE' => ini_get('opcache.enable'),
480 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_SET_REC', ['#value#' => '1']),
481 ]
482 ],
483 'check_mtime' => [
484 [
485 'PARAMETER' => 'opcache.validate_timestamps',
486 'VALUE' => ini_get('opcache.validate_timestamps'),
487 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_SET_REC', ['#value#' => '1']),
488 ]
489 ],
490 'memory_abs' => [
491 [
492 'PARAMETER' => 'opcache.memory_consumption',
493 'VALUE' => ini_get('opcache.memory_consumption'),
494 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_EQUAL_OR_GREATER_THAN_REC', ['#value#' => '40']),
495 ]
496 ],
497 'max_file_size' => [
498 [
499 'PARAMETER' => 'opcache.max_file_size',
500 'VALUE' => ini_get('opcache.max_file_size'),
501 'RECOMMENDATION' => Loc::getMessage('PERFMON_MEASURE_SET_REC', ['#value#' => '0']),
502 ]
503 ],
504 ];
505
506 if (function_exists('opcache_get_status'))
507 {
508 $conf = opcache_get_status(false);
509 $res['memory_abs'][] = [
510 'PARAMETER' => 'opcache.memory_usage.used_memory',
511 'VALUE' => CFile::FormatSize($conf['memory_usage']['used_memory']),
512 'RECOMMENDATION' => '',
513 ];
514
515 $res['memory_abs'][] = [
516 'PARAMETER' => 'opcache.memory_usage.free_memory',
517 'VALUE' => CFile::FormatSize($conf['memory_usage']['free_memory']),
518 'RECOMMENDATION' => '',
519 ];
520 }
521
522 return $res;
523 }
524}
$arParams
Определения access_dialog.php:21
$type
Определения options.php:106
$arResult
Определения generate_coupon.php:16
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения measure.php:198
static unformat($str)
Определения measure.php:392
$cache_ttl
Определения measure.php:200
$max_file_size
Определения measure.php:201
$memory_used
Определения measure.php:204
GetRecommendations()
Определения measure.php:273
$cache_limit
Определения measure.php:205
$enabled
Определения measure.php:199
__construct($enabled, $cache_ttl, $max_file_size, $check_mtime, $memory_total, $memory_used, $cache_limit=-1)
Определения measure.php:207
$check_mtime
Определения measure.php:202
$memory_total
Определения measure.php:203
GetParams()
Определения measure.php:218
IsWorking()
Определения measure.php:223
__construct()
Определения measure.php:416
GetRecommendations()
Определения measure.php:434
GetParams()
Определения measure.php:473
Определения measure.php:8
static noOp(&$k)
Определения measure.php:9
static GetPHPFilesMark()
Определения measure.php:60
static oneOp(&$k)
Определения measure.php:13
static GetPHPMailMark()
Определения measure.php:104
static GetPHPCPUMark()
Определения measure.php:21
static GetAccelerator()
Определения measure.php:174
static GetAllAccelerators()
Определения measure.php:185
static GetDBMark($type)
Определения measure.php:117
$str
Определения commerceml2.php:63
$content
Определения commerceml.php:144
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
bxmail($to, $subject, $message, $additional_headers="", $additional_parameters="", Main\Mail\Context $context=null)
Определения tools.php:4999
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$rs
Определения action.php:82
$k
Определения template_pdf.php:567