From cfa84a2aac159bb8a1763298882df7aa98f7fc6f Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Thu, 24 Mar 2011 13:55:02 -0700 Subject: Import SamplingProfiler from http://code.google.com/p/dalvik/ cp ~/android/dalvik/profiler/src/main/java/dalvik/profiler/* ~/android/master/libcore/dalvik/src/main/java/dalvik/system/profiler/ cp ~/android/dalvik/profiler/src/test/java/dalvik/profiler/* ~/android/master/libcore/dalvik/src/test/java/dalvik/system/profiler/ perl -p -i -e 's/package dalvik.profiler;/package dalvik.system.profiler;/' ~/android/master/libcore/dalvik/src/*/java/dalvik/system/profiler/*.java perl -p -i -e 's/import dalvik.profiler./import dalvik.system.profiler./' ~/android/master/libcore/dalvik/src/*/java/dalvik/system/profiler/*.java Change-Id: Iae3f63327f4a9dde7f037e69c22057e2ea704aaa --- .../main/java/dalvik/system/SamplingProfiler.java | 1728 -------------------- .../dalvik/system/profiler/AsciiHprofWriter.java | 88 + .../java/dalvik/system/profiler/BinaryHprof.java | 118 ++ .../dalvik/system/profiler/BinaryHprofReader.java | 489 ++++++ .../dalvik/system/profiler/BinaryHprofWriter.java | 245 +++ .../dalvik/system/profiler/HprofBinaryToAscii.java | 88 + .../java/dalvik/system/profiler/HprofData.java | 394 +++++ .../java/dalvik/system/profiler/HprofWriter.java | 23 + .../system/profiler/MalformedHprofException.java | 35 + .../dalvik/system/profiler/SamplingProfiler.java | 443 +++++ 10 files changed, 1923 insertions(+), 1728 deletions(-) delete mode 100644 dalvik/src/main/java/dalvik/system/SamplingProfiler.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/AsciiHprofWriter.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/BinaryHprof.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/BinaryHprofReader.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/BinaryHprofWriter.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/HprofBinaryToAscii.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/HprofData.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/HprofWriter.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/MalformedHprofException.java create mode 100644 dalvik/src/main/java/dalvik/system/profiler/SamplingProfiler.java (limited to 'dalvik/src/main') diff --git a/dalvik/src/main/java/dalvik/system/SamplingProfiler.java b/dalvik/src/main/java/dalvik/system/SamplingProfiler.java deleted file mode 100644 index b2ee6fb..0000000 --- a/dalvik/src/main/java/dalvik/system/SamplingProfiler.java +++ /dev/null @@ -1,1728 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dalvik.system; - -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Map; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import libcore.util.Objects; -import libcore.io.IoUtils; - -/** - * A sampling profiler. It currently is implemented without any - * virtual machine support, relying solely on {@code - * Thread.getStackTrace} to collect samples. As such, the overhead is - * higher than a native approach and it does not provide insight into - * where time is spent within native code, but it can still provide - * useful insight into where a program is spending time. - * - *

Usage Example

- * - * The following example shows how to use the {@code - * SamplingProfiler}. It samples the current thread's stack to a depth - * of 12 stack frame elements over two different measurement periods - * with samples taken every 100 milliseconds. In then prints the - * results in hprof format to the standard output. - * - *
 {@code
- * ThreadSet threadSet = SamplingProfiler.newArrayThreadSet(Thread.currentThread());
- * SamplingProfiler profiler = new SamplingProfiler(12, threadSet);
- * profiler.start(100);
- * // period of measurement
- * profiler.stop();
- * // period of non-measurement
- * profiler.start(100);
- * // another period of measurement
- * profiler.stop();
- * profiler.shutdown();
- * HprofWriter writer = new AsciiHprofWriter(profiler.getHprofData(), System.out);
- * writer.write();
- * }
- * - * @hide - */ -public final class SamplingProfiler { - - /** - * Represents sampling profiler data. Can be converted to ASCII or - * binary hprof-style output using {@link AsciiHprofWriter} or - * {@link BinaryHprofWriter}. - *

- * The data includes: - *