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 java.text.DecimalFormat;
21 // This should be a singleton.
22 public class TraceUnits {
24 private TimeScale mTimeScale = TimeScale.MicroSeconds;
25 private double mScale = 1.0;
26 DecimalFormat mFormatter = new DecimalFormat();
28 public double getScaledValue(long value) {
29 return value * mScale;
32 public double getScaledValue(double value) {
33 return value * mScale;
36 public String valueOf(long value) {
37 return valueOf((double) value);
40 public String valueOf(double value) {
42 double scaled = value * mScale;
43 if ((int) scaled == scaled)
46 pattern = "###,###.###";
47 mFormatter.applyPattern(pattern);
48 return mFormatter.format(scaled);
51 public String labelledString(double value) {
52 String units = label();
53 String num = valueOf(value);
54 return String.format("%s: %s", units, num);
57 public String labelledString(long value) {
58 return labelledString((double) value);
61 public String label() {
66 if (mScale == 0.000001)
71 public void setTimeScale(TimeScale val) {
86 public TimeScale getTimeScale() {
90 public enum TimeScale {
91 Seconds, MilliSeconds, MicroSeconds