• 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     final private ThreadData mThreadData;
23     final private MethodData mMethodData;
24     final Call mCaller; // the caller, or null if this is the root
25 
26     private String mName;
27     private boolean mIsRecursive;
28 
29     long mGlobalStartTime;
30     long mGlobalEndTime;
31 
32     long mThreadStartTime;
33     long mThreadEndTime;
34 
35     long mInclusiveRealTime; // real time spent in this call including its children
36     long mExclusiveRealTime; // real time spent in this call including its children
37 
38     long mInclusiveCpuTime; // cpu time spent in this call including its children
39     long mExclusiveCpuTime; // cpu time spent in this call excluding its children
40 
Call(ThreadData threadData, MethodData methodData, Call caller)41     Call(ThreadData threadData, MethodData methodData, Call caller) {
42         mThreadData = threadData;
43         mMethodData = methodData;
44         mName = methodData.getProfileName();
45         mCaller = caller;
46     }
47 
updateName()48     public void updateName() {
49         mName = mMethodData.getProfileName();
50     }
51 
addWeight(int x, int y, double weight)52     public double addWeight(int x, int y, double weight) {
53         return mMethodData.addWeight(x, y, weight);
54     }
55 
clearWeight()56     public void clearWeight() {
57         mMethodData.clearWeight();
58     }
59 
getStartTime()60     public long getStartTime() {
61         return mGlobalStartTime;
62     }
63 
getEndTime()64     public long getEndTime() {
65         return mGlobalEndTime;
66     }
67 
getExclusiveCpuTime()68     public long getExclusiveCpuTime() {
69         return mExclusiveCpuTime;
70     }
71 
getInclusiveCpuTime()72     public long getInclusiveCpuTime() {
73         return mInclusiveCpuTime;
74     }
75 
getExclusiveRealTime()76     public long getExclusiveRealTime() {
77         return mExclusiveRealTime;
78     }
79 
getInclusiveRealTime()80     public long getInclusiveRealTime() {
81         return mInclusiveRealTime;
82     }
83 
getColor()84     public Color getColor() {
85         return mMethodData.getColor();
86     }
87 
getName()88     public String getName() {
89         return mName;
90     }
91 
setName(String name)92     public void setName(String name) {
93         mName = name;
94     }
95 
getThreadData()96     public ThreadData getThreadData() {
97         return mThreadData;
98     }
99 
getThreadId()100     public int getThreadId() {
101         return mThreadData.getId();
102     }
103 
getMethodData()104     public MethodData getMethodData() {
105         return mMethodData;
106     }
107 
isContextSwitch()108     public boolean isContextSwitch() {
109         return mMethodData.getId() < 0;
110     }
111 
isIgnoredBlock()112     public boolean isIgnoredBlock() {
113         // Ignore the top-level call or context switches within the top-level call.
114         return mCaller == null || isContextSwitch() && mCaller.mCaller == null;
115     }
116 
getParentBlock()117     public TimeLineView.Block getParentBlock() {
118         return mCaller;
119     }
120 
isRecursive()121     public boolean isRecursive() {
122         return mIsRecursive;
123     }
124 
setRecursive(boolean isRecursive)125     void setRecursive(boolean isRecursive) {
126         mIsRecursive = isRecursive;
127     }
128 
addCpuTime(long elapsedCpuTime)129     void addCpuTime(long elapsedCpuTime) {
130         mExclusiveCpuTime += elapsedCpuTime;
131         mInclusiveCpuTime += elapsedCpuTime;
132     }
133 
134     /**
135      * Record time spent in the method call.
136      */
finish()137     void finish() {
138         if (mCaller != null) {
139             mCaller.mInclusiveCpuTime += mInclusiveCpuTime;
140             mCaller.mInclusiveRealTime += mInclusiveRealTime;
141         }
142 
143         mMethodData.addElapsedExclusive(mExclusiveCpuTime, mExclusiveRealTime);
144         if (!mIsRecursive) {
145             mMethodData.addTopExclusive(mExclusiveCpuTime, mExclusiveRealTime);
146         }
147         mMethodData.addElapsedInclusive(mInclusiveCpuTime, mInclusiveRealTime,
148                 mIsRecursive, mCaller);
149     }
150 
151     public static final class TraceAction {
152         public static final int ACTION_ENTER = 0;
153         public static final int ACTION_EXIT = 1;
154 
155         public final int mAction;
156         public final Call mCall;
157 
TraceAction(int action, Call call)158         public TraceAction(int action, Call call) {
159             mAction = action;
160             mCall = call;
161         }
162     }
163 }
164