use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.
the class XmlStubTraceTest method testAspects.
/**
* Test the presence and resolve of the aspects for this trace
*/
@Test
public void testAspects() {
fTestTrace = TmfXmlTraceStubNs.setupTrace(TmfCoreTestPlugin.getAbsoluteFilePath(VALID_FILE));
ITmfEventAspect<?> cpuAspect = null;
ITmfEventAspect<?> testAspect = null;
int aspectCount = 0;
for (ITmfEventAspect<?> aspect : fTestTrace.getEventAspects()) {
aspectCount++;
if (aspect instanceof TmfCpuAspect) {
cpuAspect = aspect;
} else if (aspect.getName().equals("test")) {
testAspect = aspect;
}
}
/* Check the presence of the cpu and test aspects */
assertEquals("Number of aspects", 5, aspectCount);
assertNotNull(cpuAspect);
assertNotNull(testAspect);
ITmfContext ctx;
ctx = fTestTrace.seekEvent(0L);
assertNotNull(ctx);
ITmfEvent event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 1", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 1", "abc", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 2", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 2", "abc", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 3", 2, cpuAspect.resolve(event));
assertEquals("Test aspect of event 3", "def", testAspect.resolve(event));
event = fTestTrace.getNext(ctx);
assertNotNull(event);
assertEquals("Cpu aspect of event 4", 1, cpuAspect.resolve(event));
assertEquals("Test aspect of event 4", "def", testAspect.resolve(event));
ctx.dispose();
}
use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.
the class ResourcesStatusDataProvider method putCpuTooltip.
private void putCpuTooltip(ITmfStateSystem ss, String attributeName, Map<String, String> retMap, List<ITmfStateInterval> full, int status) {
int currentThreadQuark = ss.optQuarkAbsolute(Attributes.CPUS, attributeName, Attributes.CURRENT_THREAD);
if (currentThreadQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
return;
}
Object currentThreadObject = full.get(currentThreadQuark).getValue();
if (currentThreadObject instanceof Number) {
String currentThread = currentThreadObject.toString();
retMap.put(Messages.ResourcesStatusDataProvider_attributeTidName, currentThread);
int execNameQuark = ss.optQuarkAbsolute(Attributes.THREADS, currentThread, Attributes.EXEC_NAME);
if (execNameQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
Object processName = full.get(execNameQuark).getValue();
if (processName instanceof String) {
retMap.put(Messages.ResourcesStatusDataProvider_attributeProcessName, (String) processName);
}
}
int syscallQuark = ss.optQuarkAbsolute(Attributes.THREADS, currentThread, Attributes.SYSTEM_CALL);
if (status == StateValues.CPU_STATUS_RUN_SYSCALL && syscallQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
ITmfStateInterval interval = full.get(syscallQuark);
Object syscall = interval.getValue();
if (syscall instanceof String) {
retMap.put(Attributes.SYSTEM_CALL, (String) syscall);
ITmfTrace trace = getTrace();
ITmfCallsiteResolver csAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(trace, CallsiteAnalysis.class, CallsiteAnalysis.ID);
if (csAnalysis != null) {
for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
if (aspect instanceof TmfCpuAspect) {
TmfDeviceAspect deviceAspect = (TmfCpuAspect) aspect;
List<@NonNull ITmfCallsite> callsites = csAnalysis.getCallsites(String.valueOf(trace.getUUID()), deviceAspect.getDeviceType(), attributeName, interval.getStartTime() / 2L + interval.getEndTime() / 2L);
if (!callsites.isEmpty()) {
retMap.put(TmfStrings.source(), callsites.get(0).toString());
}
}
}
}
}
}
}
}
use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method fetchTooltip.
@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
ITmfStateSystem ss = fModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
boolean completed = ss.waitUntilBuilt(0);
ITmfResponse.Status status = completed ? ITmfResponse.Status.COMPLETED : ITmfResponse.Status.RUNNING;
String statusMessage = completed ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
// TODO server: Parameters validation should be handle separately. It
// can be either in the data provider itself or before calling it. It
// will avoid the creation of filters and the content of the map can be
// use directly.
List<@NonNull Long> selected = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
List<@NonNull Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
if (times == null || times.isEmpty() || selected == null || selected.isEmpty()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
Integer quark = fQuarkMap.get(selected.get(0));
if (quark == null) {
return new TmfModelResponse<>(null, status, statusMessage);
}
long start = times.get(0);
try {
int currentCpuRqQuark = ss.optQuarkRelative(quark, Attributes.CURRENT_CPU_RQ);
if (currentCpuRqQuark == ITmfStateSystem.INVALID_ATTRIBUTE || start < ss.getStartTime() || start > ss.getCurrentEndTime()) {
return new TmfModelResponse<>(null, status, statusMessage);
}
ITmfStateInterval mainInterval = null;
ITmfStateInterval currentCpuInterval = null;
for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(quark, currentCpuRqQuark), Collections.singleton(start))) {
if (interval.getAttribute() == quark) {
mainInterval = interval;
continue;
}
currentCpuInterval = interval;
}
if (mainInterval == null || currentCpuInterval == null) {
return new TmfModelResponse<>(null, status, statusMessage);
}
ITmfCallsiteResolver csAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(getTrace(), CallsiteAnalysis.class, CallsiteAnalysis.ID);
Object value = currentCpuInterval.getValue();
if (value instanceof Integer) {
String cpuId = String.valueOf(value);
Map<String, String> returnValue = new LinkedHashMap<>();
returnValue.put(TmfStrings.cpu(), cpuId);
if (csAnalysis != null) {
Object cpuThreadObj = mainInterval.getValue();
if (cpuThreadObj instanceof Integer && Objects.equals(ProcessStatus.RUN_SYTEMCALL.getStateValue().unboxInt(), cpuThreadObj)) {
ITmfTrace trace = getTrace();
for (ITmfEventAspect<?> aspect : trace.getEventAspects()) {
if (aspect instanceof TmfCpuAspect) {
TmfCpuAspect deviceAspect = (TmfCpuAspect) aspect;
List<@NonNull ITmfCallsite> callsites = csAnalysis.getCallsites(String.valueOf(trace.getUUID()), deviceAspect.getDeviceType(), cpuId, start);
if (!callsites.isEmpty()) {
returnValue.put(TmfStrings.source(), callsites.get(0).toString());
}
}
}
}
}
return new TmfModelResponse<>(returnValue, status, statusMessage);
}
} catch (StateSystemDisposedException e) {
/* Ignored */
}
return new TmfModelResponse<>(null, status, statusMessage);
}
use of org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect in project tracecompass by tracecompass.
the class TmfXmlTraceStub method generateAspects.
private void generateAspects(ITmfEventField[] fieldsArray) {
ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
/* Initialize the first default trace aspects */
builder.add(TmfBaseAspects.getTimestampAspect());
builder.add(TmfBaseAspects.getEventTypeAspect());
/* Add custom aspects in between */
for (ITmfEventField field : fieldsArray) {
String name = field.getName();
final ITmfEventAspect<?> aspect = new TmfContentFieldAspect(name, name);
if (name.equals(ASPECT_CPU)) {
builder.add(new TmfCpuAspect() {
@Override
@Nullable
public Integer resolve(ITmfEvent event) {
Object result = aspect.resolve(event);
if (result instanceof Number) {
return ((Number) result).intValue();
}
return null;
}
});
} else {
builder.add(aspect);
}
}
/* Add the big content aspect */
builder.add(TmfBaseAspects.getContentsAspect());
/* Add the additional aspects */
builder.addAll(fAdditionalAspects);
fAspects = builder.build();
}
Aggregations