From: Milian Wolff Date: Sat, 31 May 2014 23:16:54 +0000 (+0200) Subject: Refactor DUMP_MALLOC_TRACE_OUTPUT handling. X-Git-Tag: submit/tizen/20180620.112952^2~508 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c993d99fb65d1c1c62a2a5cd0b09212bff67edc4;p=sdk%2Ftools%2Fheaptrack.git Refactor DUMP_MALLOC_TRACE_OUTPUT handling. Now we can set it to stderr or stdout/- to print directly to the console. Other files get $$ replaced by the PID of the host app. This allows us to set DUMP_MALLOC_TRACE_OUTPUT to /dev/null to disable output. --- diff --git a/malloctrace.cpp b/malloctrace.cpp index 70a41b8..d672ef1 100644 --- a/malloctrace.cpp +++ b/malloctrace.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -209,11 +210,18 @@ struct Data string outputFileName = env("DUMP_MALLOC_TRACE_OUTPUT"); if (outputFileName.empty()) { // env var might not be set when linked directly into an executable - outputFileName = "malloctrace."; + outputFileName = "malloctrace.$$"; + } else if (outputFileName == "-" || outputFileName == "stdout") { + out = stdout; + } else if (outputFileName == "stderr") { + out = stderr; + } + + if (!out) { + boost::replace_all(outputFileName, "$$", to_string(getpid())); + out = fopen(outputFileName.c_str(), "w"); } - outputFileName += to_string(getpid()); - out = fopen(outputFileName.c_str(), "wa"); if (!out) { fprintf(stderr, "Failed to open output file: %s\n", outputFileName.c_str()); exit(1); diff --git a/trace.sh b/trace.sh index 91fcb25..4ccc8a8 100755 --- a/trace.sh +++ b/trace.sh @@ -11,29 +11,16 @@ if [[ -z "$1" ]]; then exit 1 fi -output=$(pwd)/malloctrace.$(basename $1). +output=$(pwd)/malloctrace.$(basename $1).\$\$ cb echo "starting application, this might take some time..." if [ -z "$debug" ]; then - LD_PRELOAD=./libmalloctrace.so DUMP_MALLOC_TRACE_OUTPUT="$output" $@ & + LD_PRELOAD=./libmalloctrace.so DUMP_MALLOC_TRACE_OUTPUT="$output" $@ else gdb --eval-command="set environment LD_PRELOAD=./libmalloctrace.so" \ --eval-command="set environment DUMP_MALLOC_TRACE_OUTPUT=$output" \ --eval-command="run" --args $@ fi - -pid=$! -wait $pid - -exit 0 - -if [[ "$(ls $output$pid 2> /dev/null)" != "" ]]; then - echo "finished application, zipping data file" - cd $(dirname $output) - output=$(basename $output)$pid - bzip2 "$output" - du -h "$output.bz2" -fi