Skip to content

Commit

Permalink
[server] Add trace properties to the Trace instance
Browse files Browse the repository at this point in the history
The purpose of this commit is to get the trace properties using
tsp. The "properties" attribute will be in the trace instance,
and it will be filled if the opened trace implements
ITmfPropertiesProviders.

Example:
{
  "name": "string",
  "path": "string",
  "nbEvents": 0,
  "start": 0,
  "indexingStatus": "RUNNING",
  "end": 0,
  "properties":
  {
	"hostname": "qemu1",
        "clock_offset": "1450192743562703624"
  },
  "UUID": "f50af7e0-0dd5-4361-ab96-2e04f7bc7e30"
}

[Added] "properties" field in the returned Trace instance
[Added] a separate trace instrance will be created when "/traces" is queried
[Changed] /experiment endpoint will use Trace.from(ITmfTrace) to get more info of the trace

Signed-off-by: Siwei Zhang <[email protected]>
  • Loading branch information
Siwei Zhang authored and bhufmann committed Sep 26, 2024
1 parent ad96ce3 commit 2386d1d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2021 Ericsson
* Copyright (c) 2018, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -12,6 +12,7 @@
package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs;

import java.nio.charset.Charset;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

Expand All @@ -37,6 +38,7 @@ public class TraceModelStub extends AbstractModelStub {
private static final long serialVersionUID = -1030854786688167776L;

private final String fPath;
private final Map<String, String> fProperties;

/**
* {@link JsonCreator} Constructor for final fields
Expand All @@ -53,6 +55,8 @@ public class TraceModelStub extends AbstractModelStub {
* start time
* @param end
* end time
* @param properties
* the properties of the trace
* @param indexingStatus
* indexing status
*/
Expand All @@ -64,9 +68,11 @@ public TraceModelStub(
@JsonProperty("nbEvents") long nbEvents,
@JsonProperty("start") long start,
@JsonProperty("end") long end,
@JsonProperty("properties") Map<String, String> properties,
@JsonProperty("indexingStatus") String indexingStatus) {
super(name, uuid, nbEvents, start, end, indexingStatus);
fPath = path;
fProperties = properties;
}

/**
Expand All @@ -76,9 +82,11 @@ public TraceModelStub(
* trace name
* @param path
* path to trace on server file system
* @param properties
* properties of the trace
*/
public TraceModelStub(String name, String path) {
this(name, path, getUUID(path, name), 0, 0L, 0L, "RUNNING");
public TraceModelStub(String name, String path, Map<String, String> properties) {
this(name, path, getUUID(path, name), 0, 0L, 0L, properties, "RUNNING");
}

private static UUID getUUID(String path, String name) {
Expand All @@ -95,6 +103,14 @@ public String getPath() {
return fPath;
}

/**
* Returns the trace's properties
* @return the trace's properties
*/
public Map<String, String> getProperties() {
return fProperties;
}

@Override
public String toString() {
return getName() + ": <UUID=" + getUUID() + ", path=" + fPath + '>'; //$NON-NLS-1$ //$NON-NLS-2$
Expand All @@ -111,7 +127,7 @@ public boolean equals(Object obj) {
return false;
} else if (obj instanceof TraceModelStub) {
TraceModelStub other = (TraceModelStub) obj;
return Objects.equals(fPath, other.fPath);
return Objects.equals(fPath, other.fPath) && Objects.equals(fProperties, other.fProperties);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2021 Ericsson
* Copyright (c) 2018, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -162,6 +162,19 @@ public abstract class RestServerTest {
*/
protected static final String CONTEXT_SWITCHES_UST_NAME = "ust";

/**
* The properties of the trace.
*/
public static final Map<String, String> CONTEXT_SWITCHES_UST_PROPERTIES = new HashMap<>(Map.ofEntries(
Map.entry("hostname", "\"qemu1\""),
Map.entry("clock_offset", "1450192743562703624"),
Map.entry("domain", "\"ust\""),
Map.entry("host ID", "\"40b6dd3a-c130-431e-92ef-8c4dafe14627\""),
Map.entry("tracer_name", "\"lttng-ust\""),
Map.entry("tracer_major", "2"),
Map.entry("tracer_minor", "6")
));

/**
* {@link TraceModelStub} to represent the object returned by the server for
* {@link CtfTestTrace#CONTEXT_SWITCHES_KERNEL}.
Expand All @@ -173,6 +186,23 @@ public abstract class RestServerTest {
*/
protected static final String CONTEXT_SWITCHES_KERNEL_NAME = "kernel";

/**
* The properties of the trace.
*/
public static final Map<String, String> CONTEXT_SWITCHES_KERNEL_PROPERTIES = new HashMap<>(Map.ofEntries(
Map.entry("hostname", "\"qemu1\""),
Map.entry("kernel_version", "\"#1 SMP PREEMPT Sat Dec 12 14:52:43 CET 2015\""),
Map.entry("tracer_patchlevel", "3"),
Map.entry("clock_offset", "1450192747804379176"),
Map.entry("domain", "\"kernel\""),
Map.entry("sysname", "\"Linux\""),
Map.entry("host ID", "\"40b6dd3a-c130-431e-92ef-8c4dafe14627\""),
Map.entry("kernel_release", "\"4.1.13-WR8.0.0.0_standard\""),
Map.entry("tracer_name", "\"lttng-modules\""),
Map.entry("tracer_major", "2"),
Map.entry("tracer_minor", "6")
));

/**
* {@link TraceModelStub} to represent the object returned by the server for
* {@link CtfTestTrace#ARM_64_BIT_HEADER}, with the same name as {@link #CONTEXT_SWITCHES_KERNEL_STUB}
Expand All @@ -184,6 +214,23 @@ public abstract class RestServerTest {
*/
protected static final String ARM_64_KERNEL_NAME = "kernel";

/**
* The properties of the trace.
*/
public static final Map<String, String> ARM_64_KERNEL_PROPERTIES = new HashMap<>(Map.ofEntries(
Map.entry("hostname", "\"lager\""),
Map.entry("kernel_version", "\"#6 SMP PREEMPT Wed Oct 1 17:07:11 CEST 2014\""),
Map.entry("tracer_patchlevel", "0"),
Map.entry("clock_offset", "1412663327522716450"),
Map.entry("domain", "\"kernel\""),
Map.entry("sysname", "\"Linux\""),
Map.entry("host ID", "\"5a71a43c-1390-4365-9baf-111c565e78c3\""),
Map.entry("kernel_release", "\"3.10.31-ltsi\""),
Map.entry("tracer_name", "\"lttng-modules\""),
Map.entry("tracer_major", "2"),
Map.entry("tracer_minor", "5")
));

/**
* Expected toString() of all data providers for this experiment
*/
Expand All @@ -198,13 +245,13 @@ public abstract class RestServerTest {
@BeforeClass
public static void beforeTest() throws IOException {
String contextSwitchesUstPath = FileLocator.toFileURL(CtfTestTrace.CONTEXT_SWITCHES_UST.getTraceURL()).getPath().replaceAll("/$", "");
CONTEXT_SWITCHES_UST_STUB = new TraceModelStub(CONTEXT_SWITCHES_UST_NAME, contextSwitchesUstPath);
CONTEXT_SWITCHES_UST_STUB = new TraceModelStub(CONTEXT_SWITCHES_UST_NAME, contextSwitchesUstPath, CONTEXT_SWITCHES_UST_PROPERTIES);

String contextSwitchesKernelPath = FileLocator.toFileURL(CtfTestTrace.CONTEXT_SWITCHES_KERNEL.getTraceURL()).getPath().replaceAll("/$", "");
CONTEXT_SWITCHES_KERNEL_STUB = new TraceModelStub(CONTEXT_SWITCHES_KERNEL_NAME, contextSwitchesKernelPath);
CONTEXT_SWITCHES_KERNEL_STUB = new TraceModelStub(CONTEXT_SWITCHES_KERNEL_NAME, contextSwitchesKernelPath, CONTEXT_SWITCHES_KERNEL_PROPERTIES);

String arm64Path = FileLocator.toFileURL(CtfTestTrace.ARM_64_BIT_HEADER.getTraceURL()).getPath().replaceAll("/$", "");
ARM_64_KERNEL_STUB = new TraceModelStub(ARM_64_KERNEL_NAME, arm64Path);
ARM_64_KERNEL_STUB = new TraceModelStub(ARM_64_KERNEL_NAME, arm64Path, ARM_64_KERNEL_PROPERTIES);

ImmutableList.Builder<DataProviderDescriptorStub> b = ImmutableList.builder();
b.add(new DataProviderDescriptorStub("org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.scatter.dataprovider:org.eclipse.linuxtools.lttng2.ust.analysis.callstack",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -11,6 +11,7 @@

package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model;

import java.util.Map;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -59,6 +60,12 @@ public interface Trace {
@Schema(description = "The trace's end time")
long getEnd();

/**
* @return The properties.
*/
@Schema(description = "The trace's properties")
Map<String, String> getProperties();

/**
* @return The indexing status.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Ericsson
* Copyright (c) 2020, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -83,7 +83,7 @@ public Experiment(@JsonProperty("name") String name,
*/
public static Experiment from(TmfExperiment experiment, UUID expUUID) {
List<UUID> traceUUIDs = ExperimentManagerService.getTraceUUIDs(expUUID);
Set<Trace> traces = new LinkedHashSet<>(Lists.transform(traceUUIDs, uuid -> Trace.from(TraceManagerService.getTraceResource(uuid), uuid)));
Set<Trace> traces = new LinkedHashSet<>(Lists.transform(traceUUIDs, uuid -> Trace.from(TraceManagerService.getOrCreateTraceInstance(uuid), uuid)));
return new Experiment(experiment.getName(),
expUUID,
experiment.getNbEvents(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2021 Ericsson
* Copyright (c) 2018, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -210,8 +210,8 @@ public Response deleteExperiment(@Parameter(description = EXP_UUID) @PathParam("
if (resource == null) {
return Response.status(Status.NOT_FOUND).build();
}
Experiment experimentModel = Experiment.from(resource, expUUID);
TmfExperiment experiment = EXPERIMENTS.remove(expUUID);
Experiment experimentModel = experiment != null ? Experiment.from(experiment, expUUID) : Experiment.from(resource, expUUID);
if (experiment != null) {
TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, experiment));
experiment.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Ericsson
* Copyright (c) 2020, 2024 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -12,11 +12,14 @@
package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.tracecompass.tmf.core.io.ResourceUtil;
import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand All @@ -33,6 +36,7 @@ public final class Trace implements Serializable {
private final long fNbEvents;
private final long fStart;
private final long fEnd;
private final Map<String, String> fProperties;
private final String fIndexingStatus;

/**
Expand All @@ -50,6 +54,8 @@ public final class Trace implements Serializable {
* start time
* @param end
* end time
* @param properties
* the properties of the trace
* @param indexingStatus
* indexing status
*/
Expand All @@ -60,13 +66,15 @@ public Trace(@JsonProperty("name") String name,
@JsonProperty("nbEvents") long nbEvents,
@JsonProperty("start") long start,
@JsonProperty("end") long end,
@JsonProperty("properties") Map<String, String> properties,
@JsonProperty("indexingStatus") String indexingStatus) {
fName = name;
fUUID = uuid;
fPath = path;
fNbEvents = nbEvents;
fStart = start;
fEnd = end;
fProperties = properties;
fIndexingStatus = indexingStatus;
}

Expand All @@ -86,6 +94,7 @@ public static Trace from(ITmfTrace trace, UUID uuid) {
trace.getNbEvents(),
trace.getStartTime().toNanos(),
trace.getEndTime().toNanos(),
trace instanceof ITmfPropertiesProvider ? ((ITmfPropertiesProvider) trace).getProperties() : new HashMap<>(),
trace.isIndexing() ? "RUNNING" : "COMPLETED"); //$NON-NLS-1$ //$NON-NLS-2$
}

Expand All @@ -110,6 +119,7 @@ public static Trace from(IResource traceResource, UUID uuid) {
0L,
0L,
0L,
new HashMap<>(),
"CLOSED"); //$NON-NLS-1$
}

Expand Down Expand Up @@ -161,6 +171,14 @@ public long getEnd() {
return fEnd;
}

/**
* Returns the properties
* @return the properties
*/
public Map<String, String> getProperties() {
return fProperties;
}

/**
* Returns the indexing status
* @return the indexing status
Expand All @@ -171,6 +189,6 @@ public String getIndexingStatus() {

@Override
public String toString() {
return "Trace [fName=" + fName + ", fUUID=" + fUUID + ", fPath=" + fPath + ", fNbEvents=" + fNbEvents + ", fStart=" + fStart + ", fEnd=" + fEnd + ", fIndexingStatus=" + fIndexingStatus + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
return "Trace [fName=" + fName + ", fUUID=" + fUUID + ", fPath=" + fPath + ", fNbEvents=" + fNbEvents + ", fStart=" + fStart + ", fEnd=" + fEnd + ", fIndexingStatus=" + fIndexingStatus + ", fProperties" + fProperties.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
}
}
Loading

0 comments on commit 2386d1d

Please sign in to comment.