11/*******************************************************************************
2- * Copyright (c) 2019, 2020 École Polytechnique de Montréal and others
2+ * Copyright (c) 2019, 2025 École Polytechnique de Montréal and others
33 *
44 * All rights reserved. This program and the accompanying materials are
55 * made available under the terms of the Eclipse Public License 2.0 which
@@ -96,11 +96,11 @@ public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implem
9696
9797 private static final AtomicLong ENTRY_ID = new AtomicLong ();
9898
99- private Map <Long , Pair <ITmfStateSystem , Integer >> fIDToDisplayQuark = new HashMap <>();
99+ private Map <Long , Pair <ITmfStateSystem , Integer >> fIDToSSQuark = new HashMap <>();
100100
101101 // Use to add one event for every state system and module
102- private final Map <ITmfStateSystem , Long > fSsToId = new HashMap <>();
103- private final List < ModuleEntryModel > fModuleEntryModelList = new ArrayList <>();
102+ private final Map <Long , ITmfStateSystem > fIdToSs = new HashMap <>();
103+ private final Map < Long , ModuleEntryModel > fIdToModuleEntryModel = new HashMap <>();
104104
105105 private final Map <ITmfAnalysisModuleWithStateSystems , Boolean > fModulesToStatus = new HashMap <>();
106106
@@ -217,7 +217,7 @@ private Map<Long, Pair<ITmfStateSystem, Integer>> getSelectedEntries(Map<String,
217217 Map <Long , Pair <ITmfStateSystem , Integer >> idToQuark = new HashMap <>();
218218 synchronized (fEntryBuilder ) {
219219 for (Long id : selectedItems ) {
220- Pair <ITmfStateSystem , Integer > pair = fIDToDisplayQuark .get (id );
220+ Pair <ITmfStateSystem , Integer > pair = fIDToSSQuark .get (id );
221221 if (pair != null ) {
222222 idToQuark .put (id , pair );
223223 }
@@ -325,7 +325,7 @@ public TraceEntryModel build() {
325325 * The end time
326326 */
327327 protected TraceEntryModel (long id , long parentId , String traceName , long startTime , long endTime , ITmfTrace trace ) {
328- super (id , parentId , traceName , startTime , endTime );
328+ super (id , parentId , traceName , startTime , endTime , false );
329329 fEntryTrace = trace ;
330330 }
331331
@@ -509,7 +509,7 @@ public int getQuark() {
509509 // need to create the tree
510510 boolean fetchTreeIsComplete ;
511511 synchronized (fEntryBuilder ) {
512- fModuleEntryModelList .clear ();
512+ fIdToModuleEntryModel .clear ();
513513 fetchTreeIsComplete = addTrace (monitor );
514514 if (monitor != null && monitor .isCanceled ()) {
515515 return new TmfModelResponse <>(null , Status .CANCELLED , CommonStatusMessage .TASK_CANCELLED );
@@ -548,18 +548,20 @@ private boolean addTrace(@Nullable IProgressMonitor monitor) {
548548 if (monitor != null && monitor .isCanceled ()) {
549549 return false ;
550550 }
551+ boolean analysisIsDone = Objects .requireNonNull (moduleWithStatus .getValue ());
551552 ITmfAnalysisModuleWithStateSystems module = Objects .requireNonNull (moduleWithStatus .getKey ());
552- Boolean analysisIsDone = Objects .requireNonNull (moduleWithStatus .getValue ());
553+ // Children entry of the trace are the modules
554+ boolean complete = addModule (monitor , module , rootId , trace .getStartTime ().toNanos ());
553555 if (!analysisIsDone || fStartedAnalysis .contains (module )) {
554556 // Children entry of the trace are the modules
555- fetchTreeIsComplete &= addModule ( monitor , module , rootId , trace . getStartTime (). toNanos ()) ;
557+ fetchTreeIsComplete &= complete ;
556558 fStartedAnalysis .remove (module );
557559 }
558560 }
559561
560562 // Update end Time
561563 long traceEnd = traceEntry .getEndTime ();
562- for (ModuleEntryModel moduleEntryModel : fModuleEntryModelList ) {
564+ for (ModuleEntryModel moduleEntryModel : fIdToModuleEntryModel . values () ) {
563565 if (monitor != null && monitor .isCanceled ()) {
564566 return false ;
565567 }
@@ -598,16 +600,16 @@ private boolean addModule(@Nullable IProgressMonitor monitor, ITmfAnalysisModule
598600 long moduleId = moduleEntry .getId ();
599601
600602 // Add child entry
601- boolean fetchTreeIsComplete = true ;
602- Long moduleEnd = startTime ;
603+ boolean complete = true ;
604+ long moduleEnd = getTrace (). getEndTime (). toNanos () ;
603605 boolean hasChildren = false ;
604606 for (ITmfStateSystem ss : module .getStateSystems ()) {
605607 if (monitor != null && monitor .isCanceled ()) {
606608 return false ;
607609 }
608610
609611 // Children entry of the modules are state system
610- fetchTreeIsComplete &= ss .waitUntilBuilt (0 );
612+ complete &= ss .waitUntilBuilt (0 );
611613 if (!ss .isCancelled ()) {
612614 addStateSystem (monitor , ss , moduleId );
613615 moduleEnd = Long .max (moduleEnd , ss .getCurrentEndTime ());
@@ -628,13 +630,13 @@ private boolean addModule(@Nullable IProgressMonitor monitor, ITmfAnalysisModule
628630 moduleEntry .setEndTime (moduleEnd );
629631 fEntryBuilder .put (parentId , moduleName , moduleEntry );
630632 ModuleEntryModel finalModuleEntry = moduleEntry .build ();
631- fModuleEntryModelList . add ( finalModuleEntry );
632- if (fetchTreeIsComplete && hasChildren ) {
633+ fIdToModuleEntryModel . put ( finalModuleEntry . getId (), finalModuleEntry );
634+ if (complete && hasChildren ) {
633635 // Analysis is complete
634636 fModulesToStatus .put (module , true );
635637 }
636638
637- return fetchTreeIsComplete ;
639+ return complete ;
638640 }
639641
640642 private void addStateSystem (@ Nullable IProgressMonitor monitor , ITmfStateSystem ss , long parentId ) {
@@ -654,18 +656,18 @@ private void addStateSystem(@Nullable IProgressMonitor monitor, ITmfStateSystem
654656 fEntryBuilder .put (parentId , ssName , stateSystemEntryModel );
655657 }
656658 // Update entry
657- long ssId = stateSystemEntryModel .getId ();
659+ long id = stateSystemEntryModel .getId ();
658660 stateSystemEntryModel .setEndTime (endTime );
659661 fEntryBuilder .put (parentId , ssName , stateSystemEntryModel );
660- fSsToId .put (ss , ssId );
662+ fIdToSs .put (id , ss );
661663
662664 // Add child entry
663665 for (Integer attrib : ss .getSubAttributes (ITmfStateSystem .ROOT_ATTRIBUTE , false )) {
664666 if (monitor != null && monitor .isCanceled ()) {
665667 return ;
666668 }
667669 // Children of the state system are recursive hierarchy
668- addSubAttributes (monitor , ssId , startTime , endTime , ss , attrib );
670+ addSubAttributes (monitor , id , startTime , endTime , ss , attrib );
669671 }
670672 }
671673
@@ -685,7 +687,7 @@ private void addSubAttributes(@Nullable IProgressMonitor monitor, Long parentId,
685687 long id = attributeEntry .getId ();
686688
687689 Pair <ITmfStateSystem , Integer > displayQuark = new Pair <>(ss , attrib );
688- fIDToDisplayQuark .put (id , displayQuark );
690+ fIDToSSQuark .put (id , displayQuark );
689691
690692 // Add child entry
691693 for (Integer child : ss .getSubAttributes (attrib , false )) {
@@ -741,69 +743,77 @@ private void waitForInitialization(ITmfTrace trace, ITmfAnalysisModuleWithStateS
741743 }
742744
743745 @ Override
744- public @ NonNull TmfModelResponse <@ NonNull TimeGraphModel > fetchRowModel (Map <String , Object > fetchParameters , @ Nullable IProgressMonitor monitor ) {
745- Table <ITmfStateSystem , Integer , Long > table = HashBasedTable .create ();
746- // Get the quarks to display
746+ public @ NonNull TmfModelResponse <TimeGraphModel > fetchRowModel (Map <String , Object > fetchParameters , @ Nullable IProgressMonitor monitor ) {
747747 Collection <Long > selectedItems = DataProviderParameterUtils .extractSelectedItems (fetchParameters );
748+ if (selectedItems == null ) {
749+ return new TmfModelResponse <>(null , ITmfResponse .Status .FAILED , CommonStatusMessage .INCORRECT_QUERY_PARAMETERS );
750+ }
751+
752+ List <ITimeGraphRowModel > allRows = new ArrayList <>();
753+
754+ // Add requested module and state system rows
755+ synchronized (fEntryBuilder ) {
756+ selectedItems .forEach (id -> {
757+ ITimeGraphRowModel moduleRow = getModuleRowModel (id );
758+ if (moduleRow != null ) {
759+ allRows .add (moduleRow );
760+ }
761+ ITimeGraphRowModel ssRow = getStateSystemRowModel (id );
762+ if (ssRow != null ) {
763+ allRows .add (ssRow );
764+ }
765+ });
766+ }
767+
768+ // Get the quarks to display
769+ Table <ITmfStateSystem , Integer , Long > table = HashBasedTable .create ();
748770 synchronized (fEntryBuilder ) {
749- if (selectedItems == null ) {
750- // No selected items, take them all
751- selectedItems = fIDToDisplayQuark .keySet ();
752- }
753771 for (Long id : selectedItems ) {
754- Pair <ITmfStateSystem , Integer > pair = fIDToDisplayQuark .get (id );
772+ Pair <ITmfStateSystem , Integer > pair = fIDToSSQuark .get (id );
755773 if (pair != null ) {
756774 table .put (pair .getFirst (), pair .getSecond (), id );
757775 }
758776 }
759777 }
760- List <@ NonNull ITimeGraphRowModel > allRows = new ArrayList <>();
761778 try {
762779 List <Long > times = DataProviderParameterUtils .extractTimeRequested (fetchParameters );
763780 for (Entry <ITmfStateSystem , Map <Integer , Long >> ssEntry : table .rowMap ().entrySet ()) {
764781 ITmfStateSystem ss = Objects .requireNonNull (ssEntry .getKey ());
765- List <@ NonNull ITimeGraphRowModel > rows = getRowModels (ss , ssEntry .getValue (), times , fetchParameters , monitor );
782+ List <ITimeGraphRowModel > rows = getRowModels (ss , ssEntry .getValue (), times , fetchParameters , monitor );
783+ allRows .addAll (rows );
766784 if (monitor != null && monitor .isCanceled ()) {
767785 return new TmfModelResponse <>(null , Status .CANCELLED , CommonStatusMessage .TASK_CANCELLED );
768786 }
769- synchronized (fEntryBuilder ) {
770- // Add the SS
771- Long ssId = fSsToId .get (ss );
772- if (ssId != null && selectedItems .contains (ssId )) {
773- TimeGraphRowModel ssRow = new TimeGraphRowModel (ssId , new ArrayList <>());
774- List <@ NonNull ITimeGraphState > states = ssRow .getStates ();
775- states .add (new TimeGraphState (ss .getStartTime (), ss .getCurrentEndTime () - ss .getStartTime (), Integer .MAX_VALUE , null , new OutputElementStyle (TRANSPARENT )));
776- rows .add (ssRow );
777- }
778- }
779- allRows .addAll (rows );
780- }
781-
782- synchronized (fEntryBuilder ) {
783- for (ModuleEntryModel module : fModuleEntryModelList ) {
784- if (selectedItems .contains (module .getId ())) {
785- allRows .add (getModuleRowModels (module ));
786- }
787- }
788- }
789-
790- if (monitor != null && monitor .isCanceled ()) {
791- return new TmfModelResponse <>(null , Status .CANCELLED , CommonStatusMessage .TASK_CANCELLED );
792787 }
793788 return new TmfModelResponse <>(new TimeGraphModel (allRows ), Status .COMPLETED , CommonStatusMessage .COMPLETED );
794789 } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e ) {
795790 return new TmfModelResponse <>(null , Status .FAILED , CommonStatusMessage .STATE_SYSTEM_FAILED );
796791 }
797792 }
798793
799- private static ITimeGraphRowModel getModuleRowModels (ModuleEntryModel module ) {
800- TimeGraphRowModel moduleRow = new TimeGraphRowModel (module .getId (), new ArrayList <>());
801- List <@ NonNull ITimeGraphState > states = moduleRow .getStates ();
802- states .add (new TimeGraphState (module .getStartTime (), module .getEndTime () - module .getStartTime (), Integer .MAX_VALUE , null , new OutputElementStyle (TRANSPARENT )));
803- return moduleRow ;
794+ private @ Nullable ITimeGraphRowModel getModuleRowModel (long id ) {
795+ ModuleEntryModel module = fIdToModuleEntryModel .get (id );
796+ if (module != null ) {
797+ TimeGraphRowModel moduleRow = new TimeGraphRowModel (module .getId (), new ArrayList <>());
798+ List <ITimeGraphState > states = moduleRow .getStates ();
799+ states .add (new TimeGraphState (module .getStartTime (), module .getEndTime () - module .getStartTime (), Integer .MAX_VALUE , null , new OutputElementStyle (TRANSPARENT )));
800+ return moduleRow ;
801+ }
802+ return null ;
803+ }
804+
805+ private @ Nullable ITimeGraphRowModel getStateSystemRowModel (long id ) {
806+ ITmfStateSystem ss = fIdToSs .get (id );
807+ if (ss != null ) {
808+ TimeGraphRowModel ssRow = new TimeGraphRowModel (id , new ArrayList <>());
809+ List <ITimeGraphState > states = ssRow .getStates ();
810+ states .add (new TimeGraphState (ss .getStartTime (), ss .getCurrentEndTime () - ss .getStartTime (), Integer .MAX_VALUE , null , new OutputElementStyle (TRANSPARENT )));
811+ return ssRow ;
812+ }
813+ return null ;
804814 }
805815
806- private List <@ NonNull ITimeGraphRowModel > getRowModels (ITmfStateSystem ss , Map <Integer , Long > idToDisplayQuark ,
816+ private List <@ NonNull ITimeGraphRowModel > getRowModels (ITmfStateSystem ss , Map <Integer , Long > quarkToId ,
807817 @ Nullable List <Long > times , Map <String , Object > fetchParameters , @ Nullable IProgressMonitor monitor ) throws StateSystemDisposedException {
808818 // Create predicates
809819 Map <@ NonNull Integer , @ NonNull Predicate <@ NonNull Multimap <@ NonNull String , @ NonNull Object >>> predicates = new HashMap <>();
@@ -812,12 +822,12 @@ private static ITimeGraphRowModel getModuleRowModels(ModuleEntryModel module) {
812822 predicates .putAll (computeRegexPredicate (regexesMap ));
813823 }
814824 // Create quark to row
815- Map <Integer , ITimeGraphRowModel > quarkToRow = new HashMap <>(idToDisplayQuark .size ());
816- for (Entry <Integer , Long > entry : idToDisplayQuark .entrySet ()) {
825+ Map <Integer , ITimeGraphRowModel > quarkToRow = new HashMap <>(quarkToId .size ());
826+ for (Entry <Integer , Long > entry : quarkToId .entrySet ()) {
817827 quarkToRow .put (entry .getKey (), new TimeGraphRowModel (entry .getValue (), new ArrayList <>()));
818828 }
819829
820- for (ITmfStateInterval interval : ss .query2D (idToDisplayQuark .keySet (), getTimes (ss , times ))) {
830+ for (ITmfStateInterval interval : ss .query2D (quarkToId .keySet (), getTimes (ss , times ))) {
821831 if (monitor != null && monitor .isCanceled ()) {
822832 return Collections .emptyList ();
823833 }
0 commit comments