2424import java .util .List ;
2525import java .util .Map ;
2626import java .util .Objects ;
27+
2728import java .util .Set ;
29+ //import java.util.stream.Collectors;
30+ import java .util .stream .Collectors ;
2831
2932import org .eclipse .core .runtime .IProgressMonitor ;
3033import org .eclipse .core .runtime .NullProgressMonitor ;
3134import org .eclipse .jdt .annotation .NonNull ;
3235import org .eclipse .jdt .annotation .Nullable ;
36+ import org .eclipse .tracecompass .analysis .profiling .core .instrumented .InstrumentedCallStackAnalysis ;
3337import org .eclipse .tracecompass .analysis .profiling .core .tests .stubs2 .CallStackAnalysisStub ;
3438import org .eclipse .tracecompass .internal .analysis .os .linux .core .registry .LinuxStyle ;
3539import org .eclipse .tracecompass .internal .analysis .profiling .core .instrumented .FlameChartDataProvider ;
3842import org .eclipse .tracecompass .internal .analysis .profiling .core .instrumented .FlameChartEntryModel .EntryType ;
3943import org .eclipse .tracecompass .internal .tmf .core .model .filters .FetchParametersUtils ;
4044import org .eclipse .tracecompass .tmf .core .dataprovider .IDataProviderDescriptor ;
45+ import org .eclipse .tracecompass .tmf .core .model .CommonStatusMessage ;
4146import org .eclipse .tracecompass .tmf .core .model .OutputElementStyle ;
47+ import org .eclipse .tracecompass .tmf .core .model .StyleProperties ;
48+ import org .eclipse .tracecompass .tmf .core .model .StyleProperties .SymbolType ;
4249import org .eclipse .tracecompass .tmf .core .model .filters .SelectionTimeQueryFilter ;
4350import org .eclipse .tracecompass .tmf .core .model .filters .TimeQueryFilter ;
4451import org .eclipse .tracecompass .tmf .core .model .timegraph .ITimeGraphArrow ;
4855import org .eclipse .tracecompass .tmf .core .model .timegraph .TimeGraphModel ;
4956import org .eclipse .tracecompass .tmf .core .model .timegraph .TimeGraphState ;
5057import org .eclipse .tracecompass .tmf .core .model .tree .TmfTreeModel ;
58+ import org .eclipse .tracecompass .tmf .core .model .annotations .Annotation ;
59+ //import org.eclipse.tracecompass.tmf.core.model.annotations.Annotation;
60+ import org .eclipse .tracecompass .tmf .core .model .annotations .AnnotationCategoriesModel ;
61+ import org .eclipse .tracecompass .tmf .core .model .annotations .AnnotationModel ;
5162import org .eclipse .tracecompass .tmf .core .response .ITmfResponse ;
5263import org .eclipse .tracecompass .tmf .core .response .TmfModelResponse ;
5364import org .junit .Test ;
@@ -63,6 +74,11 @@ public class FlameChartDataProviderTest extends CallStackTestBase2 {
6374
6475 private static final @ Nullable IProgressMonitor MONITOR = new NullProgressMonitor ();
6576 private static final String FOR_ENTRY = " for entry " ;
77+ private static final String CALLSTACKIEVENTS_FILE = "testfiles/traces/callstackIevents.xml" ;
78+
79+ public FlameChartDataProviderTest () {
80+ super ( CALLSTACKIEVENTS_FILE );
81+ }
6682
6783 private FlameChartDataProvider getDataProvider () {
6884 CallStackAnalysisStub module = getModule ();
@@ -436,10 +452,161 @@ private static void verifyStates(List<ITimeGraphRowModel> rowModels, FlameChartE
436452 }
437453 }
438454
455+ /**
456+ * Test fetching annotation categories
457+ */
458+ @ Test
459+ public void testFetchAnnotationCategories () {
460+ FlameChartDataProvider dataProvider = getDataProvider ();
461+
462+ TmfModelResponse <AnnotationCategoriesModel > response = dataProvider .fetchAnnotationCategories (Collections .emptyMap (), MONITOR );
463+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
464+ assertEquals (CommonStatusMessage .COMPLETED , response .getStatusMessage ());
465+
466+ AnnotationCategoriesModel model = response .getModel ();
467+ assertNotNull (model );
468+ assertEquals (1 , model .getAnnotationCategories ().size ());
469+ assertEquals (InstrumentedCallStackAnalysis .ANNOTATIONS , model .getAnnotationCategories ().get (0 ));
470+ }
471+
472+ /**
473+ * Test fetchAnnotations with empty result
474+ */
475+ @ Test
476+ public void testFetchAnnotations () {
477+ FlameChartDataProvider dataProvider = getDataProvider ();
478+ Map <String , Object > parameters = FetchParametersUtils .selectionTimeQueryToMap (
479+ new SelectionTimeQueryFilter (0 , Long .MAX_VALUE , 2 , Collections .emptySet ()));
480+ TmfModelResponse <AnnotationModel > response = dataProvider .fetchAnnotations (parameters , MONITOR );
481+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
482+ assertEquals (CommonStatusMessage .COMPLETED , response .getStatusMessage ());
483+
484+ AnnotationModel model = response .getModel ();
485+ assertNotNull (model );
486+ assertTrue (model .getAnnotations ().containsKey (InstrumentedCallStackAnalysis .ANNOTATIONS ));
487+ }
488+ /**
489+ * Test fetchAnnotations with null filter returns completed with null model
490+ */
491+ @ Test
492+ public void testFetchAnnotationsNullFilter () {
493+ FlameChartDataProvider dataProvider = getDataProvider ();
494+
495+ Map <String , Object > parameters = Collections .emptyMap ();
496+ TmfModelResponse <AnnotationModel > response = dataProvider .fetchAnnotations (parameters , MONITOR );
497+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
498+ assertEquals (CommonStatusMessage .COMPLETED , response .getStatusMessage ());
499+ assertNull (response .getModel ());
500+ }
501+
502+ /**
503+ * Test fetchAnnotations style
504+ */
505+ @ Test
506+ public void testFetchAnnotationsOutputElementStyle () {
507+ FlameChartDataProvider dataProvider = getDataProvider ();
508+
509+ // Get tree to find entry IDs
510+ TmfModelResponse <@ NonNull TmfTreeModel <@ NonNull FlameChartEntryModel >> treeResponse =
511+ dataProvider .fetchTree (FetchParametersUtils .timeQueryToMap (new TimeQueryFilter (0 , Long .MAX_VALUE , 2 )), null );
512+ TmfTreeModel <@ NonNull FlameChartEntryModel > model = treeResponse .getModel ();
513+
514+ if (model != null ) {
515+ List <FlameChartEntryModel > entries = model .getEntries ();
516+
517+ // Find a function entry that should have annotations
518+ FlameChartEntryModel functionEntry = entries .stream ()
519+ .filter (e -> e .getEntryType () == EntryType .FUNCTION )
520+ .findFirst ()
521+ .orElse (null );
522+ assertNotNull (functionEntry );
523+
524+ // 15 and 18 are timestamps with instant events
525+ Map <String , Object > fetchParams = FetchParametersUtils .selectionTimeQueryToMap (
526+ new SelectionTimeQueryFilter (15 , 18 , 2 , Collections .singleton (functionEntry .getId ())));
527+
528+ // Fetch annotations
529+ TmfModelResponse <AnnotationModel > response = dataProvider .fetchAnnotations (fetchParams , MONITOR );
530+
531+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
532+ AnnotationModel m = response .getModel ();
533+ assertNotNull (m );
534+ Collection <@ NonNull Annotation > annotations = m .getAnnotations ().get (InstrumentedCallStackAnalysis .ANNOTATIONS );
535+ assertNotNull (annotations );
536+ assertFalse (annotations .isEmpty ());
537+
538+ // Verify OutputElementStyle properties
539+ Annotation annotation = annotations .iterator ().next ();
540+ OutputElementStyle style = annotation .getStyle ();
541+ assertNotNull (style );
542+
543+ Map <String , Object > styleMap = style .getStyleValues ();
544+ assertEquals ("#7D3D31" , styleMap .get (StyleProperties .COLOR ));
545+ assertEquals (0.33f , styleMap .get (StyleProperties .HEIGHT ));
546+ assertEquals (SymbolType .DIAMOND , styleMap .get (StyleProperties .SYMBOL_TYPE ));
547+ }
548+
549+ }
550+
551+ /**
552+ * Test annotation model structure and properties
553+ */
554+ @ Test
555+ public void testAnnotationModelStructure () {
556+ FlameChartDataProvider dataProvider = getDataProvider ();
557+
558+ Map <String , Object > parameters = FetchParametersUtils .selectionTimeQueryToMap (
559+ new SelectionTimeQueryFilter (0 , Long .MAX_VALUE , 2 ,Collections .emptySet ()));
560+ TmfModelResponse <AnnotationModel > response = dataProvider .fetchAnnotations (parameters , MONITOR );
561+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
562+
563+ AnnotationModel model = response .getModel ();
564+ assertNotNull (model );
565+
566+ assertEquals (1 , model .getAnnotations ().size ());
567+ assertTrue (model .getAnnotations ().containsKey (InstrumentedCallStackAnalysis .ANNOTATIONS ));
568+ assertNotNull (model .getAnnotations ().get (InstrumentedCallStackAnalysis .ANNOTATIONS ));
569+ }
570+
571+ /**
572+ * Test annotation model structure and properties
573+ */
574+ @ SuppressWarnings ("null" )
575+ @ Test
576+ public void testFetchValidAnnotations () {
577+ FlameChartDataProvider dataProvider = getDataProvider ();
578+ TmfModelResponse <@ NonNull TmfTreeModel <@ NonNull FlameChartEntryModel >> treeResponse =
579+ dataProvider .fetchTree (FetchParametersUtils .timeQueryToMap (new TimeQueryFilter (1 , Long .MAX_VALUE , 2 )), MONITOR );
580+ assertEquals (ITmfResponse .Status .COMPLETED , treeResponse .getStatus ());
581+
582+ TmfTreeModel <@ NonNull FlameChartEntryModel > m = treeResponse .getModel ();
583+ // Get entry IDs from the same tree response
584+ if (m != null ) {
585+ Set <Long > allEntryIds = m .getEntries ().stream ()
586+ .map (FlameChartEntryModel ::getId )
587+ .collect (Collectors .toSet ());
588+
589+
590+ Map <String , Object > parameters = FetchParametersUtils .selectionTimeQueryToMap (
591+ new SelectionTimeQueryFilter (1 , Long .MAX_VALUE , 2 , allEntryIds ));
592+
593+ TmfModelResponse <AnnotationModel > response = dataProvider .fetchAnnotations (parameters , MONITOR );
594+
595+ assertNotNull (response );
596+ assertEquals (ITmfResponse .Status .COMPLETED , response .getStatus ());
597+
598+ AnnotationModel model = response .getModel ();
599+ assertNotNull (model );
600+
601+ Map <String , Collection <Annotation >> annotations = model .getAnnotations ();
602+ assertNotNull (annotations );
603+ }
604+ }
605+
439606 private static void verifyArrows (List <ITimeGraphArrow > arrows , List <ITimeGraphArrow > expectedArrows ) {
440607 assertEquals (expectedArrows .size (), arrows .size ());
441608 for (ITimeGraphArrow expectedArrow : expectedArrows ) {
442- for (ITimeGraphArrow arrow : arrows ) {
609+ for (ITimeGraphArrow arrow : arrows ) {
443610 if (arrow .getValue () == expectedArrow .getValue ()) {
444611 assertEquals ("Duration for arrow " + arrow .getValue (), expectedArrow .getDuration (), arrow .getDuration ());
445612 assertEquals ("Start time for arrow " + arrow .getValue (), expectedArrow .getStartTime (), arrow .getStartTime ());
0 commit comments