Files
ulthon_admin/app/admin/view/xhprof/run/index.js

94 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$(function () {
// request_time 为浮点秒decimal(13,3)),渲染为日期时间
var formatRequestTime = function (d) {
var t = parseFloat(d.request_time);
if (!t || isNaN(t)) {
return '-';
}
var dt = new Date(t * 1000);
var p = function (n) {
return n < 10 ? '0' + n : '' + n;
};
return dt.getFullYear() + '-' + p(dt.getMonth() + 1) + '-' + p(dt.getDate())
+ ' ' + p(dt.getHours()) + ':' + p(dt.getMinutes()) + ':' + p(dt.getSeconds());
};
ua.table.render({
init: init,
toolbar: [],
cols: [[
{field: 'request_time', title: '请求时间', width: 170, sort: true, search: 'range', templet: formatRequestTime},
{
field: 'method', title: '方法', width: 90, search: 'select', selectList: {
GET: 'GET', POST: 'POST', PUT: 'PUT', DELETE: 'DELETE', HEAD: 'HEAD', OPTIONS: 'OPTIONS', PATCH: 'PATCH'
}, templet: function (d) {
var cls = {
GET: 'layui-bg-blue',
POST: 'layui-bg-green',
PUT: 'layui-bg-orange',
DELETE: 'layui-bg-red',
HEAD: 'layui-bg-gray',
OPTIONS: 'layui-bg-gray',
PATCH: 'layui-bg-cyan'
}[d.method];
if (d.method && cls) {
return '<span class="layui-badge ' + cls + '">' + d.method + '</span>';
}
return d.method || '-';
}
},
{
field: 'url', title: 'URL', minWidth: 220, searchOp: '%*%', templet: function (d) {
var u = String(d.url || '');
var esc = u.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
var short = u.length > 50 ? u.substring(0, 50) + '…' : u;
short = short.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
return '<span title="' + esc + '">' + (short === '' ? '/' : short) + '</span>';
}
},
{field: 'node_id', title: '节点', width: 160, search: 'select', searchOp: '=', selectList: ua.getDataBrage('select_list_node_id') || {}},
{
field: 'wall_time', title: '总耗时', width: 110, sort: true, searchOp: 'min', searchTip: '总耗时下限(ms)', templet: function (d) {
var ms = parseInt(d.wall_time, 10) / 1000;
var txt = ms.toFixed(1) + 'ms';
if (ms > 1000) {
return '<span class="layui-badge layui-bg-red">' + txt + '</span>';
}
return txt;
}
},
{
field: 'cpu_time', title: 'CPU耗时', width: 110, search: false, templet: function (d) {
var ms = parseInt(d.cpu_time, 10) / 1000;
var txt = ms.toFixed(1) + 'ms';
if (ms > 1000) {
return '<span class="layui-badge layui-bg-red">' + txt + '</span>';
}
return txt;
}
},
{
field: 'memory_peak', title: '内存峰值', width: 110, sort: true, search: false, templet: function (d) {
return (parseInt(d.memory_peak, 10) / 1048576).toFixed(2) + 'MB';
}
},
{
width: 100, title: '操作', fixed: 'right', templet: ua.table.tool, operat: [
[{
class: 'layui-btn layui-btn-primary layui-btn-xs',
method: 'open',
field: 'id',
text: '详情',
title: '采样详情(函数级分析)',
auth: 'detail',
url: init.detailUrl,
extend: 'data-full="true"'
}]
]
}
]]
});
ua.listen();
});