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 52 @Override addWeight(int x, int y, double weight)53 public double addWeight(int x, int y, double weight) { 54 return mMethodData.addWeight(x, y, weight); 55 } 56 57 @Override clearWeight()58 public void clearWeight() { 59 mMethodData.clearWeight(); 60 } 61 62 @Override getStartTime()63 public long getStartTime() { 64 return mGlobalStartTime; 65 } 66 67 @Override getEndTime()68 public long getEndTime() { 69 return mGlobalEndTime; 70 } 71 72 @Override getExclusiveCpuTime()73 public long getExclusiveCpuTime() { 74 return mExclusiveCpuTime; 75 } 76 77 @Override getInclusiveCpuTime()78 public long getInclusiveCpuTime() { 79 return mInclusiveCpuTime; 80 } 81 82 @Override getExclusiveRealTime()83 public long getExclusiveRealTime() { 84 return mExclusiveRealTime; 85 } 86 87 @Override getInclusiveRealTime()88 public long getInclusiveRealTime() { 89 return mInclusiveRealTime; 90 } 91 92 @Override getColor()93 public Color getColor() { 94 return mMethodData.getColor(); 95 } 96 97 @Override getName()98 public String getName() { 99 return mName; 100 } 101 setName(String name)102 public void setName(String name) { 103 mName = name; 104 } 105 getThreadData()106 public ThreadData getThreadData() { 107 return mThreadData; 108 } 109 getThreadId()110 public int getThreadId() { 111 return mThreadData.getId(); 112 } 113 114 @Override getMethodData()115 public MethodData getMethodData() { 116 return mMethodData; 117 } 118 119 @Override isContextSwitch()120 public boolean isContextSwitch() { 121 return mMethodData.getId() < 0; 122 } 123 124 @Override isIgnoredBlock()125 public boolean isIgnoredBlock() { 126 // Ignore the top-level call or context switches within the top-level call. 127 return mCaller == null || isContextSwitch() && mCaller.mCaller == null; 128 } 129 130 @Override getParentBlock()131 public TimeLineView.Block getParentBlock() { 132 return mCaller; 133 } 134 isRecursive()135 public boolean isRecursive() { 136 return mIsRecursive; 137 } 138 setRecursive(boolean isRecursive)139 void setRecursive(boolean isRecursive) { 140 mIsRecursive = isRecursive; 141 } 142 addCpuTime(long elapsedCpuTime)143 void addCpuTime(long elapsedCpuTime) { 144 mExclusiveCpuTime += elapsedCpuTime; 145 mInclusiveCpuTime += elapsedCpuTime; 146 } 147 148 /** 149 * Record time spent in the method call. 150 */ finish()151 void finish() { 152 if (mCaller != null) { 153 mCaller.mInclusiveCpuTime += mInclusiveCpuTime; 154 mCaller.mInclusiveRealTime += mInclusiveRealTime; 155 } 156 157 mMethodData.addElapsedExclusive(mExclusiveCpuTime, mExclusiveRealTime); 158 if (!mIsRecursive) { 159 mMethodData.addTopExclusive(mExclusiveCpuTime, mExclusiveRealTime); 160 } 161 mMethodData.addElapsedInclusive(mInclusiveCpuTime, mInclusiveRealTime, 162 mIsRecursive, mCaller); 163 } 164 165 public static final class TraceAction { 166 public static final int ACTION_ENTER = 0; 167 public static final int ACTION_EXIT = 1; 168 169 public final int mAction; 170 public final Call mCall; 171 TraceAction(int action, Call call)172 public TraceAction(int action, Call call) { 173 mAction = action; 174 mCall = call; 175 } 176 } 177 } 178