• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package com.android.traceview;
18 
19 import org.eclipse.swt.graphics.Color;
20 
21 class Call implements TimeLineView.Block {
22 
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;
26 
27     private int mThreadId;
28     private int mFlags;
29     MethodData mMethodData;
30 
31     /** 0-based thread-local start time */
32     long mThreadStartTime;
33 
34     /**  global start time */
35     long mGlobalStartTime;
36 
37     /** global end time */
38     long mGlobalEndTime;
39 
40     private String mName;
41 
42     /**
43      * This constructor is used for the root of a Call tree. The name is
44      * the name of the corresponding thread.
45      */
Call(String name, MethodData methodData)46     Call(String name, MethodData methodData) {
47         mName = name;
48         mMethodData = methodData;
49     }
50 
Call()51     Call() {
52     }
53 
Call(int threadId, MethodData methodData, long time, int methodAction)54     Call(int threadId, MethodData methodData, long time, int methodAction) {
55         mThreadId = threadId;
56         mMethodData = methodData;
57         mThreadStartTime = time;
58         mFlags = methodAction & METHOD_ACTION_MASK;
59         mName = methodData.getProfileName();
60     }
61 
set(int threadId, MethodData methodData, long time, int methodAction)62     public void set(int threadId, MethodData methodData, long time, int methodAction) {
63         mThreadId = threadId;
64         mMethodData = methodData;
65         mThreadStartTime = time;
66         mFlags = methodAction & METHOD_ACTION_MASK;
67         mName = methodData.getProfileName();
68     }
69 
updateName()70     public void updateName() {
71         mName = mMethodData.getProfileName();
72     }
73 
addWeight(int x, int y, double weight)74     public double addWeight(int x, int y, double weight) {
75         return mMethodData.addWeight(x, y, weight);
76     }
77 
clearWeight()78     public void clearWeight() {
79         mMethodData.clearWeight();
80     }
81 
getStartTime()82     public long getStartTime() {
83         return mGlobalStartTime;
84     }
85 
getEndTime()86     public long getEndTime() {
87         return mGlobalEndTime;
88     }
89 
getColor()90     public Color getColor() {
91         return mMethodData.getColor();
92     }
93 
addExclusiveTime(long elapsed)94     public void addExclusiveTime(long elapsed) {
95         mMethodData.addElapsedExclusive(elapsed);
96         if ((mFlags & IS_RECURSIVE) == 0) {
97             mMethodData.addTopExclusive(elapsed);
98         }
99     }
100 
addInclusiveTime(long elapsed, Call parent)101     public void addInclusiveTime(long elapsed, Call parent) {
102         boolean isRecursive = (mFlags & IS_RECURSIVE) != 0;
103         mMethodData.addElapsedInclusive(elapsed, isRecursive, parent);
104     }
105 
getName()106     public String getName() {
107         return mName;
108     }
109 
setName(String name)110     public void setName(String name) {
111         mName = name;
112     }
113 
getThreadId()114     int getThreadId() {
115         return mThreadId;
116     }
117 
getMethodData()118     public MethodData getMethodData() {
119         return mMethodData;
120     }
121 
getMethodAction()122     int getMethodAction() {
123         return mFlags & METHOD_ACTION_MASK;
124     }
125 
dump()126     public void dump() {
127         System.out.printf("%s [%d, %d]\n", mName, mGlobalStartTime, mGlobalEndTime);
128     }
129 
setRecursive(boolean isRecursive)130     public void setRecursive(boolean isRecursive) {
131         if (isRecursive) {
132             mFlags |= IS_RECURSIVE;
133         } else {
134             mFlags &= ~IS_RECURSIVE;
135         }
136     }
137 
isRecursive()138     public boolean isRecursive() {
139         return (mFlags & IS_RECURSIVE) != 0;
140     }
141 }
142