aboutsummaryrefslogtreecommitdiffstats
path: root/eventanalyzer
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2009-05-14 18:19:52 -0700
committerXavier Ducrohet <xav@android.com>2009-05-15 14:01:12 -0700
commit5542fe492293223a81e604a49aa6fa55b1719847 (patch)
tree5a8377e382e930e99c7ebe0b729ae2c2833cbf22 /eventanalyzer
parentc28e97a0db9c383cd656cb51f3b720dfb53b8d21 (diff)
downloadsdk-5542fe492293223a81e604a49aa6fa55b1719847.zip
sdk-5542fe492293223a81e604a49aa6fa55b1719847.tar.gz
sdk-5542fe492293223a81e604a49aa6fa55b1719847.tar.bz2
Make the ddmlib API use IDevice instead of Device
Device is now private. All the API is using IDevice. Updated ddms, ADT, hierarchyviewer and other tools that relied on ddmlib.
Diffstat (limited to 'eventanalyzer')
-rw-r--r--eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java108
1 files changed, 54 insertions, 54 deletions
diff --git a/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java b/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java
index c520784..11444ec 100644
--- a/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java
+++ b/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java
@@ -17,7 +17,7 @@
package com.android.eventanalyzer;
import com.android.ddmlib.AndroidDebugBridge;
-import com.android.ddmlib.Device;
+import com.android.ddmlib.IDevice;
import com.android.ddmlib.Log;
import com.android.ddmlib.Log.ILogOutput;
import com.android.ddmlib.Log.LogLevel;
@@ -42,19 +42,19 @@ import java.util.Set;
import java.util.TreeMap;
/**
- * Connects to a device using ddmlib and analyze its event log.
+ * Connects to a device using ddmlib and analyze its event log.
*/
public class EventAnalyzer implements ILogListener {
-
+
private final static int TAG_ACTIVITY_LAUNCH_TIME = 30009;
private final static char DATA_SEPARATOR = ',';
private final static String CVS_EXT = ".csv";
private final static String TAG_FILE_EXT = ".tag"; //$NON-NLS-1$
-
+
private EventLogParser mParser;
- private TreeMap<String, ArrayList<Long>> mLaunchMap = new TreeMap<String, ArrayList<Long>>();
-
+ private TreeMap<String, ArrayList<Long>> mLaunchMap = new TreeMap<String, ArrayList<Long>>();
+
String mInputTextFile = null;
String mInputBinaryFile = null;
String mInputDevice = null;
@@ -65,47 +65,47 @@ public class EventAnalyzer implements ILogListener {
public static void main(String[] args) {
new EventAnalyzer().run(args);
}
-
+
private void run(String[] args) {
if (args.length == 0) {
printUsageAndQuit();
}
-
+
int index = 0;
do {
String argument = args[index++];
if ("-s".equals(argument)) {
checkInputValidity("-s");
-
+
if (index == args.length) {
printUsageAndQuit();
}
-
+
mInputDevice = args[index++];
} else if ("-fb".equals(argument)) {
checkInputValidity("-fb");
-
+
if (index == args.length) {
printUsageAndQuit();
}
-
+
mInputBinaryFile = args[index++];
} else if ("-ft".equals(argument)) {
checkInputValidity("-ft");
-
+
if (index == args.length) {
printUsageAndQuit();
}
-
+
mInputTextFile = args[index++];
} else if ("-F".equals(argument)) {
checkInputValidity("-F");
-
+
if (index == args.length) {
printUsageAndQuit();
}
-
+
mInputFolder = args[index++];
} else if ("-t".equals(argument)) {
if (index == args.length) {
@@ -156,17 +156,17 @@ public class EventAnalyzer implements ILogListener {
} else if (mInputDevice != null) {
parseLogFromDevice();
}
-
+
// analyze the data gathered by the parser methods
analyzeData();
} catch (IOException e) {
e.printStackTrace();
}
}
-
+
/**
* Parses a binary event log file located at {@link #mInputBinaryFile}.
- * @throws IOException
+ * @throws IOException
*/
private void parseBinaryLogFile() throws IOException {
mParser = new EventLogParser();
@@ -183,13 +183,13 @@ public class EventAnalyzer implements ILogListener {
printAndExit("Failed to get event tags from " + tagFile, false /* terminate*/);
}
}
-
+
LogReceiver receiver = new LogReceiver(this);
byte[] buffer = new byte[256];
-
+
FileInputStream fis = new FileInputStream(mInputBinaryFile);
-
+
int count;
while ((count = fis.read(buffer)) != -1) {
receiver.parseNewData(buffer, 0, count);
@@ -230,10 +230,10 @@ public class EventAnalyzer implements ILogListener {
private void parseLogFromDevice() throws IOException {
// init the lib
AndroidDebugBridge.init(false /* debugger support */);
-
+
try {
AndroidDebugBridge bridge = AndroidDebugBridge.createBridge();
-
+
// we can't just ask for the device list right away, as the internal thread getting
// them from ADB may not be done getting the first list.
// Since we don't really want getDevices() to be blocking, we wait here manually.
@@ -245,7 +245,7 @@ public class EventAnalyzer implements ILogListener {
} catch (InterruptedException e) {
// pass
}
-
+
// let's not wait > 10 sec.
if (count > 100) {
printAndExit("Timeout getting device list!", true /* terminate*/);
@@ -253,21 +253,21 @@ public class EventAnalyzer implements ILogListener {
}
// now get the devices
- Device[] devices = bridge.getDevices();
-
- for (Device device : devices) {
+ IDevice[] devices = bridge.getDevices();
+
+ for (IDevice device : devices) {
if (device.getSerialNumber().equals(mInputDevice)) {
grabLogFrom(device);
return;
}
}
-
+
System.err.println("Could not find " + mInputDevice);
} finally {
AndroidDebugBridge.terminate();
}
}
-
+
/**
* Parses the log files located in the folder, and its sub-folders.
* @param folderPath the path to the folder.
@@ -278,14 +278,14 @@ public class EventAnalyzer implements ILogListener {
printAndExit(String.format("%1$s is not a valid folder", folderPath),
false /* terminate */);
}
-
+
String[] files = f.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
name = name.toLowerCase();
return name.endsWith(".tag") == false;
}
});
-
+
for (String file : files) {
try {
f = new File(folderPath + File.separator + file);
@@ -300,18 +300,18 @@ public class EventAnalyzer implements ILogListener {
}
}
- private void grabLogFrom(Device device) throws IOException {
+ private void grabLogFrom(IDevice device) throws IOException {
mParser = new EventLogParser();
if (mParser.init(device) == false) {
printAndExit("Failed to get event-log-tags from " + device.getSerialNumber(),
true /* terminate*/);
}
-
+
LogReceiver receiver = new LogReceiver(this);
device.runEventLogService(receiver);
}
-
+
/**
* Analyze the data and writes it to {@link #mOutputFile}
* @throws IOException
@@ -326,23 +326,23 @@ public class EventAnalyzer implements ILogListener {
writer = new BufferedWriter(new FileWriter(mOutputFile));
StringBuilder builder = new StringBuilder();
-
+
// write the list of launch start. One column per activity.
Set<String> activities = mLaunchMap.keySet();
-
+
// write the column headers.
for (String activity : activities) {
builder.append(activity).append(DATA_SEPARATOR);
}
writer.write(builder.append('\n').toString());
-
+
// loop on the activities and write their values.
boolean moreValues = true;
int index = 0;
while (moreValues) {
moreValues = false;
builder.setLength(0);
-
+
for (String activity : activities) {
// get the activity list.
ArrayList<Long> list = mLaunchMap.get(activity);
@@ -353,33 +353,33 @@ public class EventAnalyzer implements ILogListener {
builder.append(DATA_SEPARATOR);
}
}
-
+
// write the line.
if (moreValues) {
writer.write(builder.append('\n').toString());
}
-
+
index++;
}
-
+
// write per-activity stats.
for (String activity : activities) {
builder.setLength(0);
builder.append(activity).append(DATA_SEPARATOR);
-
+
// get the activity list.
ArrayList<Long> list = mLaunchMap.get(activity);
-
+
// sort the list
Collections.sort(list);
-
+
// write min/max
builder.append(list.get(0).longValue()).append(DATA_SEPARATOR);
builder.append(list.get(list.size()-1).longValue()).append(DATA_SEPARATOR);
-
+
// write median value
builder.append(list.get(list.size()/2).longValue()).append(DATA_SEPARATOR);
-
+
// compute and write average
long total = 0; // despite being encoded on a long, the values are low enough that
// a Long should be enough to compute the total
@@ -387,7 +387,7 @@ public class EventAnalyzer implements ILogListener {
total += value.longValue();
}
builder.append(total / list.size()).append(DATA_SEPARATOR);
-
+
// finally write the data.
writer.write(builder.append('\n').toString());
}
@@ -412,7 +412,7 @@ public class EventAnalyzer implements ILogListener {
// parse and process the entry data.
processEvent(mParser.parse(entry));
}
-
+
private void processEvent(EventContainer event) {
if (event != null && event.mTag == TAG_ACTIVITY_LAUNCH_TIME) {
// get the activity name
@@ -434,12 +434,12 @@ public class EventAnalyzer implements ILogListener {
private void addLaunchTime(String name, Long value) {
ArrayList<Long> list = mLaunchMap.get(name);
-
+
if (list == null) {
list = new ArrayList<Long>();
mLaunchMap.put(name, list);
}
-
+
list.add(value);
}
@@ -469,11 +469,11 @@ public class EventAnalyzer implements ILogListener {
System.out.println("Options:");
System.out.println(" -t <file> The path to tag file to use in case the one associated with");
System.out.println(" the source is missing");
-
+
System.exit(1);
}
-
-
+
+
private static void printAndExit(String message, boolean terminate) {
System.out.println(message);
if (terminate) {