use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class DataDrivenOutputEntry method buildEntries.
/**
* Build the actual entries from this entry descriptor
*
* @param ssq
* The base state system to use
* @param parentEntryId
* The ID of the parent time graph entry
* @param trace
* The trace these entries are for, used to get any additional
* state system
* @param prevBaseQuark
* The base quark of the parent
* @param prevRegex
* With recursive entries, this is the result of the previous
* regex that may contain placeholders whose value need to be
* replace in current entry's regex
* @param currentEnd
* The current end time
* @param idGenerator
* A callback used to generate the entry's unique ID
* @param callback
* A callback to register an ID with the state system and quark
* pair
* @return All the newly created entries
*/
public List<TimeGraphEntryModel> buildEntries(ITmfStateSystem ssq, long parentEntryId, ITmfTrace trace, int prevBaseQuark, String prevRegex, long currentEnd, IdGetter idGenerator, QuarkCallback callback) {
// Get the state system to use to populate those entries, by default, it
// is the same as the parent
String specificSs = fAnalysisId;
ITmfStateSystem parentSs = ssq;
ITmfStateSystem ss = parentSs;
int baseQuark = prevBaseQuark;
if (specificSs != null) {
ss = TmfStateSystemAnalysisModule.getStateSystem(trace, specificSs);
baseQuark = ITmfStateSystem.ROOT_ATTRIBUTE;
if (ss == null) {
return Collections.emptyList();
}
}
DataContainer container = SS_TO_CONTAINER.computeIfAbsent(ss, s -> new DataContainer(s));
// Replace any place holders in the path.
// FIXME: Figure out what this really does and better document it
Pattern pattern = Pattern.compile(prevRegex);
String attributePath = prevBaseQuark > 0 ? parentSs.getFullAttributePath(prevBaseQuark) : StringUtils.EMPTY;
Matcher matcher = pattern.matcher(attributePath);
String path = fPath;
if (matcher.find()) {
path = matcher.replaceFirst(path);
}
/* Replace * by .* to have a regex string */
// $NON-NLS-1$//$NON-NLS-2$
String regexName = path.replaceAll("\\*", "(.*)");
/* Get the list of quarks to process with this path */
String[] paths = regexName.split(SPLIT_STRING);
int i = 0;
List<Integer> quarks = Collections.singletonList(baseQuark);
while (i < paths.length) {
List<Integer> subQuarks = new ArrayList<>();
String name = paths[i];
for (int relativeQuark : quarks) {
subQuarks.addAll(ss.getSubAttributes(relativeQuark, false, name));
}
quarks = subQuarks;
i++;
}
Map<Integer, Long> startTimes = new HashMap<>();
Map<Integer, Long> endTimes = new HashMap<>();
long startTime = ss.getStartTime();
try {
Iterable<ITmfStateInterval> iter = ss.query2D(quarks, Arrays.asList(startTime, currentEnd));
for (ITmfStateInterval interval : iter) {
if (interval.getValue() == null) {
/*
* Adjust the start/end time if a null state crosses one and
* only one start/end boundary. Otherwise leave the default
* to state system start/end time.
*/
int quark = interval.getAttribute();
if (!interval.intersects(currentEnd)) {
startTimes.put(quark, interval.getEndTime() + 1);
}
if (!interval.intersects(startTime)) {
endTimes.put(quark, interval.getStartTime());
}
}
}
} catch (StateSystemDisposedException e) {
return Collections.emptyList();
}
/* Process each quark */
DataDrivenStateSystemPath displayPath = fDisplay;
DataDrivenStateSystemPath namePath = fName;
DataDrivenStateSystemPath idPath = fId;
DataDrivenStateSystemPath parentPath = fParent;
Map<String, DataDrivenOutputEntryModel.EntryBuilder> entryMap = new HashMap<>();
List<DataDrivenOutputEntryModel.EntryBuilder> entries = new ArrayList<>();
List<TimeGraphEntryModel> entryList = new ArrayList<>();
for (int quark : quarks) {
long id = idGenerator.getIdFor(ss, quark);
// Get the quark containing the data to display, else there is no display
int displayQuark = ITmfStateSystem.INVALID_ATTRIBUTE;
long entryStart = startTimes.getOrDefault(quark, startTime);
long entryEnd = endTimes.getOrDefault(quark, currentEnd);
if (displayPath != null) {
displayQuark = displayPath.getQuark(quark, container);
if (displayQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
// The entry has no display quark, do not display
continue;
}
callback.registerQuark(id, ss, displayQuark, fDisplayType);
}
// Get the name of this entry
String name = StringUtils.EMPTY;
if (namePath != null) {
name = getFirstValue(quark, namePath, container);
}
if (name.isEmpty()) {
// Default, use the attribute name as name
name = ss.getAttributeName(quark);
}
// Get the XML internal ID of this entry
String xmlId;
if (idPath != null) {
xmlId = getFirstValue(quark, idPath, container);
} else {
// Use the name as ID
xmlId = name;
}
// Get the parent's internal ID of the entry
String xmlParentId = StringUtils.EMPTY;
if (parentPath != null) {
xmlParentId = getFirstValue(quark, parentPath, container);
}
EntryBuilder entryBuilder = new DataDrivenOutputEntryModel.EntryBuilder(id, parentEntryId, displayQuark, name, xmlId, xmlParentId, entryStart, entryEnd, fDisplayText, fDisplayType);
entryMap.put(xmlId, entryBuilder);
entries.add(entryBuilder);
/* Process the children entry of this entry */
for (DataDrivenOutputEntry subEntry : fChildrenEntries) {
@NonNull String regex = prevRegex.isEmpty() ? regexName : prevRegex + '/' + regexName;
entryList.addAll(subEntry.buildEntries(ss, entryBuilder.getId(), trace, quark, regex, currentEnd, idGenerator, callback));
}
}
// At this point, the parent has been set, so we can build the entries
buildTree(entryMap);
for (EntryBuilder b : entries) {
entryList.add(b.build());
}
return entryList;
}
Aggregations