blob: d99722416a1dc6a663dd74eb8e480975ebd5a064 [file] [log] [blame]
Andreas Gampe554d7ee2015-09-15 08:57:12 -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
17package com.android.preload;
18
19import java.util.Date;
20import java.util.HashMap;
21import java.util.HashSet;
22import java.util.Map;
23import java.util.Set;
24
25/**
26 * Holds the collected data for a process.
27 */
28public class DumpData {
29 /**
30 * Name of the package (=application).
31 */
32 String packageName;
33
34 /**
35 * A map of class name to a string for the classloader. This may be a toString equivalent,
36 * or just a unique ID.
37 */
38 Map<String, String> dumpData;
39
40 /**
41 * The Date when this data was captured. Mostly for display purposes.
42 */
43 Date date;
44
45 /**
46 * A cached value for the number of boot classpath classes (classloader value in dumpData is
47 * null).
48 */
49 int bcpClasses;
50
51 public DumpData(String packageName, Map<String, String> dumpData, Date date) {
52 this.packageName = packageName;
53 this.dumpData = dumpData;
54 this.date = date;
55
56 countBootClassPath();
57 }
58
59 public String getPackageName() {
60 return packageName;
61 }
62
63 public Date getDate() {
64 return date;
65 }
66
67 public Map<String, String> getDumpData() {
68 return dumpData;
69 }
70
71 public void countBootClassPath() {
72 bcpClasses = 0;
73 for (Map.Entry<String, String> e : dumpData.entrySet()) {
74 if (e.getValue() == null) {
75 bcpClasses++;
76 }
77 }
78 }
79
80 // Return an inverted mapping.
81 public Map<String, Set<String>> invertData() {
82 Map<String, Set<String>> ret = new HashMap<>();
83 for (Map.Entry<String, String> e : dumpData.entrySet()) {
84 if (!ret.containsKey(e.getValue())) {
85 ret.put(e.getValue(), new HashSet<String>());
86 }
87 ret.get(e.getValue()).add(e.getKey());
88 }
89 return ret;
90 }
91}