diff --git a/genman.sh b/genman.sh index f33a47b..7ae6bf5 100755 --- a/genman.sh +++ b/genman.sh @@ -1,5 +1,6 @@ #!/bin/bash -cd src && help2man -n "instrumentation CPU profiler" -N -o cpuusage.1 ./cpuusage +mkdir -p build && cd build && cmake .. && make -s && \ +cd ../src && help2man -n "instrumentation CPU profiler" -N -o cpuusage.1 ./cpuusage exit ${?} diff --git a/src/cpuusage b/src/cpuusage index 6b45522..91ba74a 100755 --- a/src/cpuusage +++ b/src/cpuusage @@ -68,9 +68,9 @@ showusage() # Version showversion() { - echo "cpuusage v1.20" + echo "cpuusage v1.21" echo "" - echo "Copyright (C) 2017-2018 Kristofer Berggren" + echo "Copyright (C) 2017-2020 Kristofer Berggren" echo "" echo "cpuusage is distributed under the BSD 3-Clause license." echo "" @@ -91,7 +91,7 @@ fi # Arguments - regular options ALL="0" -AUTO="1" +MANUAL="0" DEBUG="0" FUNCS="" INCS="" @@ -135,7 +135,7 @@ while getopts "?acdf:i:j:m:o:p:r:sv" OPT; do READ="${OPTARG}" ;; s) - AUTO="0" + MANUAL="1" ;; v) VERB="true" @@ -253,7 +253,7 @@ if [ -f "${TMPDIR}/headers.txt" ] && [ -f "${TMPDIR}/prototypes.txt" ]; then ${VERB} && echo "cpuusage: starting program ${1}" JSONPATH="${TMPDIR}/cutrace.json" if [ "${DEBUG}" == "0" ]; then - CU_FILE="${JSONPATH}" CU_AUTO="${AUTO}" \ + CU_FILE="${JSONPATH}" CU_MANUAL="${MANUAL}" \ LD_PRELOAD="${TMPDIR}/build/libwrapper.so" \ DYLD_INSERT_LIBRARIES="${TMPDIR}/build/libwrapper.dylib" \ DYLD_FORCE_FLAT_NAMESPACE=1 "${@:1}" & @@ -262,7 +262,7 @@ if [ -f "${TMPDIR}/headers.txt" ] && [ -f "${TMPDIR}/prototypes.txt" ]; then else LLDBCMDPATH="${TMPDIR}/lldb.cmd" echo "env CU_FILE=\"${JSONPATH}\"" > "${LLDBCMDPATH}" - echo "env CU_AUTO=\"${AUTO}\"" >> "${LLDBCMDPATH}" + echo "env CU_MANUAL=\"${MANUAL}\"" >> "${LLDBCMDPATH}" echo "env LD_PRELOAD=\"${TMPDIR}/build/libwrapper.so\"" >> "${LLDBCMDPATH}" echo "env DYLD_INSERT_LIBRARIES=\"${TMPDIR}/build/libwrapper.dylib\"" >> "${LLDBCMDPATH}" echo "env DYLD_FORCE_FLAT_NAMESPACE=1" >> "${LLDBCMDPATH}" @@ -297,7 +297,7 @@ elif [ -f "${TMPDIR}/nowrappers.txt" ]; then ${VERB} && echo "cpuusage: starting program ${1}" JSONPATH="${TMPDIR}/cutrace.json" if [ "${DEBUG}" == "0" ]; then - CU_FILE="${JSONPATH}" CU_AUTO="${AUTO}" \ + CU_FILE="${JSONPATH}" CU_MANUAL="${MANUAL}" \ LD_PRELOAD="${LIBDIR}/libcpuusage.so" \ DYLD_INSERT_LIBRARIES="${LIBDIR}/libcpuusage.dylib" \ DYLD_FORCE_FLAT_NAMESPACE=1 "${@:1}" & @@ -306,7 +306,7 @@ elif [ -f "${TMPDIR}/nowrappers.txt" ]; then else LLDBCMDPATH="${TMPDIR}/lldb.cmd" echo "env CU_FILE=\"${JSONPATH}\"" > "${LLDBCMDPATH}" - echo "env CU_AUTO=\"${AUTO}\"" >> "${LLDBCMDPATH}" + echo "env CU_MANUAL=\"${MANUAL}\"" >> "${LLDBCMDPATH}" echo "env LD_PRELOAD=\"${LIBDIR}/libcpuusage.so\"" >> "${LLDBCMDPATH}" echo "env DYLD_INSERT_LIBRARIES=\"${LIBDIR}/libcpuusage.dylib\"" >> "${LLDBCMDPATH}" echo "env DYLD_FORCE_FLAT_NAMESPACE=1" >> "${LLDBCMDPATH}" diff --git a/src/cpuusage.1 b/src/cpuusage.1 index 9ec80ea..2f7367a 100644 --- a/src/cpuusage.1 +++ b/src/cpuusage.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH CPUUSAGE "1" "November 2019" "cpuusage v1.20" "User Commands" +.TH CPUUSAGE "1" "February 2020" "cpuusage v1.21" "User Commands" .SH NAME cpuusage \- instrumentation CPU profiler .SH SYNOPSIS @@ -103,6 +103,6 @@ Written by Kristofer Berggren .SH "REPORTING BUGS" Report bugs at https://github.com/d99kris/cpuusage .SH COPYRIGHT -Copyright \(co 2017\-2018 Kristofer Berggren +Copyright \(co 2017\-2020 Kristofer Berggren .PP cpuusage is distributed under the BSD 3\-Clause license. diff --git a/src/cumain.cpp b/src/cumain.cpp index d77be53..ee8f6e6 100644 --- a/src/cumain.cpp +++ b/src/cumain.cpp @@ -61,20 +61,24 @@ static std::string cu_addr_to_symbol(void *addr); /* ----------- Global Functions ---------------------------------- */ void __attribute__ ((constructor)) cu_init(void) { - char *manual = getenv("CU_AUTO"); + if (getenv("LD_PRELOAD") == NULL) return; + + char *manual = getenv("CU_MANUAL"); if ((manual != NULL) && (strncmp(manual, "1", 1) == 0)) { - cu_start_tracing(0); + signal(SIGUSR1, cu_start_tracing); + signal(SIGUSR2, cu_stop_tracing); } else { - signal(SIGUSR1, cu_start_tracing); - signal(SIGUSR2, cu_stop_tracing); + cu_start_tracing(0); } } void __attribute__ ((destructor)) cu_fini(void) { + if (getenv("LD_PRELOAD") == NULL) return; + cu_stop_tracing(0); }