Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into tia
  • Loading branch information
Raphael-N committed Jun 21, 2024
2 parents 38c11b4 + b0ef272 commit 5160d84
Show file tree
Hide file tree
Showing 49 changed files with 664 additions and 688 deletions.
40 changes: 38 additions & 2 deletions .teamscale.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
server.url = "https://cqse.teamscale.io/"
project.id = "teamscale-net-profiler"
# The Teamscale IDE configuration file format version of this file.

version = "1.0" # Optional, default: 1.0

# Whether this is the root config file.
# If true, configuration discovery stops at this file and does not continue upwards to the filesystem root.

root = true # Optional, default: false

[server]

# The URL of the Teamscale server.
# If set, it must match the URL of a server for which credentials (Username, Access Key) have been configured in the respective IDE.

url = "https://cqse.teamscale.io/" # Optional, but must be set in the merged configuration

[project]

# The Project ID (or one of its Alternative Project IDs) of the Teamscale project.
# Note that the Project ID may be different from the more prominently displayed Project Name.
#
# If a .teamscale.toml file sets the project.id and does not set project.path
# explicitly, then it implicitly sets project.path = "" (i.e., associates the
# current folder with the root folder of the Teamscale project).

id = "teamscale-net-profiler" # Optional, but must be set in the merged configuration

# The branch to use for retrieving data from the server.
#
# If empty or unset, the applicable branch is discovered from the VCS, with the
# Teamscale default branch being a fallback.
# If set and non-empty, branch auto-discovery is not used. Instead, the given branch is used

# The code path within the Teamscale project on the server.
#
# Paths from parent configs will be overwritten.
# Forward-slashes are used as path separators.
# If empty (i.e., path = ""), the Teamscale project root is used as code path.
11 changes: 8 additions & 3 deletions Commander.Server/ProfilerTestController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cqse.Teamscale.Profiler.Commons.Ipc;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Text.Json.Serialization;
using System.Web;
using System.Xml.Linq;
Expand Down Expand Up @@ -31,7 +32,7 @@ public long GetStart()
}

[HttpPost("start/{testName}")]
public void StartTest(string testName)
public HttpStatusCode StartTest(string testName)
{
if (string.IsNullOrEmpty(testName))
{
Expand All @@ -41,25 +42,29 @@ public void StartTest(string testName)
logger.LogInformation("Starting test: {}", testName);
profilerIpc.TestStartMS = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
profilerIpc.StartTest(HttpUtility.UrlDecode(testName));
return HttpStatusCode.NoContent;
}

[HttpPost("stop/{result}")]
public void StopTest(TestExecutionResult result)
public HttpStatusCode StopTest(TestExecutionResult result)
{
long testEnd = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
logger.LogInformation("Stopping test (JaCoCo endpoint): {}; Result: {}; duration: {}", GetCurrent(), result, testEnd - GetStart());
profilerIpc.EndTest(result, durationMs: testEnd - GetStart());
return HttpStatusCode.NoContent;
}

/// <summary>
/// Legacy end test to match the JaCoCo API.
/// </summary>
[HttpPost("end/{name}")]
public void EndTest(string name, [FromBody] TestResultDto result)
public HttpStatusCode EndTest(string name, [FromBody] TestResultDto result)
{
long testEnd = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
logger.LogInformation("Stopping test (JaCoCo endpoint): {}; Result: {}; duration: {}", name, result.Result, testEnd - GetStart());
profilerIpc.EndTest(result.Result, durationMs: testEnd - GetStart());

return HttpStatusCode.NoContent;
}

public class TestResultDto
Expand Down
4 changes: 2 additions & 2 deletions Commander/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ protected override void OnExit(ExitEventArgs e)
profilerIpc.Dispose();
}

internal void EndTest(TestExecutionResult result, string message = "", long durationMs = 0)
internal void EndTest(TestExecutionResult result, long durationMs = 0)
{
profilerIpc.EndTest(result, message, durationMs);
profilerIpc.EndTest(result, durationMs);
}

internal void StartTest(string testName = null)
Expand Down
2 changes: 1 addition & 1 deletion Commons/Commons.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net4.8</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net48</TargetFrameworks>
<RootNamespace>Cqse.Teamscale.Profiler.Commons</RootNamespace>
<AssemblyName>Cqse.Teamscale.Profiler.Commons</AssemblyName>
<Version>1.0.0</Version>
Expand Down
15 changes: 12 additions & 3 deletions Commons/Ipc/IpcConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Cqse.Teamscale.Profiler.Commons.Ipc
using System;
using System.Linq;

namespace Cqse.Teamscale.Profiler.Commons.Ipc
{
/// <summary>
/// Configuration for ZeroMQ IPC.
Expand All @@ -15,7 +18,12 @@ public class IpcConfig
/// The ZeroMQ socket to receive and answer requests from subscribed profilers via REQ-REP pattern.
/// Default ist localhost TCP port 7146 (leet for TIA-Socket + 1 = 7145 + 1)
/// </summary>
public string RequestSocket { get; } = "tcp://127.0.0.1:7146";
public string RequestSocket { get; } = "tcp://127.0.0.1";

/// <summary>
/// The intial port number. As new .Net Profiler instances are registered, this is changed so each one has its own port.
/// </summary>
public int StartPortNumber { get; } = 7146;

public IpcConfig()
{
Expand All @@ -25,7 +33,8 @@ public IpcConfig()
public IpcConfig(string publishSocket, string requestSocket)
{
PublishSocket = publishSocket;
RequestSocket = requestSocket;
RequestSocket = requestSocket.Substring(0, requestSocket.LastIndexOf(':')) ;
StartPortNumber = Int32.Parse(requestSocket.Split(':').Last());
}
}
}
61 changes: 0 additions & 61 deletions Commons/Ipc/IpcServer.cs

This file was deleted.

41 changes: 28 additions & 13 deletions Commons/Ipc/ProfilerIpc.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using NLog;
using System;
using System.Text.RegularExpressions;

namespace Cqse.Teamscale.Profiler.Commons.Ipc
{
public class ProfilerIpc : IDisposable
{

Check warning on line 8 in Commons/Ipc/ProfilerIpc.cs

View check run for this annotation

cqse.teamscale.io / teamscale-findings

Commons/Ipc/ProfilerIpc.cs#L7-L8

Interface comment missing https://cqse.teamscale.io/findings/details/teamscale-net-profiler?t=tia%3AHEAD&id=38EC8BA5BE026350B1CA7BAADE5569A0
private static readonly Logger logger = LogManager.GetCurrentClassLogger();

private readonly IpcServer ipcServer;
private readonly ZmqIpcServer ipcServer;

/// <summary>
/// The name of the current test, empty string if no test is running.
Expand All @@ -24,7 +25,7 @@ public ProfilerIpc(IpcConfig config)
this.ipcServer = CreateIpcServer(config);
}

protected virtual IpcServer CreateIpcServer(IpcConfig config)
protected virtual ZmqIpcServer CreateIpcServer(IpcConfig config)
{

Check warning on line 29 in Commons/Ipc/ProfilerIpc.cs

View check run for this annotation

cqse.teamscale.io / teamscale-findings

Commons/Ipc/ProfilerIpc.cs#L28-L29

Interface comment missing https://cqse.teamscale.io/findings/details/teamscale-net-profiler?t=tia%3AHEAD&id=C28FDFFFDEB1D0745D97EF41CBDAB4BD
logger.Info("Starting IPC server (PUB={pub}, REQ={req})", config.PublishSocket, config.RequestSocket);
return new ZmqIpcServer(config, this.HandleRequest);
Expand All @@ -34,9 +35,13 @@ protected virtual string HandleRequest(string message)
{

Check warning on line 35 in Commons/Ipc/ProfilerIpc.cs

View check run for this annotation

cqse.teamscale.io / teamscale-findings

Commons/Ipc/ProfilerIpc.cs#L34-L35

Interface comment missing https://cqse.teamscale.io/findings/details/teamscale-net-profiler?t=tia%3AHEAD&id=368C6B659242B42589736B988E7C4151
switch (message)
{
case "get_testname":
logger.Info("Received request get_testname. Response {testName}", TestName);
return TestName;
case "testname":
logger.Info("Received request get_testname. Response {testName}", this.TestName);
if (this.TestName == string.Empty)
{
return string.Empty;
}
return $"start:{this.TestName}";
default:
logger.Info("Received request: {request}.", message);
return string.Empty;
Expand All @@ -47,19 +52,29 @@ public void StartTest(string testName)
{
if (string.IsNullOrEmpty(testName))
{
throw new ArgumentException("Test name may not be empty or null");
throw new ArgumentException("Test name must not be empty or null");
}

logger.Info("Broadcasting start of test {testName}", testName);
this.TestName = testName;
ipcServer.Publish("test:start", testName);
if (this.TestName != string.Empty)
{
logger.Info("Starting a new test while a test is still active. Ending active Test with result Skipped since actual result is unknown.");
this.EndTest(TestExecutionResult.Skipped);
}
String cleanedTestName = testName.Replace("\n", " ").Replace("\r", " ");
logger.Info("Broadcasting start of test {testName}", cleanedTestName);
this.TestName = cleanedTestName;
ipcServer.SendTestEvent($"start:{cleanedTestName}");
}

public void EndTest(TestExecutionResult result, string message = "", long durationMs = 0)
public void EndTest(TestExecutionResult result, long durationMs = 0)
{
logger.Info("Broadcasting end of test {testName} with result {result} with duration {duration}", TestName, result, durationMs);
if (TestName == string.Empty)
{
logger.Info("Testname is empty. Result {result} cannot be associated with a testname and is not broadcasted with duration {duration}.", TestName, result, durationMs);
return;
}
logger.Info("Broadcasting end of test {testName} with result {result}", TestName, result);
this.TestName = string.Empty;
ipcServer.Publish("test:end", Enum.GetName(typeof(TestExecutionResult), result).ToUpper(), message, durationMs.ToString());
ipcServer.SendTestEvent($"end:{Enum.GetName(typeof(TestExecutionResult), result).ToUpper()}:{durationMs}");
}

public void Dispose()
Expand Down
Loading

0 comments on commit 5160d84

Please sign in to comment.