From eb9c580c3622e366d793df5abe77478f7bcaffb8 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 21 Apr 2021 17:42:52 +0300 Subject: [PATCH] Introduce ways to toggle and tweak core Trace Event recording and logging When toggling tile debugging in the Help>About, toggle Trace Event recordning, too. Add a comment with an example of how to turn on SAL_LOG overriding at the same place. The following new messages from client to server are introduced: traceeventrecording Starts or stops comphelper::TraceEvent recording. sallogoverride Overrides the SAL_LOG value, or stops overriding if no parameter or parameter is "default". Signed-off-by: Tor Lillqvist Change-Id: I8b56c28cd99d39115cd796c44e5051d934d21a1f Signed-off-by: Tor Lillqvist --- kit/ChildSession.cpp | 35 +++++++++++++++++++++++++++++++- loleaflet/src/control/Toolbar.js | 18 ++++++++++++++++ wsd/ClientSession.cpp | 5 ++++- wsd/protocol.txt | 15 ++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 1cc11b300..126abbc1b 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -305,7 +305,9 @@ bool ChildSession::_handleInput(const char *buffer, int length) tokens.equals(0, "removetextcontext") || tokens.equals(0, "dialogevent") || tokens.equals(0, "completefunction")|| - tokens.equals(0, "formfieldevent")); + tokens.equals(0, "formfieldevent") || + tokens.equals(0, "traceeventrecording") || + tokens.equals(0, "sallogoverride")); if (tokens.equals(0, "clientzoom")) { @@ -457,6 +459,37 @@ bool ChildSession::_handleInput(const char *buffer, int length) { return formFieldEvent(buffer, length, tokens); } + else if (tokens.equals(0, "traceeventrecording")) + { + if (tokens.size() > 0) + { + if (tokens.equals(1, "start")) + { + getLOKit()->setOption("traceeventrecording", "start"); + LOG_INF("Profile zone tracing in this kit process turned on (might have been on all the time)"); + } + else if (tokens.equals(1, "stop")) + { + getLOKit()->setOption("traceeventrecording", "stop"); + LOG_INF("Profile zone tracing in this kit process turned off"); + } + } + } + else if (tokens.equals(0, "sallogoverride")) + { + if (tokens.size() == 0 || tokens.equals(1, "default")) + { + getLOKit()->setOption("sallogoverride", nullptr); + } + else if (tokens.size() > 0 && tokens.equals(1, "off")) + { + getLOKit()->setOption("sallogoverride", "-WARN-INFO"); + } + else if (tokens.size() > 0) + { + getLOKit()->setOption("sallogoverride", tokens[1].c_str()); + } + } else { assert(false && "Unknown command token."); diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index aa50ecd3e..d3214e791 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -26,6 +26,11 @@ L.Map.include({ } }, + // Triple-clicking turns profiling on in the kit process for + // this document (it is already if the server is running with log level + // "trace"). Triple-clicking again turns it off. Etc. + _profilingRequestedToggle: false, + onFontSelect: function(e) { var font = e.target.value; this.applyFont(font); @@ -703,6 +708,19 @@ L.Map.include({ hammer.add(new Hammer.Tap({ taps: 3 })); hammer.on('tap', function() { map._docLayer.toggleTileDebugMode(); + + map._socket.sendMessage('traceeventrecording ' + (map._profilingRequestedToggle ? 'stop' : 'start')); + + // Just as a test, uncomment this to toggle SAL_WARN and SAL_INFO + // selection between two states: 1) the default as directed by the + // SAL_LOG environment variable, and 2) all warnings on plus SAL_INFO for sc. + // + // (Note that loolwsd sets the SAL_LOG environment variable to + // "-WARN-INFO", i.e. the default is that nothing is logged) + + // map._socket.sendMessage('sallogoverride ' + (map._profilingRequestedToggle ? 'default' : '+WARN+INFO.sc')); + + map._profilingRequestedToggle = !map._profilingRequestedToggle; }); this.contentEl.style.width = w + 'px'; diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 9db035c71..9ee207a1c 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -691,7 +691,10 @@ bool ClientSession::_handleInput(const char *buffer, int length) docBroker->uploadAsToStorage(getId(), "", wopiFilename, true); return true; } - else if (tokens.equals(0, "dialogevent") || tokens.equals(0, "formfieldevent")) + else if (tokens.equals(0, "dialogevent") || + tokens.equals(0, "formfieldevent") || + tokens.equals(0, "traceeventrecording") || + tokens.equals(0, "sallogoverride")) { return forwardToChild(firstLine, docBroker); } diff --git a/wsd/protocol.txt b/wsd/protocol.txt index f56e7f04e..957e0cecd 100644 --- a/wsd/protocol.txt +++ b/wsd/protocol.txt @@ -289,6 +289,15 @@ removesession privilege views cannot remove higher ones, eg. a readonly view can't remove an editor. +traceeventrecording + + Starts or stops comphelper::TraceEvent recording. + +sallogoverride + + Overrides the SAL_LOG value, or stops overriding if no parameter + or parameter is "default". + server -> client ================ @@ -622,6 +631,12 @@ clipboardcontent: ... +trace: + + Followed by a number of lines consisting of Chrome Trace Event + formatted data recorded by the comphelper::TraceEvent API in the + core parts of the kit process. + parent -> child ===============