use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class TmfCommonXAxisChartViewer method createQueryParameters.
/**
* Create map of parameters that will be used by updateData method. If a
* viewer need a more specialized map than just the time requested it's its
* responsibility to override this method and provide the desired instance.
*
* @param start
* The starting value
* @param end
* The ending value
* @param nb
* The number of entries
* @return Map of parameters
*/
@NonNull
protected Map<String, Object> createQueryParameters(long start, long end, int nb) {
Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(start, end, nb));
Multimap<@NonNull Integer, @NonNull String> regexesMap = getRegexes();
if (!regexesMap.isEmpty()) {
parameters.put(DataProviderParameterUtils.REGEX_MAP_FILTERS_KEY, regexesMap.asMap());
}
return parameters;
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class ThreadStatusDataProviderTest method assertAndGetTree.
private static Map<Long, String> assertAndGetTree(ThreadStatusDataProvider provider) throws IOException {
TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> treeResponse = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), null);
assertNotNull(treeResponse);
assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
TmfTreeModel<@NonNull TimeGraphEntryModel> treeModel = treeResponse.getModel();
assertNotNull(treeModel);
List<@NonNull TimeGraphEntryModel> treeEntries = treeModel.getEntries();
List<String> expectedStrings = Files.readAllLines(Paths.get("testfiles/kernel_analysis/expectedThreadStatusTree"));
assertEquals(expectedStrings.size(), treeEntries.size());
for (int i = 0; i < expectedStrings.size(); i++) {
String expectedString = expectedStrings.get(i);
String[] split = expectedString.split(",");
TimeGraphEntryModel threadEntry = treeEntries.get(i);
// Assert common fields
assertEquals(split[0], threadEntry.getName());
assertEquals(Long.parseLong(split[1]), threadEntry.getStartTime());
assertEquals(Long.parseLong(split[2]), threadEntry.getEndTime());
if (threadEntry instanceof ThreadEntryModel) {
// Verify the thread entry fields
ThreadEntryModel threadEntryModel = (ThreadEntryModel) threadEntry;
assertEquals(Integer.parseInt(split[3]), threadEntryModel.getThreadId());
assertEquals(Integer.parseInt(split[4]), threadEntryModel.getProcessId());
assertEquals(Integer.parseInt(split[5]), threadEntryModel.getParentThreadId());
} else {
// Make sure there is no extra expected fields
assertEquals(3, split.length);
}
}
Map<Long, String> map = new HashMap<>();
for (TimeGraphEntryModel threadModel : treeEntries) {
map.put(threadModel.getId(), threadModel.getName());
}
return map;
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class CpuUsageDataProvider method getTree.
/**
* @since 2.5
*/
@Override
protected TmfTreeModel<CpuUsageEntryModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(parameters);
if (filter == null) {
return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
}
long end = filter.getEnd();
List<CpuUsageEntryModel> entryList = new ArrayList<>();
Set<Integer> cpus = extractCpuSet(parameters);
Map<String, Long> cpuUsageMap = getAnalysisModule().getCpuUsageInRange(cpus, filter.getStart(), end);
double timeRange = end - filter.getStart();
long totalTime = cpuUsageMap.getOrDefault(KernelCpuUsageAnalysis.TOTAL, 0l);
long totalId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
entryList.add(new CpuUsageEntryModel(totalId, -1, ImmutableList.of(getTrace().getName(), String.valueOf(Messages.CpuUsageDataProvider_Total), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * totalTime / timeRange : (float) 0), TIME_FORMATTER.format(totalTime)), TOTAL_SERIES_TID, totalTime));
for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
/*
* Process only entries representing the total of all CPUs and that
* have time on CPU
*/
String key = entry.getKey();
if (entry.getValue() == 0 || !key.startsWith(KernelCpuUsageAnalysis.TOTAL)) {
continue;
}
String[] strings = key.split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
if (strings.length > 1) {
int tid = Integer.parseInt(strings[1]);
Long time = entry.getValue();
if (tid != 0) {
entryList.add(new CpuUsageEntryModel(getId(tid), totalId, ImmutableList.of(getProcessName(tid, strings[1], end), String.valueOf(tid), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * time / timeRange : (float) 0), TIME_FORMATTER.format(time)), tid, time));
}
}
}
return new TmfTreeModel<>(ImmutableList.of(String.valueOf(Messages.CpuUsageDataProvider_ColumnProcess), OsStrings.tid(), String.valueOf(Messages.CpuUsageDataProvider_ColumnPercent), String.valueOf(Messages.CpuUsageDataProvider_ColumnTime)), entryList);
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class KernelMemoryUsageDataProvider method getTree.
/**
* @since 2.5
*/
@Override
protected TmfTreeModel<MemoryUsageTreeModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(parameters);
if (filter == null) {
return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
}
long start = filter.getStart();
long end = filter.getEnd();
// Let the list of active states be null if we aren't filtering
List<ITmfStateInterval> active = null;
Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(parameters);
if (isFiltered != null && isFiltered) {
if (start == end || start > ss.getCurrentEndTime() || end < ss.getStartTime()) {
/*
* return an empty list if the filter is empty or does not intersect the state
* system
*/
return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
}
active = ss.queryFullState(Long.max(start, ss.getStartTime()));
}
List<MemoryUsageTreeModel> nodes = new ArrayList<>();
List<Integer> threadQuarkList = ss.getSubAttributes(ITmfStateSystem.ROOT_ATTRIBUTE, false);
long totalId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
nodes.add(new MemoryUsageTreeModel(totalId, -1, TOTAL_TID, Collections.singletonList(getTrace().getName())));
for (Integer threadQuark : threadQuarkList) {
if (active == null || ((threadQuark < active.size()) && active.get(threadQuark).getEndTime() < end)) {
String tidString = ss.getAttributeName(threadQuark);
String procname = fProcessNameMap.computeIfAbsent(tidString, string -> getProcessName(string, end));
// Ensure that we reuse the same id for a given quark.
long id = getId(threadQuark);
nodes.add(new MemoryUsageTreeModel(id, totalId, parseTid(tidString), Collections.singletonList(procname)));
}
}
return new TmfTreeModel<>(Collections.emptyList(), nodes);
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class ControlFlowCheckActiveProvider method getActiveIds.
private Set<Long> getActiveIds(TimeGraphEntry cfe, TmfTimeRange range) {
ITimeGraphDataProvider<? extends TimeGraphEntryModel> dataProvider = BaseDataProviderTimeGraphView.getProvider(cfe);
if (range.equals(fRange) && dataProvider.equals(fProvider) || !(dataProvider instanceof ThreadStatusDataProvider)) {
return fActive;
}
TimeQueryFilter filter = new TimeQueryFilter(range.getStartTime().toNanos(), range.getEndTime().toNanos(), 2);
Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.timeQueryToMap(filter);
parameters.put(ThreadStatusDataProvider.ACTIVE_THREAD_FILTER_KEY, true);
TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = ((ThreadStatusDataProvider) dataProvider).fetchTree(parameters, null);
TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
if (model == null) {
// query must have failed, return empty and don't invalidate the cache.
return Collections.emptySet();
}
fRange = range;
fActive = model.getEntries().stream().map(TimeGraphEntryModel::getId).collect(Collectors.toSet());
return fActive;
}
Aggregations