1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/guid.html">
9<link rel="import" href="/tracing/base/range_utils.html">
10<link rel="import" href="/tracing/core/auditor.html">
11<link rel="import" href="/tracing/model/helpers/android_app.html">
12<link rel="import" href="/tracing/model/helpers/android_surface_flinger.html">
13
14<script>
15'use strict';
16
17/**
18 * @fileoverview Class for managing android-specific model meta data,
19 * such as rendering apps, frames rendered, and SurfaceFlinger.
20 */
21tr.exportTo('tr.model.helpers', function() {
22  var AndroidApp = tr.model.helpers.AndroidApp;
23  var AndroidSurfaceFlinger = tr.model.helpers.AndroidSurfaceFlinger;
24
25  var IMPORTANT_SURFACE_FLINGER_SLICES = {
26    'doComposition' : true,
27    'updateTexImage' : true,
28    'postFramebuffer' : true
29  };
30  var IMPORTANT_UI_THREAD_SLICES = {
31    'Choreographer#doFrame' : true,
32    'performTraversals' : true,
33    'deliverInputEvent' : true
34  };
35  var IMPORTANT_RENDER_THREAD_SLICES = {
36    'doFrame' : true
37  };
38
39  function iterateImportantThreadSlices(thread, important, callback) {
40    if (!thread)
41      return;
42
43    thread.sliceGroup.slices.forEach(function(slice) {
44      if (slice.title in important)
45        callback(slice);
46    });
47  }
48
49  /**
50   * Model for Android-specific data.
51   * @constructor
52   */
53  function AndroidModelHelper(model) {
54    this.model = model;
55    this.apps = [];
56    this.surfaceFlinger = undefined;
57
58    var processes = model.getAllProcesses();
59    for (var i = 0; i < processes.length && !this.surfaceFlinger; i++) {
60      this.surfaceFlinger =
61          AndroidSurfaceFlinger.createForProcessIfPossible(processes[i]);
62    }
63
64    model.getAllProcesses().forEach(function(process) {
65      var app = AndroidApp.createForProcessIfPossible(
66          process, this.surfaceFlinger);
67      if (app)
68        this.apps.push(app);
69    }, this);
70  };
71
72  AndroidModelHelper.guid = tr.b.GUID.allocate();
73
74  AndroidModelHelper.supportsModel = function(model) {
75    return true;
76  };
77
78  AndroidModelHelper.prototype = {
79    iterateImportantSlices: function(callback) {
80      if (this.surfaceFlinger) {
81        iterateImportantThreadSlices(
82            this.surfaceFlinger.thread,
83            IMPORTANT_SURFACE_FLINGER_SLICES,
84            callback);
85      }
86
87      this.apps.forEach(function(app) {
88        iterateImportantThreadSlices(
89            app.uiThread,
90            IMPORTANT_UI_THREAD_SLICES,
91            callback);
92        iterateImportantThreadSlices(
93            app.renderThread,
94            IMPORTANT_RENDER_THREAD_SLICES,
95            callback);
96      });
97    }
98  };
99
100  return {
101    AndroidModelHelper: AndroidModelHelper
102  };
103});
104</script>
105