Skip to content

Commit

Permalink
Migrate to ddmslib's AllocationsParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
advayDev1 committed Aug 18, 2015
1 parent a6c5737 commit 4ee214a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 248 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
build/
.idea/shelf
.idea/libraries
.idea/workspace.xml

Expand Down
10 changes: 7 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ Tools to analyze performance of Android applications.

Copyright (c) 2015 by Advay Mengle.

For the original AllocationsParser.java:
Copyright (C) 2015 The Android Open Source Project

This distribution may include portions of Guava:
Copyright (C) 2006-2015 The Guava Authors

This distribution may include portions of com.android.tools.ddms:ddmlib,
to which the following notice applies:
Copyright (c) 2005-2008, The Android Open Source Project

For the original AllocationsParser.java:
Copyright (C) 2015 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
You may obtain a copy of the License at
Expand Down
1 change: 1 addition & 0 deletions apat.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Gradle: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.tools.ddms:ddmlib:24.3.1" level="project" />
</component>
</module>
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.google.guava:guava:18.0'
compile('com.android.tools.ddms:ddmlib:24.3.1') {
exclude group: 'net.sf.kxml'
exclude group: 'com.android.tools'
}
}

jar {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2015 by Advay Mengle.
*
* A modified version of AllocationsParser.java. Original:
* Copyright (C) 2015 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 com.madvay.tools.android.perf.allocs;

import com.android.ddmlib.AllocationInfo;
import com.android.ddmlib.AllocationsParser;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

public class AllocationsParserAdapter {
public static ByteBuffer mapFile(File f, long offset, ByteOrder byteOrder) throws IOException {
FileInputStream dataFile = new FileInputStream(f);
try {
FileChannel fc = dataFile.getChannel();
MappedByteBuffer buffer =
fc.map(FileChannel.MapMode.READ_ONLY, offset, f.length() - offset);
buffer.order(byteOrder);
return buffer;
} finally {
dataFile.close(); // this *also* closes the associated channel, fc
}
}

public static List<AllocRow> parse(ByteBuffer data) {
AllocationInfo[] orig = AllocationsParser.parse(data);
List<AllocRow> ret = new ArrayList<>();
for (AllocationInfo a : orig) {
ret.add(new AllocRow(a.getAllocNumber(), a.getAllocatedClass(), a.getSize(),
a.getThreadId(), a.getStackTrace()));
}
return ret;
}

public static List<AllocRow> parse(String allocFilePath) {
try {
ByteBuffer buf = mapFile(new File(allocFilePath), 0, ByteOrder.BIG_ENDIAN);
return parse(buf);
} catch (IOException e) {
throw new RuntimeException("Could not load " + allocFilePath, e);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/madvay/tools/android/perf/apat/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.madvay.tools.android.perf.allocs.AllocRow;
import com.madvay.tools.android.perf.allocs.AllocTable;
import com.madvay.tools.android.perf.allocs.AllocationsParser;
import com.madvay.tools.android.perf.allocs.AllocationsParserAdapter;
import com.madvay.tools.android.perf.allocs.PrettyAllocRowOutput;
import com.madvay.tools.android.perf.common.CsvOutput;
import com.madvay.tools.android.perf.common.TableFormatter;
Expand Down Expand Up @@ -164,7 +164,7 @@ public static void main(String[] argv) {
private static void runAllocs(CommandLine cmd) {
switch (cmd.args.get(0)) {
case "parse": {
AllocTable table = new AllocTable(AllocationsParser.parse(cmd.args.get(1)));
AllocTable table = new AllocTable(AllocationsParserAdapter.parse(cmd.args.get(1)));
if (cmd.flags.containsKey("sort")) {
table.sortOn(Splitter.on(',').splitToList(cmd.flags.get("sort")));
}
Expand Down

0 comments on commit 4ee214a

Please sign in to comment.