blob: cea1dc179e926cfa3b2b0ee788efab7746b9ae17 [file] [log] [blame]
Richard Uhler35244722015-09-10 16:45:54 -07001/*
2 * Copyright (C) 2015 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
17import dalvik.system.VMDebug;
18import java.io.IOException;
19
20/**
21 * Program used to create a heap dump for test purposes.
22 */
23public class Main {
24 // Keep a reference to the DumpedStuff instance so that it is not garbage
25 // collected before we take the heap dump.
26 public static DumpedStuff stuff;
27
28 // We will take a heap dump that includes a single instance of this
29 // DumpedStuff class. Objects stored as fields in this class can be easily
30 // found in the hprof dump by searching for the instance of the DumpedStuff
31 // class and reading the desired field.
32 public static class DumpedStuff {
33 public String basicString = "hello, world";
34 public String nullString = null;
35 public Object anObject = new Object();
36 }
37
38 public static void main(String[] args) throws IOException {
39 if (args.length < 1) {
40 System.err.println("no output file specified");
41 return;
42 }
43 String file = args[0];
44
45 // Allocate the instance of DumpedStuff.
46 stuff = new DumpedStuff();
47
48 // Take a heap dump that will include that instance of DumpedStuff.
49 System.err.println("Dumping hprof data to " + file);
50 VMDebug.dumpHprofData(file);
51 }
52}