diff options
author | Oliver Nguyen <olivernguyen@google.com> | 2019-07-29 17:37:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-07-29 17:37:30 +0000 |
commit | f0723588de38100c49f73bbdbd7e0126200372f8 (patch) | |
tree | 81f37b99ca033984a538570c76f9758e81a0d667 /tools | |
parent | 9f26142f3a3850082fb4d03a34da3201438076b0 (diff) | |
parent | 05b1c06a91b54321bd2b329916ea0702a020d12e (diff) | |
download | base-f0723588de38100c49f73bbdbd7e0126200372f8.tar.gz |
Merge "Change coverage dump to specify the output file instead of directory."
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dump-coverage/README.md | 6 | ||||
-rw-r--r-- | tools/dump-coverage/dump_coverage.cc | 52 |
2 files changed, 12 insertions, 46 deletions
diff --git a/tools/dump-coverage/README.md b/tools/dump-coverage/README.md index 2bab4bc8c984..d1c10bc2e520 100644 --- a/tools/dump-coverage/README.md +++ b/tools/dump-coverage/README.md @@ -16,7 +16,7 @@ adb shell 'mkdir /data/data/com.android.deskclock/folder-to-use' Then we can run the command to dump the data: ``` -adb shell 'am attach-agent com.android.deskclock /system/lib/libdumpcoverage.so=dump:/data/data/com.android.deskclock/folder-to-use' +adb shell 'am attach-agent com.android.deskclock /system/lib/libdumpcoverage.so=dump:/data/data/com.android.deskclock/folder-to-use/coverage-file.ec' ``` We can also reset the coverage information with @@ -28,10 +28,10 @@ adb shell 'am attach-agent com.android.deskclock /system/lib/libdumpcoverage.so= then perform more actions, then dump the data again. To get the files, we can get ``` -adb pull /data/data/com.android.deskclock/folder-to-use ~/path-on-your-computer +adb pull /data/data/com.android.deskclock/folder-to-use/coverage-file.ec ~/path-on-your-computer ``` -And you should have timestamped `.exec` files on your machine under the folder `~/path-on-your-computer` +And you should have `coverage-file.ec` on your machine under the folder `~/path-on-your-computer` # Details diff --git a/tools/dump-coverage/dump_coverage.cc b/tools/dump-coverage/dump_coverage.cc index 3de1865b8018..0808e776f190 100644 --- a/tools/dump-coverage/dump_coverage.cc +++ b/tools/dump-coverage/dump_coverage.cc @@ -18,20 +18,10 @@ #include <jvmti.h> #include <string.h> -#include <atomic> -#include <ctime> #include <fstream> -#include <iomanip> -#include <iostream> -#include <istream> -#include <memory> -#include <sstream> -#include <string> -#include <vector> using std::get; using std::tuple; -using std::chrono::system_clock; namespace dump_coverage { @@ -87,35 +77,11 @@ static jbyteArray GetExecutionData(JNIEnv* env) { return java_result_array; } -// Gets the filename to write execution data to -// dirname: the directory in which to place the file -// outputs <dirname>/YYYY-MM-DD-HH-MM-SS.SSS.exec -static std::string GetFilename(const std::string& dirname) { - system_clock::time_point time_point = system_clock::now(); - auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(time_point); - auto fractional_time = time_point - seconds; - auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(fractional_time); - - std::time_t time = system_clock::to_time_t(time_point); - auto tm = *std::gmtime(&time); - - std::ostringstream oss; - oss - << dirname - << "/" - << std::put_time(&tm, "%Y-%m-%d-%H-%M-%S.") - << std::setfill('0') << std::setw(3) << millis.count() - << ".ec"; - return oss.str(); -} - -// Writes the execution data to a file -// data, length: represent the data, as a sequence of bytes -// dirname: directory name to contain the file +// Writes the execution data to a file. +// data, length: represent the data, as a sequence of bytes. +// filename: file to write coverage data to. // returns JNI_ERR if there is an error in writing the file, otherwise JNI_OK. -static jint WriteFile(const char* data, int length, const std::string& dirname) { - auto filename = GetFilename(dirname); - +static jint WriteFile(const char* data, int length, const std::string& filename) { LOG(INFO) << "Writing file of length " << length << " to '" << filename << "'"; std::ofstream file(filename, std::ios::binary); @@ -136,11 +102,11 @@ static jint WriteFile(const char* data, int length, const std::string& dirname) return JNI_OK; } -// Grabs execution data and writes it to a file -// dirname: directory name to contain the file +// Grabs execution data and writes it to a file. +// filename: file to write coverage data to. // returns JNI_ERR if there is an error writing the file. // Will crash if the Agent isn't found or if any Java Exception occurs. -static jint Dump(const std::string& dirname) { +static jint Dump(const std::string& filename) { LOG(INFO) << "Dumping file"; JNIEnv* env = GetJNIEnv(); @@ -152,12 +118,12 @@ static jint Dump(const std::string& dirname) { int result_len = env->GetArrayLength(java_result_array); - return WriteFile((const char*) result_ptr, result_len, dirname); + return WriteFile((const char*) result_ptr, result_len, filename); } // Resets execution data, performing the equivalent of // Agent.getInstance().reset(); -// args: should be empty +// args: should be empty. // returns JNI_ERR if the arguments are invalid. // Will crash if the Agent isn't found or if any Java Exception occurs. static jint Reset(const std::string& args) { |