From 05c9e56973a9a6a1f406b9fdda90a3ecb196c6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Fri, 24 Mar 2017 01:28:21 +0100 Subject: [PATCH] FEATURE #2389 @2h: add request detail into profiler --- bower.json | 3 +- gulpfile.js | 1 + .../Http/Controllers/ProfilerController.php | 17 +++- .../Http/Controllers/RequestController.php | 23 +++++ modules/Profiler/Http/routes.php | 16 +++- modules/Profiler/Resources/lang/cs/module.php | 10 ++ .../views/_partials/requestList.blade.php | 55 +++++++++++ .../Profiler/Resources/views/index.blade.php | 38 ++------ .../Resources/views/queries/index.blade.php | 50 +++++----- .../Resources/views/request/detail.blade.php | 92 +++++++++++++++++++ resources/assets/admin/css/custom.css | 58 ++++++------ 11 files changed, 273 insertions(+), 90 deletions(-) create mode 100644 modules/Profiler/Http/Controllers/RequestController.php create mode 100644 modules/Profiler/Resources/views/_partials/requestList.blade.php create mode 100644 modules/Profiler/Resources/views/request/detail.blade.php diff --git a/bower.json b/bower.json index 8a0fecdd..313afb2b 100644 --- a/bower.json +++ b/bower.json @@ -14,6 +14,7 @@ "tether": "~1.1.1", "tinycolor": "~1.2.1", "dropzone": "~4.2.0", - "jquery.are-you-sure": "~1.9" + "jquery.are-you-sure": "~1.9", + "chart.js": "^2.5.0" } } diff --git a/gulpfile.js b/gulpfile.js index e591f1d3..4832a5de 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,6 +11,7 @@ elixir (function (mix) { 'responsive-bootstrap-toolkit/dist/bootstrap-toolkit.js', 'metisMenu/dist/metisMenu.min.js', 'tinycolor/dist/tinycolor-min.js', + 'chart.js/dist/Chart.bundle.min.js', 'jquery.are-you-sure/jquery.are-you-sure.js', '../resources/assets/admin/js/app.js', ], 'public/js/vendor.js', 'bower_components'); diff --git a/modules/Profiler/Http/Controllers/ProfilerController.php b/modules/Profiler/Http/Controllers/ProfilerController.php index e03979e7..9aa23e83 100644 --- a/modules/Profiler/Http/Controllers/ProfilerController.php +++ b/modules/Profiler/Http/Controllers/ProfilerController.php @@ -1,15 +1,28 @@ with('queries') - ->paginate(25); + ->with('queries'); + + if (Input::get('method')) { + $filters[] = 'method'; + $httpLog = $httpLog->where('method', Input::get('method')); + } + + if (Input::get('url')) { + $filters[] = 'url'; + $httpLog = $httpLog->where('url', Input::get('url')); + } + + $httpLog = $httpLog->paginate(25); return view('profiler::index', compact('httpLog')); } diff --git a/modules/Profiler/Http/Controllers/RequestController.php b/modules/Profiler/Http/Controllers/RequestController.php new file mode 100644 index 00000000..25a640d9 --- /dev/null +++ b/modules/Profiler/Http/Controllers/RequestController.php @@ -0,0 +1,23 @@ +url) + ->where('method', $httpLog->method) + ->get(); + + $times = [ + 'avg' => $sameRequests->avg('time'), + 'min' => $sameRequests->min('time'), + 'max' => $sameRequests->max('time') + ]; + + return view('profiler::request.detail', compact('httpLog', 'sameRequests', 'times')); + } +} \ No newline at end of file diff --git a/modules/Profiler/Http/routes.php b/modules/Profiler/Http/routes.php index 4b3da4c2..78ae793c 100644 --- a/modules/Profiler/Http/routes.php +++ b/modules/Profiler/Http/routes.php @@ -1,14 +1,20 @@ LaravelLocalization::setLocale(), - 'namespace' => 'Modules\Profiler\Http\Controllers' + 'prefix' => LaravelLocalization::setLocale(), + 'namespace' => 'Modules\Profiler\Http\Controllers' ], function () { Route::group([ 'middleware' => ['admin'], - 'prefix' => 'profiler' + 'prefix' => 'admin/profiler' ], function () { - Route::get('/', 'ProfilerController@index')->name('profiler.index'); - Route::get('{httpLog}/queries', 'QueryController@index')->name('queries.index'); + Route::get('/', 'ProfilerController@index') + ->name('profiler.index'); + + Route::get('{httpLog}', 'RequestController@detail') + ->name('request.detail'); + + Route::get('{httpLog}/queries', 'QueryController@index') + ->name('queries.index'); }); }); \ No newline at end of file diff --git a/modules/Profiler/Resources/lang/cs/module.php b/modules/Profiler/Resources/lang/cs/module.php index 4cf8d445..4abae6eb 100644 --- a/modules/Profiler/Resources/lang/cs/module.php +++ b/modules/Profiler/Resources/lang/cs/module.php @@ -11,5 +11,15 @@ return [ 'settings' => [ 'useProfilerInVisitorArea' => 'Zapnout měření ve veřejné části?', 'useProfilerInAdmin' => 'Zapnout měření v administraci?' + ], + 'request' => [ + 'info' => 'Detaily requestu', + 'sql' => 'SQL dotazy', + 'detail' => 'Detail požadavku', + 'sameRequests' => 'Ostatní volání' + ], + 'graphs' => [ + 'responseTime' => 'Doba odezvy' ] + ]; \ No newline at end of file diff --git a/modules/Profiler/Resources/views/_partials/requestList.blade.php b/modules/Profiler/Resources/views/_partials/requestList.blade.php new file mode 100644 index 00000000..e81d86fe --- /dev/null +++ b/modules/Profiler/Resources/views/_partials/requestList.blade.php @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + @foreach($requests as $request) + + + + + + + + + @endforeach + +
@lang('profiler::module.index.createdAt')@lang('profiler::module.index.httpMethod')@lang('profiler::module.index.url')@lang('profiler::module.index.time')@lang('profiler::module.index.systemLoad')
{{$request->created_at->format('d.m.Y G:i')}}{{$request->method}}{{$request->url}}{{number_format($request->time, 3)}} ms{{$request->load_1}}, {{$request->load_5}}, {{$request->load_15}} + +
+ + + + + + + + +
+ +
+
+ + +
\ No newline at end of file diff --git a/modules/Profiler/Resources/views/index.blade.php b/modules/Profiler/Resources/views/index.blade.php index 33ef20c6..fca67c83 100644 --- a/modules/Profiler/Resources/views/index.blade.php +++ b/modules/Profiler/Resources/views/index.blade.php @@ -4,34 +4,12 @@ @section('content') - - - - - - - - - - - - - - - @foreach($httpLog as $request) - - - - - - - - - @endforeach - -
@lang('profiler::module.index.createdAt')@lang('profiler::module.index.httpMethod')@lang('profiler::module.index.url')@lang('profiler::module.index.time')@lang('profiler::module.index.systemLoad')
{{$request->created_at->format('d.m.Y G:i')}}{{$request->method}}{{$request->url}}{{number_format($request->time, 3)}} ms{{$request->load_1}}, {{$request->load_5}}, {{$request->load_15}} - SQL -
- - {!! $httpLog->render() !!} +
+
+ @include('profiler::_partials.requestList', ['requests' => $httpLog]) +
+ +
@stop \ No newline at end of file diff --git a/modules/Profiler/Resources/views/queries/index.blade.php b/modules/Profiler/Resources/views/queries/index.blade.php index 1e7ea4c1..6cc05e5f 100644 --- a/modules/Profiler/Resources/views/queries/index.blade.php +++ b/modules/Profiler/Resources/views/queries/index.blade.php @@ -4,30 +4,34 @@ @section('content') - - - - - - - - - - - +
+
+
@lang('profiler::module.queries.createdAt')@lang('profiler::module.queries.sql')@lang('profiler::module.queries.binding')@lang('profiler::module.queries.time')
+ + + + + + + + - @foreach($queries as $query) - - - - + - - - @endforeach - -
@lang('profiler::module.queries.sql')@lang('profiler::module.queries.time')
{{$query->created_at->format('d.m.Y G:i')}}{{$query->query}} + @foreach($queries as $query) +
+ @php $sql = $query->query; @endphp + @foreach($query->bindings as $value) + @php $sql = preg_replace('/\?/', $value, $sql, 1); @endphp + @endforeach - {{var_export($query->bindings)}} - {{number_format($query->time, 3)}} ms
+ {{$sql}} + + {{number_format($query->time, 3)}} ms + + @endforeach + + + + @endsection \ No newline at end of file diff --git a/modules/Profiler/Resources/views/request/detail.blade.php b/modules/Profiler/Resources/views/request/detail.blade.php new file mode 100644 index 00000000..8722edf3 --- /dev/null +++ b/modules/Profiler/Resources/views/request/detail.blade.php @@ -0,0 +1,92 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('profiler::module.name')) + +@section('content') + +
+
+
+
+
+

@lang('profiler::module.request.detail')

+
+
+ +
+
+
    +
  • @lang('profiler::module.index.httpMethod'): {{$httpLog->method}}
  • +
  • @lang('profiler::module.index.url'): {{$httpLog->url}}
  • +
  • @lang('profiler::module.index.time'): {{number_format($httpLog->time, 2)}}
  • +
  • @lang('profiler::module.index.systemLoad'): {{$httpLog->load_1}}, {{$httpLog->load_5}} + , {{$httpLog->load_15}}
  • +
+
+ +
+

{{count($sameRequests)}} ×

volano
+

{{number_format($times['min'], 2)}} ms

min
+

{{number_format($times['max'], 2)}} ms

max
+

{{number_format($times['avg'], 2)}} ms

prumer
+
+ +
+
+
+ +
+
+
+
+

@lang('profiler::module.graphs.responseTime')

+
+
+
+ +
+
+
+
+ +
+
+
+

@lang('profiler::module.request.sameRequests')

+
+
+ +
+ @include('profiler::_partials.requestList', ['requests' => $sameRequests]) +
+
+ + +@endsection + +@section('javascripts') + +@endsection \ No newline at end of file diff --git a/resources/assets/admin/css/custom.css b/resources/assets/admin/css/custom.css index 40ea2d5f..d3d68009 100644 --- a/resources/assets/admin/css/custom.css +++ b/resources/assets/admin/css/custom.css @@ -340,77 +340,77 @@ img { } /*.tag {*/ - /*display: inline-block;*/ - /*padding: 0.25em 0.4em;*/ - /*font-size: 75%;*/ - /*font-weight: bold;*/ - /*line-height: 1;*/ - /*color: #FFF;*/ - /*text-align: center;*/ - /*white-space: nowrap;*/ - /*vertical-align: baseline;*/ - /*border-radius: 0.25rem;*/ +/*display: inline-block;*/ +/*padding: 0.25em 0.4em;*/ +/*font-size: 75%;*/ +/*font-weight: bold;*/ +/*line-height: 1;*/ +/*color: #FFF;*/ +/*text-align: center;*/ +/*white-space: nowrap;*/ +/*vertical-align: baseline;*/ +/*border-radius: 0.25rem;*/ /*}*/ /*.tag:empty {*/ - /*display: none;*/ +/*display: none;*/ /*}*/ /*.btn .tag {*/ - /*position: relative;*/ - /*top: -1px;*/ +/*position: relative;*/ +/*top: -1px;*/ /*}*/ /*a.tag:focus, a.tag:hover {*/ - /*color: #FFF;*/ - /*text-decoration: none;*/ - /*cursor: pointer;*/ +/*color: #FFF;*/ +/*text-decoration: none;*/ +/*cursor: pointer;*/ /*}*/ /*.tag-pill {*/ - /*padding-right: 0.6em;*/ - /*padding-left: 0.6em;*/ - /*border-radius: 10rem;*/ +/*padding-right: 0.6em;*/ +/*padding-left: 0.6em;*/ +/*border-radius: 10rem;*/ /*}*/ /*.tag-default {*/ - /*background-color: #818A91;*/ +/*background-color: #818A91;*/ /*}*/ /*.tag-default[href]:focus, .tag-default[href]:hover {*/ - /*background-color: #687077;*/ +/*background-color: #687077;*/ /*}*/ /*.tag-success {*/ - /*background-color: #5CB85C;*/ +/*background-color: #5CB85C;*/ /*}*/ /*.tag-success[href]:focus, .tag-success[href]:hover {*/ - /*background-color: #449D44;*/ +/*background-color: #449D44;*/ /*}*/ /*.tag-info {*/ - /*background-color: #5BC0DE;*/ +/*background-color: #5BC0DE;*/ /*}*/ /*.tag-info[href]:focus, .tag-info[href]:hover {*/ - /*background-color: #31B0D5;*/ +/*background-color: #31B0D5;*/ /*}*/ /*.tag-warning {*/ - /*background-color: #F0AD4E;*/ +/*background-color: #F0AD4E;*/ /*}*/ /*.tag-warning[href]:focus, .tag-warning[href]:hover {*/ - /*background-color: #EC971F;*/ +/*background-color: #EC971F;*/ /*}*/ /*.tag-danger {*/ - /*background-color: #D9534F;*/ +/*background-color: #D9534F;*/ /*}*/ /*.tag-danger[href]:focus, .tag-danger[href]:hover {*/ - /*background-color: #C9302C;*/ +/*background-color: #C9302C;*/ /*}*/