2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.traceview;
19 import org.eclipse.swt.graphics.Color;
21 class Call implements TimeLineView.Block {
23 // Values for bits within the mFlags field.
24 private static final int METHOD_ACTION_MASK = 0x3;
25 private static final int IS_RECURSIVE = 0x10;
27 private int mThreadId;
29 MethodData mMethodData;
31 /** 0-based thread-local start time */
32 long mThreadStartTime;
34 /** global start time */
35 long mGlobalStartTime;
37 /** global end time */
43 * This constructor is used for the root of a Call tree. The name is
44 * the name of the corresponding thread.
46 Call(String name, MethodData methodData) {
48 mMethodData = methodData;
54 Call(int threadId, MethodData methodData, long time, int methodAction) {
56 mMethodData = methodData;
57 mThreadStartTime = time;
58 mFlags = methodAction & METHOD_ACTION_MASK;
59 mName = methodData.getProfileName();
62 public void set(int threadId, MethodData methodData, long time, int methodAction) {
64 mMethodData = methodData;
65 mThreadStartTime = time;
66 mFlags = methodAction & METHOD_ACTION_MASK;
67 mName = methodData.getProfileName();
70 public void updateName() {
71 mName = mMethodData.getProfileName();
74 public double addWeight(int x, int y, double weight) {
75 return mMethodData.addWeight(x, y, weight);
78 public void clearWeight() {
79 mMethodData.clearWeight();
82 public long getStartTime() {
83 return mGlobalStartTime;
86 public long getEndTime() {
87 return mGlobalEndTime;
90 public Color getColor() {
91 return mMethodData.getColor();
94 public void addExclusiveTime(long elapsed) {
95 mMethodData.addElapsedExclusive(elapsed);
96 if ((mFlags & IS_RECURSIVE) == 0) {
97 mMethodData.addTopExclusive(elapsed);
101 public void addInclusiveTime(long elapsed, Call parent) {
102 boolean isRecursive = (mFlags & IS_RECURSIVE) != 0;
103 mMethodData.addElapsedInclusive(elapsed, isRecursive, parent);
106 public String getName() {
110 public void setName(String name) {
118 public MethodData getMethodData() {
122 int getMethodAction() {
123 return mFlags & METHOD_ACTION_MASK;
127 System.out.printf("%s [%d, %d]\n", mName, mGlobalStartTime, mGlobalEndTime);
130 public void setRecursive(boolean isRecursive) {
132 mFlags |= IS_RECURSIVE;
134 mFlags &= ~IS_RECURSIVE;
138 public boolean isRecursive() {
139 return (mFlags & IS_RECURSIVE) != 0;