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 20 public class ProfileData { 21 22 protected MethodData mElement; 23 24 /** mContext is either the parent or child of mElement */ 25 protected MethodData mContext; 26 protected boolean mElementIsParent; 27 protected long mElapsedInclusiveCpuTime; 28 protected long mElapsedInclusiveRealTime; 29 protected int mNumCalls; 30 ProfileData()31 public ProfileData() { 32 } 33 ProfileData(MethodData context, MethodData element, boolean elementIsParent)34 public ProfileData(MethodData context, MethodData element, 35 boolean elementIsParent) { 36 mContext = context; 37 mElement = element; 38 mElementIsParent = elementIsParent; 39 } 40 getProfileName()41 public String getProfileName() { 42 return mElement.getProfileName(); 43 } 44 getMethodData()45 public MethodData getMethodData() { 46 return mElement; 47 } 48 addElapsedInclusive(long cpuTime, long realTime)49 public void addElapsedInclusive(long cpuTime, long realTime) { 50 mElapsedInclusiveCpuTime += cpuTime; 51 mElapsedInclusiveRealTime += realTime; 52 mNumCalls += 1; 53 } 54 setElapsedInclusive(long cpuTime, long realTime)55 public void setElapsedInclusive(long cpuTime, long realTime) { 56 mElapsedInclusiveCpuTime = cpuTime; 57 mElapsedInclusiveRealTime = realTime; 58 } 59 getElapsedInclusiveCpuTime()60 public long getElapsedInclusiveCpuTime() { 61 return mElapsedInclusiveCpuTime; 62 } 63 getElapsedInclusiveRealTime()64 public long getElapsedInclusiveRealTime() { 65 return mElapsedInclusiveRealTime; 66 } 67 setNumCalls(int numCalls)68 public void setNumCalls(int numCalls) { 69 mNumCalls = numCalls; 70 } 71 getNumCalls()72 public String getNumCalls() { 73 int totalCalls; 74 if (mElementIsParent) 75 totalCalls = mContext.getTotalCalls(); 76 else 77 totalCalls = mElement.getTotalCalls(); 78 return String.format("%d/%d", mNumCalls, totalCalls); 79 } 80 isParent()81 public boolean isParent() { 82 return mElementIsParent; 83 } 84 getContext()85 public MethodData getContext() { 86 return mContext; 87 } 88 } 89