Created
July 11, 2019 11:55
-
-
Save JuniperPhoton/75ba5dafd6cb817e2b706e4a5cbb57bb to your computer and use it in GitHub Desktop.
Convert Android hprof to Java SE hprof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
namespace AdbTest { | |
class Program { | |
static void Main (string[] args) { | |
if (args.Length == 0) { | |
Console.WriteLine ("Please specified folder path"); | |
Environment.Exit (-1); | |
} | |
var folderPath = args[0]; | |
string[] files = null; | |
try { | |
files = Directory.GetFiles (folderPath, "*.hprof"); | |
} catch (DirectoryNotFoundException) { | |
Console.WriteLine ("Directory not found"); | |
Environment.Exit (-1); | |
} | |
if (files.Length == 0) { | |
Console.WriteLine ("Folder has no *.hprof file"); | |
Environment.Exit (-1); | |
} | |
var folder = Directory.CreateDirectory ($"{folderPath}/outputs"); | |
foreach (var path in files) { | |
var fileName = Path.GetFileName(path); | |
var command = $"hprof-conv -z {path} {folder}/{fileName}"; | |
Console.WriteLine($"Running command {command}"); | |
command.RunAsBash (); | |
} | |
} | |
} | |
public static class ShellHelper { | |
public static string RunAsBash (this string cmd) { | |
var escapedArgs = cmd.Replace ("\"", "\\\""); | |
var process = new Process () { | |
StartInfo = new ProcessStartInfo { | |
FileName = "/bin/bash", | |
Arguments = $"-c \"{escapedArgs}\"", | |
RedirectStandardOutput = true, | |
UseShellExecute = false, | |
CreateNoWindow = true, | |
} | |
}; | |
process.Start (); | |
string result = process.StandardOutput.ReadToEnd (); | |
process.WaitForExit (); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this code:
dotnet build
anddotnet /bin/AdbTest.dll ~/path/to/your/hprof/folder