|
24 | 24 | import java.util.List; |
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.Objects; |
| 27 | + |
27 | 28 | import java.util.Set; |
| 29 | +//import java.util.stream.Collectors; |
| 30 | +import java.util.stream.Collectors; |
28 | 31 |
|
29 | 32 | import org.eclipse.core.runtime.IProgressMonitor; |
30 | 33 | import org.eclipse.core.runtime.NullProgressMonitor; |
31 | 34 | import org.eclipse.jdt.annotation.NonNull; |
32 | 35 | import org.eclipse.jdt.annotation.Nullable; |
| 36 | +import org.eclipse.tracecompass.analysis.profiling.core.instrumented.InstrumentedCallStackAnalysis; |
33 | 37 | import org.eclipse.tracecompass.analysis.profiling.core.tests.stubs2.CallStackAnalysisStub; |
34 | 38 | import org.eclipse.tracecompass.internal.analysis.os.linux.core.registry.LinuxStyle; |
35 | 39 | import org.eclipse.tracecompass.internal.analysis.profiling.core.instrumented.FlameChartDataProvider; |
|
38 | 42 | import org.eclipse.tracecompass.internal.analysis.profiling.core.instrumented.FlameChartEntryModel.EntryType; |
39 | 43 | import org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils; |
40 | 44 | import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; |
| 45 | +import org.eclipse.tracecompass.tmf.core.model.CommonStatusMessage; |
41 | 46 | import 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; |
42 | 49 | import org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter; |
43 | 50 | import org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter; |
44 | 51 | import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow; |
|
48 | 55 | import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel; |
49 | 56 | import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState; |
50 | 57 | import 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; |
51 | 62 | import org.eclipse.tracecompass.tmf.core.response.ITmfResponse; |
52 | 63 | import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse; |
53 | 64 | import org.junit.Test; |
@@ -436,10 +447,161 @@ private static void verifyStates(List<ITimeGraphRowModel> rowModels, FlameChartE |
436 | 447 | } |
437 | 448 | } |
438 | 449 |
|
| 450 | + /** |
| 451 | + * Test fetching annotation categories |
| 452 | + */ |
| 453 | + @Test |
| 454 | + public void testFetchAnnotationCategories() { |
| 455 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 456 | + |
| 457 | + TmfModelResponse<AnnotationCategoriesModel> response = dataProvider.fetchAnnotationCategories(Collections.emptyMap(), MONITOR); |
| 458 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 459 | + assertEquals(CommonStatusMessage.COMPLETED, response.getStatusMessage()); |
| 460 | + |
| 461 | + AnnotationCategoriesModel model = response.getModel(); |
| 462 | + assertNotNull(model); |
| 463 | + assertEquals(1, model.getAnnotationCategories().size()); |
| 464 | + assertEquals(InstrumentedCallStackAnalysis.ANNOTATIONS, model.getAnnotationCategories().get(0)); |
| 465 | + } |
| 466 | + |
| 467 | + /** |
| 468 | + * Test fetchAnnotations with empty result |
| 469 | + */ |
| 470 | + @Test |
| 471 | + public void testFetchAnnotations() { |
| 472 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 473 | + Map<String, Object> parameters = FetchParametersUtils.selectionTimeQueryToMap( |
| 474 | + new SelectionTimeQueryFilter(0, Long.MAX_VALUE, 2, Collections.emptySet())); |
| 475 | + TmfModelResponse<AnnotationModel> response = dataProvider.fetchAnnotations(parameters, MONITOR); |
| 476 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 477 | + assertEquals(CommonStatusMessage.COMPLETED, response.getStatusMessage()); |
| 478 | + |
| 479 | + AnnotationModel model = response.getModel(); |
| 480 | + assertNotNull(model); |
| 481 | + assertTrue(model.getAnnotations().containsKey(InstrumentedCallStackAnalysis.ANNOTATIONS)); |
| 482 | + } |
| 483 | + /** |
| 484 | + * Test fetchAnnotations with null filter returns completed with null model |
| 485 | + */ |
| 486 | + @Test |
| 487 | + public void testFetchAnnotationsNullFilter() { |
| 488 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 489 | + |
| 490 | + Map<String, Object> parameters = Collections.emptyMap(); |
| 491 | + TmfModelResponse<AnnotationModel> response = dataProvider.fetchAnnotations(parameters, MONITOR); |
| 492 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 493 | + assertEquals(CommonStatusMessage.COMPLETED, response.getStatusMessage()); |
| 494 | + assertNull(response.getModel()); |
| 495 | + } |
| 496 | + |
| 497 | + /** |
| 498 | + * Test fetchAnnotations style |
| 499 | + */ |
| 500 | + @Test |
| 501 | + public void testFetchAnnotationsOutputElementStyle() { |
| 502 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 503 | + |
| 504 | + // Get tree to find entry IDs |
| 505 | + TmfModelResponse<@NonNull TmfTreeModel<@NonNull FlameChartEntryModel>> treeResponse = |
| 506 | + dataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), null); |
| 507 | + TmfTreeModel<@NonNull FlameChartEntryModel> model = treeResponse.getModel(); |
| 508 | + |
| 509 | + if (model != null) { |
| 510 | + List<FlameChartEntryModel> entries = model.getEntries(); |
| 511 | + |
| 512 | + // Find a function entry that should have annotations |
| 513 | + FlameChartEntryModel functionEntry = entries.stream() |
| 514 | + .filter(e -> e.getEntryType() == EntryType.FUNCTION) |
| 515 | + .findFirst() |
| 516 | + .orElse(null); |
| 517 | + assertNotNull(functionEntry); |
| 518 | + |
| 519 | + // 15 and 18 are timestamps with instant events |
| 520 | + Map<String, Object> fetchParams = FetchParametersUtils.selectionTimeQueryToMap( |
| 521 | + new SelectionTimeQueryFilter(15, 18, 2, Collections.singleton(functionEntry.getId()))); |
| 522 | + |
| 523 | + // Fetch annotations |
| 524 | + TmfModelResponse<AnnotationModel> response = dataProvider.fetchAnnotations(fetchParams, MONITOR); |
| 525 | + |
| 526 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 527 | + AnnotationModel m = response.getModel(); |
| 528 | + assertNotNull(m); |
| 529 | + Collection<@NonNull Annotation> annotations = m.getAnnotations().get(InstrumentedCallStackAnalysis.ANNOTATIONS); |
| 530 | + assertNotNull(annotations); |
| 531 | + assertFalse(annotations.isEmpty()); |
| 532 | + |
| 533 | + // Verify OutputElementStyle properties |
| 534 | + Annotation annotation = annotations.iterator().next(); |
| 535 | + OutputElementStyle style = annotation.getStyle(); |
| 536 | + assertNotNull(style); |
| 537 | + |
| 538 | + Map<String, Object> styleMap = style.getStyleValues(); |
| 539 | + assertEquals("#7D3D31", styleMap.get(StyleProperties.COLOR)); |
| 540 | + assertEquals(0.33f, styleMap.get(StyleProperties.HEIGHT)); |
| 541 | + assertEquals(SymbolType.DIAMOND, styleMap.get(StyleProperties.SYMBOL_TYPE)); |
| 542 | + } |
| 543 | + |
| 544 | + } |
| 545 | + |
| 546 | + /** |
| 547 | + * Test annotation model structure and properties |
| 548 | + */ |
| 549 | + @Test |
| 550 | + public void testAnnotationModelStructure() { |
| 551 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 552 | + |
| 553 | + Map<String, Object> parameters = FetchParametersUtils.selectionTimeQueryToMap( |
| 554 | + new SelectionTimeQueryFilter(0, Long.MAX_VALUE, 2,Collections.emptySet())); |
| 555 | + TmfModelResponse<AnnotationModel> response = dataProvider.fetchAnnotations(parameters, MONITOR); |
| 556 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 557 | + |
| 558 | + AnnotationModel model = response.getModel(); |
| 559 | + assertNotNull(model); |
| 560 | + |
| 561 | + assertEquals(1, model.getAnnotations().size()); |
| 562 | + assertTrue(model.getAnnotations().containsKey(InstrumentedCallStackAnalysis.ANNOTATIONS)); |
| 563 | + assertNotNull(model.getAnnotations().get(InstrumentedCallStackAnalysis.ANNOTATIONS)); |
| 564 | + } |
| 565 | + |
| 566 | +/** |
| 567 | + * Test annotation model structure and properties |
| 568 | + */ |
| 569 | +@SuppressWarnings("null") |
| 570 | +@Test |
| 571 | + public void testFetchValidAnnotations() { |
| 572 | + FlameChartDataProvider dataProvider = getDataProvider(); |
| 573 | + TmfModelResponse<@NonNull TmfTreeModel<@NonNull FlameChartEntryModel>> treeResponse = |
| 574 | + dataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(1, Long.MAX_VALUE, 2)), MONITOR); |
| 575 | + assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus()); |
| 576 | + |
| 577 | + TmfTreeModel<@NonNull FlameChartEntryModel> m = treeResponse.getModel(); |
| 578 | + // Get entry IDs from the same tree response |
| 579 | + if(m != null) { |
| 580 | + Set<Long> allEntryIds = m.getEntries().stream() |
| 581 | + .map(FlameChartEntryModel::getId) |
| 582 | + .collect(Collectors.toSet()); |
| 583 | + |
| 584 | + |
| 585 | + Map<String, Object> parameters = FetchParametersUtils.selectionTimeQueryToMap( |
| 586 | + new SelectionTimeQueryFilter(1, Long.MAX_VALUE, 2, allEntryIds)); |
| 587 | + |
| 588 | + TmfModelResponse<AnnotationModel> response = dataProvider.fetchAnnotations(parameters, MONITOR); |
| 589 | + |
| 590 | + assertNotNull(response); |
| 591 | + assertEquals(ITmfResponse.Status.COMPLETED, response.getStatus()); |
| 592 | + |
| 593 | + AnnotationModel model = response.getModel(); |
| 594 | + assertNotNull(model); |
| 595 | + |
| 596 | + Map<String, Collection<Annotation>> annotations = model.getAnnotations(); |
| 597 | + assertNotNull(annotations ); |
| 598 | + } |
| 599 | + } |
| 600 | + |
439 | 601 | private static void verifyArrows(List<ITimeGraphArrow> arrows, List<ITimeGraphArrow> expectedArrows) { |
440 | 602 | assertEquals(expectedArrows.size(), arrows.size()); |
441 | 603 | for (ITimeGraphArrow expectedArrow : expectedArrows) { |
442 | | - for (ITimeGraphArrow arrow: arrows) { |
| 604 | + for (ITimeGraphArrow arrow : arrows) { |
443 | 605 | if (arrow.getValue() == expectedArrow.getValue()) { |
444 | 606 | assertEquals("Duration for arrow " + arrow.getValue(), expectedArrow.getDuration(), arrow.getDuration()); |
445 | 607 | assertEquals("Start time for arrow " + arrow.getValue(), expectedArrow.getStartTime(), arrow.getStartTime()); |
|
0 commit comments