• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7base.require('tracing.analysis.analyze_counters');
8base.require('tracing.analysis.analyze_slices');
9base.require('tracing.analysis.util');
10base.require('ui');
11base.exportTo('tracing.analysis', function() {
12
13  /**
14   * Analyzes the selection, outputting the analysis results into the provided
15   * results object.
16   *
17   * @param {AnalysisResults} results Where the analysis is placed.
18   * @param {Selection} selection What to analyze.
19   */
20  function analyzeSelection(results, selection) {
21    analyzeHitsByType(results, selection.getHitsOrganizedByType());
22  }
23
24  function analyzeHitsByType(results, hitsByType) {
25    var sliceHits = hitsByType.slices;
26    var counterSampleHits = hitsByType.counterSamples;
27    var objectHits = new tracing.Selection();
28    objectHits.addSelection(hitsByType.objectSnapshots);
29    objectHits.addSelection(hitsByType.objectInstances);
30
31    if (sliceHits.length == 1) {
32      tracing.analysis.analyzeSingleSliceHit(results, sliceHits[0]);
33    } else if (sliceHits.length > 1) {
34      tracing.analysis.analyzeMultipleSliceHits(results, sliceHits);
35    }
36
37    if (counterSampleHits.length == 1) {
38      tracing.analysis.analyzeSingleCounterSampleHit(
39          results, counterSampleHits[0]);
40    } else if (counterSampleHits.length > 1) {
41      tracing.analysis.analyzeMultipleCounterSampleHits(
42          results, counterSampleHits);
43    }
44
45    if (objectHits.length)
46      analyzeObjectHits(results, objectHits);
47  }
48
49  /**
50   * Extremely simplistic analysis of objects. Mainly exists to provide
51   * click-through to the main object's analysis view.
52   */
53  function analyzeObjectHits(results, objectHits) {
54    objectHits = base.asArray(objectHits).sort(base.Range.compareByMinTimes);
55
56    var table = results.appendTable('analysis-object-sample-table', 2);
57    results.appendTableHeader(table, 'Selected Objects:');
58
59    objectHits.forEach(function(hit) {
60      var row = results.appendTableRow(table);
61      var ts;
62      var objectText;
63      var selectionGenerator;
64      if (hit instanceof tracing.SelectionObjectSnapshotHit) {
65        var objectSnapshot = hit.objectSnapshot;
66        ts = tracing.analysis.tsRound(objectSnapshot.ts);
67        objectText = objectSnapshot.objectInstance.typeName + ' ' +
68            objectSnapshot.objectInstance.id;
69        selectionGenerator = function() {
70          var selection = new tracing.Selection();
71          selection.addObjectSnapshot(hit.track, objectSnapshot);
72          return selection;
73        };
74      } else {
75        var objectInstance = hit.objectInstance;
76
77        var deletionTs = objectInstance.deletionTs == Number.MAX_VALUE ?
78            '' : tracing.analysis.tsRound(objectInstance.deletionTs);
79        ts = tracing.analysis.tsRound(objectInstance.creationTs) +
80            '-' + deletionTs;
81
82        objectText = objectInstance.typeName + ' ' +
83            objectInstance.id;
84
85        selectionGenerator = function() {
86          var selection = new tracing.Selection();
87          selection.addObjectInstance(hit.track, objectInstance);
88          return selection;
89        };
90      }
91
92      results.appendTableCell(table, row, ts);
93      var linkContainer = results.appendTableCell(table, row, '');
94      linkContainer.appendChild(
95          results.createSelectionChangingLink(objectText, selectionGenerator));
96    });
97  }
98
99  return {
100    analyzeSelection: analyzeSelection,
101    analyzeHitsByType: analyzeHitsByType
102  };
103});
104