From 828a2eb1cef08d6aade2cdb8e7b8af466b1420b9 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 15 Jan 2016 09:52:31 +0100 Subject: [PATCH] added time --- .jsbeautifyrc | 4 + js/client/modules/@arangodb/work-monitor.js | 147 +++++++++++++++++--- lib/Basics/WorkMonitor.cpp | 2 + 3 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 .jsbeautifyrc diff --git a/.jsbeautifyrc b/.jsbeautifyrc new file mode 100644 index 0000000000..cbae34b07e --- /dev/null +++ b/.jsbeautifyrc @@ -0,0 +1,4 @@ +{ + "indent_size": 2, + "indent_char": " " +} \ No newline at end of file diff --git a/js/client/modules/@arangodb/work-monitor.js b/js/client/modules/@arangodb/work-monitor.js index 14b4ee012f..7da8d8f128 100644 --- a/js/client/modules/@arangodb/work-monitor.js +++ b/js/client/modules/@arangodb/work-monitor.js @@ -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; - diff --git a/lib/Basics/WorkMonitor.cpp b/lib/Basics/WorkMonitor.cpp index cbc4052747..eb5f4cee30 100644 --- a/lib/Basics/WorkMonitor.cpp +++ b/lib/Basics/WorkMonitor.cpp @@ -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)); {