mirror of https://gitee.com/bigwinds/arangodb
added time
This commit is contained in:
parent
d2c349b8b5
commit
828a2eb1ce
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"indent_size": 2,
|
||||
"indent_char": " "
|
||||
}
|
|
@ -28,6 +28,121 @@
|
|||
const arangosh = require("@arangodb/arangosh");
|
||||
const printf = require("internal").printf;
|
||||
|
||||
const colors = require("internal").COLORS;
|
||||
const BLUE = colors.COLOR_BLUE;
|
||||
const RED = colors.COLOR_RED;
|
||||
const GREEN = colors.COLOR_GREEN;
|
||||
const CYAN = colors.COLOR_CYAN;
|
||||
const RESET = colors.COLOR_RESET;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief fills left
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const fillL = function(s, w) {
|
||||
if (s.length >= w) {
|
||||
return s;
|
||||
}
|
||||
|
||||
return (new Array(w - s.length + 1)).join(" ") + s;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief fills right
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const fillR = function(s, w) {
|
||||
if (s.length >= w) {
|
||||
return s;
|
||||
}
|
||||
|
||||
return s + (new Array(w - s.length + 1)).join(" ");
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generates work description
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const workDescription = function(level, w, desc, now) {
|
||||
const t = w.type;
|
||||
|
||||
desc.level = level;
|
||||
|
||||
if (level === 0) {
|
||||
desc.root = desc;
|
||||
}
|
||||
|
||||
desc.level = level;
|
||||
|
||||
if (t === "thread") {
|
||||
desc.root.thread = w.name;
|
||||
|
||||
desc.type = "thread";
|
||||
desc.name = "";
|
||||
desc.info = "";
|
||||
} else if (t === "AQL query") {
|
||||
desc.type = "aql";
|
||||
desc.name = GREEN + "AQL" + RESET;
|
||||
desc.info = w.description;
|
||||
} else if (t === "http-handler") {
|
||||
desc.type = "request";
|
||||
desc.name = GREEN + "REQUEST" + RESET;
|
||||
desc.info = w.method + " " + w.url + " (" + w.protocol + ")";
|
||||
|
||||
desc = desc.child = {
|
||||
root: desc.root, level: desc.level, type: "variable",
|
||||
name: CYAN + "runtime" + RESET,
|
||||
info: (now - w.startTime).toFixed(2) + " sec"
|
||||
};
|
||||
|
||||
desc = desc.child = {
|
||||
root: desc.root, level: desc.level, type: "variable",
|
||||
name: CYAN + "client " + RESET,
|
||||
info: w.client.address + ":" + w.client.port
|
||||
};
|
||||
} else {
|
||||
desc.type = "unknown";
|
||||
desc.name = RED + t + RESET;
|
||||
desc.info = "";
|
||||
}
|
||||
|
||||
if (w.hasOwnProperty('parent')) {
|
||||
desc.child = {
|
||||
root: desc.root
|
||||
};
|
||||
workDescription(level + 1, w.parent, desc.child, now);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief outputs work description
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const outputWorkDescription = function(desc, opts) {
|
||||
let line = "";
|
||||
|
||||
if (desc.level > 0 && desc.type === "thread") {
|
||||
return;
|
||||
}
|
||||
|
||||
line += BLUE;
|
||||
|
||||
if (desc.level === 0) {
|
||||
line += fillR(desc.thread, opts.width);
|
||||
} else {
|
||||
line += fillR("", opts.width);;
|
||||
}
|
||||
|
||||
line += RESET + fillR("", 2 * desc.level + 1) + desc.name;
|
||||
line += " " + desc.info;
|
||||
|
||||
print(line);
|
||||
|
||||
if (desc.hasOwnProperty("child")) {
|
||||
outputWorkDescription(desc.child, opts);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief request work information
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -38,25 +153,24 @@ const workOverview = function() {
|
|||
|
||||
const work = res.work;
|
||||
|
||||
const output = function(indent, w) {
|
||||
let txt = "";
|
||||
let descs = [];
|
||||
let w1 = 0;
|
||||
const now = res.time;
|
||||
|
||||
if (w.type === "thread") {
|
||||
txt = w.name;
|
||||
} else if (w.type === "AQL query") {
|
||||
txt = w.description;
|
||||
} else if (w.type === "http-handler") {
|
||||
txt = w.url + " (started: " + w.startTime + ")";
|
||||
}
|
||||
|
||||
printf("%s%s: %s\n", indent, w.type, txt);
|
||||
work.forEach(function(w) {
|
||||
let desc = {};
|
||||
|
||||
if (w.hasOwnProperty('parent')) {
|
||||
output(" " + indent, w.parent);
|
||||
}
|
||||
};
|
||||
workDescription(0, w, desc, now);
|
||||
descs.push(desc);
|
||||
|
||||
work.forEach(function(w) {output("", w);});
|
||||
w1 = Math.max(w1, desc.thread.length);
|
||||
});
|
||||
|
||||
descs.forEach(function(d) {
|
||||
outputWorkDescription(d, {
|
||||
width: w1
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -64,4 +178,3 @@ const workOverview = function() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.workOverview = workOverview;
|
||||
|
||||
|
|
|
@ -375,6 +375,8 @@ void WorkMonitor::run() {
|
|||
VPackBuilder b;
|
||||
|
||||
b.add(VPackValue(VPackValueType::Object));
|
||||
|
||||
b.add("time", VPackValue(TRI_microtime()));
|
||||
b.add("work", VPackValue(VPackValueType::Array));
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue