allFilesAndDirs = Files.walk(dir)) {
result = allFilesAndDirs.filter(Files::isRegularFile).collect(Collectors.toList());
} catch (IOException e) {
Log.e(TAG, String.format("Failed to walk the files under path %s", dir), e);
}
return result;
}
/**
* Running the binary by shell command and reformatting the output.
*
* Example of output = "name,binder_use,binder_started,count\n" + "DockObserver,0,32,2\n" +
* "SurfaceFlinger,0,5,8\n" + "SurfaceFlingerAIDL,0,5,8\n";
*
*
Example of lines = ["name,binder_use,binder_started,count", "DockObserver,0,32,2",
* "SurfaceFlinger,0,5,8", "SurfaceFlingerAIDL,0,5,8"]
*
*
Example of headers = ["name", "binder_use", "binder_started", "count"]
*
*
Example of result = { "DockObserver_binder_use" : 0 "DockObserver_binder_started" : 32
* "DockObserver_count" : 2 }
*
* @param executable: a path of the executable file path
* @return result: a map including the metrics and values from the output
* @throws IOException if the shell command runs into errors
*/
private Map execAndGetResults(Path executable) throws IOException {
String prefix = mExecutableDir.relativize(executable).toString();
Map result = new HashMap<>();
String output = executeShellCommand(executable.toString());
if (output.length() <= 0) {
return result;
}
String[] lines = output.split(System.lineSeparator());
String[] headers = lines[0].split(CSV_SEPARATOR);
for (int row = 1; row < lines.length; row++) {
String[] l = lines[row].split(CSV_SEPARATOR);
for (int col = 1; col < l.length; col++) {
result.put(String.join(METRIC_KEY_SEPARATOR, prefix, l[0], headers[col]), l[col]);
}
}
return result;
}
/**
* Execute a shell command and return its output.
*
* @param command a string of command
*/
@VisibleForTesting
public String executeShellCommand(String command) throws IOException {
return mUiDevice.executeShellCommand(command);
}
}