Output a Trace Event metadata event identifying each named thread

Move the generic dummy implementation of
TraceEvent::emitOneRecording() to a source file of its own. (That is
the one which is used in test and tool executables.)

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I81cab07e5a6852b42d278a5446c13c3825cf546e
pull/2626/head
Tor Lillqvist 2021-06-17 13:31:27 +03:00 committed by Tor Lillqvist
parent bbd60b5575
commit d6569159b7
7 changed files with 42 additions and 13 deletions

View File

@ -154,12 +154,14 @@ noinst_PROGRAMS += loolwsd_fuzzer
endif
connect_SOURCES = tools/Connect.cpp \
common/DummyTraceEventEmitter.cpp \
common/Log.cpp \
common/Protocol.cpp \
common/StringVector.cpp \
common/Util.cpp
lokitclient_SOURCES = common/Log.cpp \
common/DummyTraceEventEmitter.cpp \
tools/KitClient.cpp \
common/Protocol.cpp \
common/StringVector.cpp \
@ -210,6 +212,7 @@ httpresponse_fuzzer_SOURCES = \
httpresponse_fuzzer_LDFLAGS = -fsanitize=fuzzer $(AM_LDFLAGS)
clientnb_SOURCES = net/clientnb.cpp \
common/DummyTraceEventEmitter.cpp \
common/Log.cpp \
common/StringVector.cpp \
common/Util.cpp
@ -222,18 +225,21 @@ loolconvert_SOURCES = tools/Tool.cpp
loolstress_CPPFLAGS = -DTDOC=\"$(abs_top_srcdir)/test/data\" ${include_paths}
loolstress_SOURCES = tools/Stress.cpp \
common/DummyTraceEventEmitter.cpp \
common/Protocol.cpp \
common/StringVector.cpp \
common/Log.cpp \
common/Util.cpp
loolconfig_SOURCES = tools/Config.cpp \
common/DummyTraceEventEmitter.cpp \
common/Crypto.cpp \
common/Log.cpp \
common/StringVector.cpp \
common/Util.cpp
loolsocketdump_SOURCES = tools/WebSocketDump.cpp \
common/DummyTraceEventEmitter.cpp \
$(shared_sources)
wsd_headers = wsd/Admin.hpp \

View File

@ -0,0 +1,18 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Compile and link this into test and utility executables that need it to link
#include <common/TraceEvent.hpp>
void TraceEvent::emitOneRecording(const std::string &recording)
{
// Dummy.
(void) recording;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -102,10 +102,6 @@ protected:
}
}
// This method needs to be implemented separately in the WSD and Kit processes. (WSD writes the
// actual Trace Event log file, Kit just forwards the Trace Events to WSD for output.)
static void emitOneRecording(const std::string &recording);
public:
static void startRecording();
static void stopRecording();
@ -120,6 +116,10 @@ public:
emitInstantEvent(name, createArgsString(args));
}
// This method needs to be implemented separately in the WSD and Kit processes. (WSD writes the
// actual Trace Event log file, Kit just forwards the Trace Events to WSD for output.)
static void emitOneRecording(const std::string &recording);
TraceEvent(const TraceEvent&) = delete;
void operator=(const TraceEvent&) = delete;
};

View File

@ -62,6 +62,7 @@
#include "Common.hpp"
#include "Log.hpp"
#include "Protocol.hpp"
#include "TraceEvent.hpp"
namespace Util
{
@ -573,6 +574,16 @@ namespace Util
[[NSThread currentThread] setName:[NSString stringWithUTF8String:ThreadName]];
LOG_INF("Thread " << getThreadId() << ") is now called [" << s << ']');
#endif
// Emit a metadata Trace Event identifying this thread. This will invoke a different function
// depending on which executable this is in.
TraceEvent::emitOneRecording("{\"name\":\"thread_name\",\"ph\":\"M\",\"args\":{\"name\":\""
+ s
+ "\"},\"pid\":"
+ std::to_string(getpid())
+ ",\"tid\":"
+ std::to_string(Util::getThreadId())
+ "},");
}
const char *getThreadName()

View File

@ -525,7 +525,6 @@ int main(int argc, char** argv)
SigUtil::setTerminationSignals();
#endif
Util::setThreadName("forkit");
Util::setApplicationPath(Poco::Path(argv[0]).parent().toString());
// Initialization
@ -694,6 +693,8 @@ int main(int argc, char** argv)
config::initialize(std::string(conf ? conf : std::string()));
#endif
Util::setThreadName("forkit");
LOG_INF("Preinit stage OK.");
// We must have at least one child, more are created dynamically.

View File

@ -119,7 +119,7 @@ unit_base_la_LIBADD += -lssl -lcrypto
endif
fakesockettest_CPPFLAGS = -g
fakesockettest_SOURCES = fakesockettest.cpp ../net/FakeSocket.cpp ../common/Log.cpp ../common/Util.cpp
fakesockettest_SOURCES = fakesockettest.cpp ../net/FakeSocket.cpp ../common/DummyTraceEventEmitter.cpp ../common/Log.cpp ../common/Util.cpp
fakesockettest_LDADD = $(CPPUNIT_LIBS)
# old-style unit tests - bootstrapped via UnitClient

View File

@ -28,16 +28,9 @@
#if ENABLE_SSL
# include <SslSocket.hpp>
#endif
#include <common/TraceEvent.hpp>
SocketPoll DumpSocketPoll("websocket");
void TraceEvent::emitOneRecording(const std::string &sRecording)
{
// Dummy.
(void) sRecording;
}
// Dumps incoming websocket messages and doesn't respond.
class DumpSocketHandler : public WebSocketHandler
{