/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.tracecompass.tmf.ui.views.callstack;
+import java.util.Optional;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
/**
* Presentation provider for the Call Stack view, based on the generic TMF
* presentation provider.
private Integer fAverageCharWidth;
+ private final LoadingCache<CallStackEvent, Optional<String>> fTimeEventNames = CacheBuilder.newBuilder()
+ .maximumSize(1000)
+ .build(new CacheLoader<CallStackEvent, Optional<String>>() {
+ @Override
+ public Optional<String> load(CallStackEvent event) {
+ CallStackEntry entry = event.getEntry();
+ ITmfStateSystem ss = entry.getStateSystem();
+ try {
+ ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
+ if (!value.isNull()) {
+ String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
+ return Optional.ofNullable(name);
+ }
+ } catch (TimeRangeException e) {
+ Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
+ } catch (StateSystemDisposedException e) {
+ /* Ignored */
+ }
+ return Optional.empty();
+ }
+ });
+
private enum State {
MULTIPLE (new RGB(100, 100, 100)),
EXEC (new RGB(0, 200, 0));
@Override
public String getEventName(ITimeEvent event) {
if (event instanceof CallStackEvent) {
- CallStackEntry entry = (CallStackEntry) event.getEntry();
- ITmfStateSystem ss = entry.getStateSystem();
- try {
- ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
- if (!value.isNull()) {
- return fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
- }
- } catch (AttributeNotFoundException e) {
- Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
- } catch (TimeRangeException e) {
- Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
- } catch (StateSystemDisposedException e) {
- /* Ignored */
- }
- return null;
+ return fTimeEventNames.getUnchecked((CallStackEvent) event).orElse(null);
}
return State.MULTIPLE.toString();
}
if (!(event instanceof CallStackEvent)) {
return;
}
- CallStackEntry entry = (CallStackEntry) event.getEntry();
- ITmfStateSystem ss = entry.getStateSystem();
- try {
- ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
- if (!value.isNull()) {
- String name = fView.getFunctionName(entry.getTrace(), entry.getProcessId(), event.getTime(), value);
- gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
- Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
- }
- } catch (AttributeNotFoundException e) {
- Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
- } catch (TimeRangeException e) {
- Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
- } catch (StateSystemDisposedException e) {
- /* Ignored */
- }
+ String name = fTimeEventNames.getUnchecked((CallStackEvent) event).orElse(null);
+ gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ Utils.drawText(gc, name, bounds.x, bounds.y, bounds.width, bounds.height, true, true);
+ }
+
+ /**
+ * Indicate that the provider of function names has changed, so any cached
+ * values must be reset.
+ */
+ void resetFunctionNames() {
+ fTimeEventNames.invalidateAll();
}
}