Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Test Impact Analysis #154

Draft
wants to merge 189 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
065c418
zmq powered gui
mpdeimos Sep 28, 2020
2385d65
retarget vc projects
mpdeimos Sep 28, 2020
a1e3e9f
codemaid
mpdeimos Sep 28, 2020
e0d81b1
add ZMQ, first concept of one-way profiler communication
mpdeimos Sep 29, 2020
a64c664
add testcase for one-way profiler communication
mpdeimos Sep 29, 2020
f0c0be3
rename gui
mpdeimos Sep 30, 2020
5befda8
add profiler commons project and use in test
mpdeimos Sep 30, 2020
95d8074
Test infra: use .net ZMQ and native ZMQ
mpdeimos Nov 24, 2020
59af32f
Extend Profiler Testee with an interactive mode
mpdeimos Nov 25, 2020
2f6f80d
Add publisher socket to C# IPC implementation
mpdeimos Nov 25, 2020
5c63ba7
Wire subscribe socket in C++ IPC
mpdeimos Nov 25, 2020
d40729c
write function infos to log on test case switch
mpdeimos Nov 25, 2020
1d016b9
Real TIA method call profiling
mpdeimos Dec 1, 2020
ea2fa00
Refactor tests
mpdeimos Dec 2, 2020
2f2e923
No locking until IPC is started
mpdeimos Dec 14, 2020
3022397
Use NetMQ-native threading
mpdeimos Dec 14, 2020
a5d3519
compiler profiler testee with native bitness and as x86, x64
mpdeimos Dec 14, 2020
aee3e91
parameterize tia tests as x64 and x86
mpdeimos Dec 14, 2020
1fbf7e7
test start ipc after app (not working yet)
mpdeimos Jan 22, 2021
82ea47f
commander rework
mpdeimos Jan 22, 2021
3874d31
simplified commander
mpdeimos Jan 22, 2021
519a256
multipart tia start/end
mpdeimos Jan 26, 2021
b421dc6
escaping of characters
mpdeimos Jan 26, 2021
0fec463
store test execution result
mpdeimos Jan 26, 2021
0bf704e
disable mscorlib profiling for TIA
mpdeimos Jan 26, 2021
8d868f8
fix for default socket
mpdeimos Jan 29, 2021
b256b52
Wrap coverage data in report class.
salsolatragus Nov 24, 2020
efa1a83
Write testwise coverage report.
salsolatragus Nov 27, 2020
6f639cf
Merge TraceFile and ParsedTraceFile classes.
salsolatragus Jan 31, 2021
266c6c0
Hide internal data of TraceFile.
salsolatragus Jan 31, 2021
5f9ad5e
Make names consistent.
salsolatragus Jan 31, 2021
c379efa
Ignores method references from unkown assemblies.
salsolatragus Jan 31, 2021
f83ce26
Improve some names.
salsolatragus Jan 31, 2021
985a4a4
Split testwise report and separate conversion from files.
salsolatragus Jan 31, 2021
9abbb23
Generate aggregated report.
salsolatragus Jan 31, 2021
1fcbe09
Introduce ICoverageReport abstraction.
salsolatragus Jan 31, 2021
abd3188
Tests simple report output.
salsolatragus Jan 31, 2021
d30faf1
Tests aggregated trace.
salsolatragus Jan 31, 2021
702224b
Test testwise report contents.
salsolatragus Jan 31, 2021
0769fc1
Remove obsolete method.
salsolatragus Jan 31, 2021
9a7a5f4
Simplify tests.
salsolatragus Jan 31, 2021
0bb95e6
Test generating testwise report.
salsolatragus Feb 1, 2021
760c7b9
Merge SimpleCoverageReport and LineCoverageReport.
salsolatragus Feb 1, 2021
2e0df40
Remove unused import.
salsolatragus Feb 1, 2021
9784045
Remove obsolete class.
salsolatragus Feb 1, 2021
7d2353f
Cleanup testwise report model.
salsolatragus Feb 1, 2021
6ef6870
Simplify creation of testwise report.
salsolatragus Feb 1, 2021
4cd2c43
Merge testwise reports with different tests.
salsolatragus Feb 1, 2021
2fba176
Merge testwise reports.
salsolatragus Feb 1, 2021
dffe644
Send report format to Teamscale.
salsolatragus Feb 1, 2021
d297d3b
Move simple report to own namespace.
salsolatragus Feb 1, 2021
9de811b
Serialize testwise report.
salsolatragus Feb 1, 2021
5c1df8d
Test parsing jitted, inlined, and called events.
salsolatragus Feb 2, 2021
458b210
Assume tests always start.
salsolatragus Feb 2, 2021
54b99b5
Consider test without end.
salsolatragus Feb 2, 2021
4057fab
Add no-test coverage only if any.
salsolatragus Feb 2, 2021
6a8c035
Fix test result labels.
salsolatragus Feb 2, 2021
73b2bd3
Keep non-test coverage.
salsolatragus Feb 2, 2021
4d232e2
cache latest test runs
mpdeimos Feb 2, 2021
3a32c3c
Merge test metadata.
salsolatragus Feb 2, 2021
77888f4
Simplify archiving API.
salsolatragus Feb 2, 2021
2e35d47
Shorten an expression.
salsolatragus Feb 2, 2021
6f74a98
Fix stupid merge error.
salsolatragus Feb 2, 2021
059a5e5
test timing fix
mpdeimos Feb 3, 2021
7563980
error logging
mpdeimos Feb 12, 2021
e13ce46
test name validation
mpdeimos Feb 12, 2021
083ea6d
Extract Tia test baseclass.
salsolatragus Feb 19, 2021
f850e52
Abstract test setup.
salsolatragus Feb 19, 2021
515f5c9
Restructure test infrastructure.
salsolatragus Feb 23, 2021
1a4fb06
Remove TiaTestee.
salsolatragus Feb 23, 2021
c07b91b
Simplify testee.
salsolatragus Feb 23, 2021
ee83cde
Reduce visibility.
salsolatragus Feb 23, 2021
8017b25
Specify bitness on testee rather than profiler.
salsolatragus Feb 24, 2021
5f36782
Add performance testee.
salsolatragus Feb 24, 2021
7f5505f
Configure Commons to build a nuget package.
salsolatragus Mar 2, 2021
f0eca90
Remove unused import.
salsolatragus Mar 2, 2021
8657ed2
Add logging to commander.
salsolatragus Mar 2, 2021
577373d
Merge remote-tracking branch 'origin/tia_report' into tia
salsolatragus Mar 2, 2021
601669b
Performance improvements:
mpdeimos Mar 2, 2021
cfb259b
Merge branch 'tia' of https://github.com/cqse/teamscale-profiler-dotn…
mpdeimos Mar 2, 2021
d52ecaf
Add missing dependency to commander.
salsolatragus Mar 8, 2021
4cc5eb5
support test path prefixes
mpdeimos Feb 12, 2021
5907e52
correct emptiness handling for testwise traces
mpdeimos Feb 12, 2021
d0c4f3e
Add some interface comments.
salsolatragus Mar 10, 2021
e561a15
Reduce default log level to Info.
salsolatragus Mar 10, 2021
609bdfd
Add improvements to branch
Raphael-N Sep 8, 2021
8c869e9
Add comments and fix Testee bitness
Raphael-N Oct 4, 2021
975801d
fix empty traces
mpdeimos Mar 16, 2021
4cafeeb
* keep existing tests also for report merge
mpdeimos Mar 16, 2021
f7503c2
remove support for known test cases
mpdeimos Mar 17, 2022
793f93b
add support for partial coverage reports
mpdeimos Mar 17, 2022
e6c7c79
Potential Fix for crashes at Healthineers
Raphael-N Mar 22, 2022
244bc12
Fix casing
mpdeimos Mar 24, 2022
c780e5f
Commander CLI
mpdeimos Mar 24, 2022
ef2410a
Commander Server
mpdeimos Mar 24, 2022
717a669
Review
mpdeimos Apr 1, 2022
6717a8e
review
mpdeimos Apr 12, 2022
b083f25
add logging
mpdeimos Apr 13, 2022
7cece30
add quiet mode
mpdeimos Apr 13, 2022
889d158
additional null checks
mpdeimos Apr 13, 2022
3d3a934
add nullable library
mpdeimos Apr 13, 2022
823bac7
forbid setting test name to null
mpdeimos Apr 13, 2022
f1a85b3
🤦
mpdeimos Apr 13, 2022
4e08202
better error handling
mpdeimos Apr 13, 2022
725cbe5
Merge pull request #160 from cqse/tia_server_cli
Raphael-N Apr 25, 2022
af822fe
Update Platform version and toolset
Raphael-N Apr 26, 2022
59171c6
Remove ifdefs, rework, add tga toggle to options
Raphael-N Apr 26, 2022
e1ca972
Swap vectors instead of using a toggle boolean
Raphael-N Apr 28, 2022
9afa9aa
Rename method id vectors to primary and backing vectors
Raphael-N Apr 28, 2022
c57da74
Merge pull request #155 from cqse/tia-merge-reports
Raphael-N Apr 28, 2022
6bde083
Add tests for tga and tia configurations
Raphael-N May 12, 2022
776e0bd
Implement int set to achieve faster checks
Raphael-N May 22, 2022
ef52fae
Add documentation to custom set implementation
Raphael-N Jun 1, 2022
c5e0762
Merge branch 'tia' into performance_improvements_tia
Raphael-N Jun 1, 2022
b3d64f2
Fix minor issue
Raphael-N Jun 1, 2022
122a357
Rework
Raphael-N Jun 7, 2022
0bd6864
Merge pull request #158 from cqse/performance_improvements_tia
mpdeimos Jun 8, 2022
3e0225e
Fix issue in functionId_set
Raphael-N Jul 4, 2022
b09bc74
update bummer/update output path
mpdeimos Jul 8, 2022
04d1980
bummer update
mpdeimos Jul 14, 2022
6aeea2c
fix tests
mpdeimos Jul 14, 2022
ec9d95f
Use newer libzmq commands for context shutdown and add timeout to sub…
Raphael-N Aug 1, 2022
68bd98f
pre-initialize profiler ipc
mpdeimos Aug 10, 2022
37db7ce
Add documentation for TIA mode catch in shutdown
Raphael-N Jan 18, 2023
907d385
Merge branch 'master' into tia
Raphael-N Feb 8, 2023
1833413
Fix Test cases
Raphael-N Feb 8, 2023
6f5659f
Consider testwise coverage for artifactory uploads
Raphael-N May 19, 2023
0866873
Change name for artifactory report upload
Raphael-N Jun 16, 2023
ef114a8
Merge branch 'master' into tia
Raphael-N Jun 21, 2023
732af2b
Fix Test after merge
Raphael-N Jun 23, 2023
df39b8d
Remove Worker thread due to issues with many processes
Raphael-N Jul 24, 2023
34570e4
Add Zipping step to Artifactory Upload
Raphael-N Jul 30, 2023
eb09de3
Fix Artifactory Upload
Raphael-N Jul 30, 2023
7e6b4ee
Improve artifactory branches
Raphael-N Jul 30, 2023
13a4cc6
add dialog for recording test duration
Aug 1, 2023
265f77d
implement long <-> string conversion for duration
Aug 1, 2023
488b600
send adjusted duration to profiler
Aug 1, 2023
0013465
fix bugs
Aug 1, 2023
77f704a
fix teamscale findings
Aug 1, 2023
a14794b
Start implementing synchronous communication
Raphael-N Aug 2, 2023
25cc661
Add Socket handling
Raphael-N Aug 2, 2023
352cd4f
Support time configuration in profiler and daemon
Raphael-N Aug 2, 2023
82e4720
Use milliseconds for automated tests
Raphael-N Aug 2, 2023
1af9253
Fix some communication issues
Raphael-N Aug 3, 2023
48ec74d
rework
Aug 3, 2023
69c2fdf
update to newer framework version
Aug 4, 2023
50c49b8
malformed trace lines should not crash upload daemon
Aug 4, 2023
89f82ef
Send PID to ZmqIpcServer as clientID
Aug 4, 2023
b12a785
Update TargetFrameworkVersion in UploadDaemon_Test
Aug 4, 2023
96e5746
rework
Raphael-N Aug 7, 2023
82a9680
Rework
Raphael-N Aug 7, 2023
474fa63
Write as one string instead of per entry
Raphael-N Aug 7, 2023
78b8d62
Add synchronization to jit inlining events
Raphael-N Aug 9, 2023
1a961c8
Fix casing of results
Raphael-N Aug 17, 2023
8e94aa4
Merge branch 'tia_synchronous_events' of https://github.com/cqse/team…
Raphael-N Aug 17, 2023
269a07e
Disable inlining for accurate results
Raphael-N Aug 17, 2023
c584514
Merge pull request #180 from cqse/test-commander-change-duration
Raphael-N Aug 18, 2023
fa7ea27
Fix encoding of test names
Raphael-N Aug 29, 2023
c6fe173
Update Test Times and Add Checks for running Tests
Raphael-N Sep 19, 2023
a16e337
Fix initial test not appearing
Raphael-N Sep 22, 2023
652929c
Fix Process not shutting down
Raphael-N Sep 22, 2023
306ab2e
Improve performance of Upload Daemon
Raphael-N Sep 22, 2023
82c75f9
TS#35530 Check if the trace directory is writable
Raphael-N Sep 25, 2023
77630df
Fix issue with time sending
Raphael-N Oct 4, 2023
0485275
Reduce Memory Usage
Raphael-N Oct 27, 2023
6ef1bcf
Replace newline with space in testname
Raphael-N Oct 27, 2023
668537d
Implement Splitting for too large reports
Raphael-N Oct 30, 2023
7db2f6d
Merge branch 'tia' into tia_synchronous_events
Raphael-N Nov 27, 2023
5d1bb79
Cleanup leftovers from merge
Raphael-N Nov 29, 2023
5aa9762
Minor fixes
Raphael-N Jan 10, 2024
db12283
Fix several Teamscale findings
Raphael-N Jan 26, 2024
ca0da28
Add String report splitting for other upload types
Raphael-N Jan 31, 2024
9311980
Small fixes
Raphael-N Feb 27, 2024
a239651
Fix tests and socket configurations
Raphael-N Feb 28, 2024
20fa0fe
Fix Tests
Raphael-N Mar 20, 2024
62a1aeb
Update tests
Raphael-N Apr 10, 2024
a192408
More Test fixes and add back pipeline
Raphael-N Apr 12, 2024
b0ef272
Merge pull request #183 from cqse/tia_synchronous_events
Raphael-N Apr 12, 2024
38c11b4
Merge branch 'master' into tia
Raphael-N Jun 21, 2024
5160d84
Merge branch 'tia' of https://github.com/cqse/teamscale-profiler-dotn…
Raphael-N Jun 21, 2024
6800edd
Fix merge leftovers
Raphael-N Jun 26, 2024
0a63d9c
TS#38029 Fix remaining tests
Raphael-N Jul 10, 2024
a43ce20
Merge branch 'master' into tia
Raphael-N Jul 10, 2024
e71d373
TS#38029 Update Profiler Testee
Raphael-N Jul 10, 2024
91c8a68
TS#38029 Introduce AssemblyExtractor to fix EmbeddudUploadTarget Hand…
Raphael-N Jul 15, 2024
bd3289a
TS#38029 Fix TS findings
Raphael-N Jul 15, 2024
d660612
TS#38029 Rework functionId_set
Raphael-N Jul 22, 2024
a4a70c8
TS#38029 Refactor trace file parsing
Raphael-N Aug 1, 2024
55b4ec4
TS#38029 Fix leftover issues from TraceFileParser rework
Raphael-N Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
multipart tia start/end
mpdeimos committed Jan 26, 2021
commit 519a256e0bbe7aba3346ea17bb445b2371d42c0a
13 changes: 12 additions & 1 deletion Commons/Ipc/IpcServer.cs
Original file line number Diff line number Diff line change
@@ -43,7 +43,18 @@ private Thread StartRequestHandlerThread()

protected abstract void StartPublisher();

public abstract void Publish(string testName);
protected abstract void Publish(params string[] frames);

public void SendTestStart(string testName)
{
Publish("test:start", testName);
}

// FIXME result as enum
public void SendTestEnd(string result = "", string message = "")
{
Publish("test:end", result, message);
}

public virtual void Dispose()
{
2 changes: 1 addition & 1 deletion Commons/Ipc/ProfilerIpc.cs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ public string TestName
else
{
testName = value;
ipcServer.Publish(testName);
ipcServer.SendTestStart(testName);
}
}
}
5 changes: 3 additions & 2 deletions Commons/Ipc/ZmqIpcServer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Linq;

namespace Cqse.Teamscale.Profiler.Commons.Ipc
{
@@ -36,9 +37,9 @@ override protected void StartPublisher()
this.publishSocket.Bind(this.config.PublishSocket);
}

public override void Publish(string testName)
protected override void Publish(params string[] frames)
{
this.publishSocket.SendFrame(testName);
this.publishSocket.SendMultipartMessage(new NetMQMessage(frames.Select(frame => new NetMQFrame(frame))));
}

public override void Dispose()
25 changes: 20 additions & 5 deletions Profiler/CProfilerCallback.cpp
Original file line number Diff line number Diff line change
@@ -137,11 +137,12 @@ HRESULT CProfilerCallback::InitializeImplementation(IUnknown* pICorProfilerInfoU
if (config.isTiaEnabled()) {
traceLog.info("TIA enabled. SUB: " + config.getTiaSubscribeSocket() + " REQ: " + config.getTiaRequestSocket());
enableFunctionHooks = true;
std::function<void(std::string)> callback = std::bind(&CProfilerCallback::onTestChanged, this, std::placeholders::_1);
this->ipc = new Ipc(&this->config, callback);
std::function<void(std::string)> testStartCallback = std::bind(&CProfilerCallback::onTestStart, this, std::placeholders::_1);
std::function<void(std::string, std::string)> testEndCallback = std::bind(&CProfilerCallback::onTestEnd, this, std::placeholders::_1, std::placeholders::_2);
this->ipc = new Ipc(&this->config, testStartCallback, testEndCallback);
std::string testName = this->ipc->getCurrentTestName();
if (!testName.empty()) {
traceLog.logTestCase(testName);
traceLog.startTestCase(testName);
}
}
#endif
@@ -537,13 +538,27 @@ int CProfilerCallback::writeFileVersionInfo(LPCWSTR assemblyPath, char* buffer,

#ifdef TIA

void CProfilerCallback::onTestChanged(std::string testName)
void CProfilerCallback::onTestStart(std::string testName)
{
if (config.isProfilingEnabled() && config.isTiaEnabled()) {
EnterCriticalSection(&callbackSynchronization);

writeFunctionInfosToLog();
traceLog.logTestCase(testName);
traceLog.startTestCase(testName);

calledMethodIds.clear();

LeaveCriticalSection(&callbackSynchronization);
}
}

void CProfilerCallback::onTestEnd(std::string result, std::string message)
{
if (config.isProfilingEnabled() && config.isTiaEnabled()) {
EnterCriticalSection(&callbackSynchronization);

writeFunctionInfosToLog();
traceLog.endTestCase(result, message);

calledMethodIds.clear();

9 changes: 6 additions & 3 deletions Profiler/CProfilerCallback.h
Original file line number Diff line number Diff line change
@@ -102,8 +102,11 @@ class CProfilerCallback : public CProfilerCallbackBase {
/** Inter-process connection for TIA communication. null if not in TIA mode. */
Ipc* ipc = NULL;

/** Callback that is being called when a testcase changes. */
void onTestChanged(std::string testName);
/** Callback that is being called when a testcase starts. */
void onTestStart(std::string testName);

/** Callback that is being called when a testcase ends. */
void onTestEnd(std::string result = "", std::string message = "");

/**
* Keeps track of called methods.
@@ -119,7 +122,7 @@ class CProfilerCallback : public CProfilerCallbackBase {

/** Callback on function enter. */
static void __stdcall onFunctionEnterStatic(FunctionID funcId, UINT_PTR clientData, COR_PRF_FRAME_INFO func, COR_PRF_FUNCTION_ARGUMENT_INFO* argumentInfo);

/** Callback on function enter. */
void onFunctionEnter(FunctionID funcId);
#endif
30 changes: 28 additions & 2 deletions Profiler/log/TraceLog.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
#include <winuser.h>
#include "utils/WindowsUtils.h"
#include <string>
#include <regex>

TraceLog::~TraceLog() {
// Nothing to do here, destructing is handled in FileLogBase
@@ -83,9 +84,34 @@ void TraceLog::logAssembly(std::string assembly)
writeTupleToFile(LOG_KEY_ASSEMBLY, assembly.c_str());
}

void TraceLog::logTestCase(std::string testName)
#ifdef TIA
void TraceLog::startTestCase(std::string testName)
{
writeTupleToFile(LOG_KEY_TESTCASE, testName.c_str());
// Line will look like this:
// Test=Start:20150601_1220270707:Test Name\: 1:something we do not know yet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the upload daemon does not support escaping by \:.

std::string info = "Start:" + getFormattedCurrentTime() + ":" + escape(testName);
writeTupleToFile(LOG_KEY_TESTCASE, info.c_str());
}

void TraceLog::endTestCase(std::string result, std::string message)
{
// Line will look like this:
// Test=End:20150601_1220280807:PASSED:optional msg
std::string info = "End:" + getFormattedCurrentTime();
if (!result.empty()) {
info += ":" + result;
if (!message.empty()) {
info += ":" + message;
}
}

writeTupleToFile(LOG_KEY_TESTCASE, info.c_str());
}
#endif

inline std::string TraceLog::escape(std::string message) {
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
static std::regex colonEscape(":");
return std::regex_replace(message, colonEscape, "\\:");
}

void TraceLog::shutdown() {
8 changes: 7 additions & 1 deletion Profiler/log/TraceLog.h
Original file line number Diff line number Diff line change
@@ -55,7 +55,10 @@ class TraceLog : public FileLogBase
/** Writes info about a profiled assembly into the log. Should only be called once. */
void logAssembly(std::string assembly);

void logTestCase(std::string testName);
#ifdef TIA
void startTestCase(std::string testName);
void endTestCase(std::string result = "", std::string message = "");
#endif

protected:
/** The key to log information about the profiler startup. */
@@ -102,4 +105,7 @@ class TraceLog : public FileLogBase

/** Write all information about the given function to the log. */
void writeSingleFunctionInfoToLog(const char* key, FunctionInfo& info);

/** Escapes the messages by putting a backslash before special characters, e.g. escapes the colon : -> \:. */
std::string escape(std::string message);
};
56 changes: 48 additions & 8 deletions Profiler/utils/Ipc.cpp
Original file line number Diff line number Diff line change
@@ -9,10 +9,11 @@
// ZMQ strings are not zero-terminated, let's terminate these
#define IPC_TERMINATE_STRING(buffer, len) buffer[len < IPC_BUFFER_SIZE ? len : IPC_BUFFER_SIZE - 1] = '\0'

Ipc::Ipc(Config* config, std::function<void(std::string)> testChangedCallback)
Ipc::Ipc(Config* config, std::function<void(std::string)> testStartCallback, std::function<void(std::string, std::string)> testEndCallback)
{
this->config = config;
this->testChangedCallback = testChangedCallback;
this->testStartCallback = testStartCallback;
this->testEndCallback = testEndCallback;
this->zmqTimeout = IPC_TIMEOUT_MS;
this->zmqContext = zmq_ctx_new();

@@ -36,20 +37,59 @@ Ipc::~Ipc()

void Ipc::handlerThreadLoop() {
this->zmqSubscribeSocket = zmq_socket(this->zmqContext, ZMQ_SUB);
zmq_setsockopt(this->zmqSubscribeSocket, ZMQ_SUBSCRIBE, "", 0);
zmq_setsockopt(this->zmqSubscribeSocket, ZMQ_SUBSCRIBE, "test:", 0);
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
zmq_setsockopt(this->zmqSubscribeSocket, ZMQ_RCVTIMEO, &zmqTimeout, sizeof(zmqTimeout));
zmq_connect(this->zmqSubscribeSocket, config->getTiaSubscribeSocket().c_str());
char buffer[IPC_BUFFER_SIZE];

/// Alternative way to read messages
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
//char buffer[IPC_BUFFER_SLOTS][IPC_BUFFER_SIZE];
//while (!this->shutdown) {
// int len = zmq_recv(this->zmqSubscribeSocket, &buffer[0], IPC_BUFFER_SIZE - 1, 0);
// if (len >= 0) {
// IPC_TERMINATE_STRING(buffer[0], len);
// this->testStartCallback(buffer[0]);
// }
//}

std::vector<std::string> frames;
zmq_msg_t message;
while (!this->shutdown) {
int len = zmq_recv(this->zmqSubscribeSocket, &buffer, IPC_BUFFER_SIZE - 1, 0);
if (len >= 0) {
IPC_TERMINATE_STRING(buffer, len);
this->testChangedCallback(buffer);
zmq_msg_init(&message);
do {
int len = zmq_msg_recv(&message, this->zmqSubscribeSocket, 0);
if (len >= 0) {
frames.push_back(std::string((char*)zmq_msg_data(&message), zmq_msg_size(&message)));
}
} while (zmq_msg_more(&message));

if (!frames.empty()) {
handleMessage(frames);
frames.clear();
}
zmq_msg_close(&message);
}
zmq_close(this->zmqSubscribeSocket);
}

void Ipc::handleMessage(std::vector<std::string> frames) {
if (frames[0] == "test:start" && frames.size() > 1) {
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
this->testStartCallback(frames[1]);
}
else if (frames[0] == "test:end") {
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
std::string result = "";
if (frames.size() > 1) {
result = frames[1];
}

std::string message = "";
if (frames.size() > 2) {
message = frames[2];
}

this->testEndCallback(result, message);
}
}

std::string Ipc::getCurrentTestName()
{
return this->request("get_testname");
Raphael-N marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions Profiler/utils/Ipc.h
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
class Ipc
{
public:
Ipc(Config* config, std::function<void(std::string)> testChangedCallback);
Ipc(Config* config, std::function<void(std::string)> testStartCallback, std::function<void(std::string, std::string)> testEndCallback);
~Ipc();
std::string getCurrentTestName();
private:
@@ -18,9 +18,11 @@ class Ipc
void* zmqSubscribeSocket = NULL;
Config* config = NULL;
std::thread* handlerThread = NULL;
std::function<void(std::string)> testChangedCallback;
std::function<void(std::string)> testStartCallback;
std::function<void(std::string, std::string)> testEndCallback;
std::atomic<bool> shutdown = false;
void handlerThreadLoop();
void handleMessage(std::vector<std::string> frames);
void initRequestSocket();
std::string request(std::string message);
};
7 changes: 4 additions & 3 deletions Profiler_Test/Tia/NativeZmqIpcServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cqse.Teamscale.Profiler.Commons.Ipc;
using System.Linq;
using System.Threading;
using ZeroMQ;

@@ -37,11 +38,11 @@ override protected void StartPublisher()
publishSocket.Bind(this.config.PublishSocket);
}

public override void Publish(string testName)
protected override void Publish(params string[] frames)
{
using (var frame = new ZFrame(testName))
using (var msg = new ZMessage(frames.Select(frame => new ZFrame(frame))))
{
publishSocket.Send(frame);
publishSocket.Send(msg);
}
}

6 changes: 3 additions & 3 deletions Profiler_Test/Tia/TiaProfilerTest.cs
Original file line number Diff line number Diff line change
@@ -256,11 +256,11 @@ internal static List<TestCase> FromTraceLines(IEnumerable<string> traceLines)
testCases.Add(new TestCase(string.Empty, currentLines));
foreach (var line in traceLines)
{
if (line.StartsWith("Test="))
if (line.StartsWith("Test=Start:"))
{
string currentTest = line.Substring("Test=".Length);
string[] parts = line.Substring("Test=".Length).Split(':');
currentLines = new List<string>();
testCases.Add(new TestCase(currentTest, currentLines));
testCases.Add(new TestCase(parts[2], currentLines));
}

currentLines.Add(line);