<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Monitor; use Illuminate\Database\Events\QueryExecuted; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use ModStart\Core\Util\ArrayUtil; class DatabaseMonitor { private static $queryCountPerRequest = 0; private static $queryCountPerRequestSqls = array(); public static function init() { goto B80VG; snfJd: self::$queryCountPerRequest = 0; goto YoFDT; B80VG: if (!config('modstart.trackPerformance', false)) { return; } goto snfJd; sS8FJ: try { DB::listen(function ($AOBVZ, $c8ASk = null, $gmNPm = null, $cUGGU = null) { self::$queryCountPerRequest++; $or7wn = $AOBVZ; if (method_exists(\ModStart\ModStart::class, 'env') && \ModStart\ModStart::env() == 'laravel9') { goto JBO_r; JBO_r: $or7wn = $AOBVZ->sql; goto w3Cbk; DSMff: $gmNPm = $AOBVZ->time; goto ItfqC; w3Cbk: $c8ASk = $AOBVZ->bindings; goto DSMff; ItfqC: } self::$queryCountPerRequestSqls[] = array('sql' => $or7wn, 'bindings' => $c8ASk); if ($gmNPm > 500) { Log::warning("LONG_SQL {$gmNPm}ms, {$or7wn}, " . ArrayUtil::serializeForLog($c8ASk)); } }); } catch (\Exception $SXS9c) { } goto FDcwr; YoFDT: self::$queryCountPerRequestSqls = array(); goto sS8FJ; FDcwr: } public static function getQueryCountPerRequest() { return self::$queryCountPerRequest; } public static function getQueryCountPerRequestSqls() { foreach (self::$queryCountPerRequestSqls as $eQWJY => $tHq0l) { if (is_array($tHq0l)) { $c8ASk = ArrayUtil::serializeForLog($tHq0l['bindings']); self::$queryCountPerRequestSqls[$eQWJY] = $tHq0l['sql'] . ', ' . $c8ASk; } } return self::$queryCountPerRequestSqls; } }