citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit dd826f571c1de787212c4b71baa9e15ba6e7c101
parent c165d0647f9ee53908ef9cd25ab51b2428494dad
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 13 Aug 2016 21:07:37 -0600

src: print number of milliseconds the front end took

Diffstat:
Msrc/check.in | 14++++++++------
Msrc/inst_main.cc | 12+++++++++++-
Mt/check_empty.t | 2--
Mt/inst_binop.t | 4+---
Mt/inst_correct.t | 4+---
Mt/inst_dowhile.t | 4+---
Mt/inst_for.t | 4+---
Mt/inst_funcdef.t | 4+---
Mt/inst_if.t | 4+---
Mt/inst_link_multiple.t | 4+---
Mt/inst_log.t | 1+
Mt/inst_macro.t | 4+---
Mt/inst_return.t | 4+---
Mt/inst_src_ext.t | 4+---
Mt/inst_stdout.t | 4+---
Mt/inst_switch.t | 6++----
Mt/inst_two_src.t | 4+---
Mt/inst_while.t | 4+---
Mtest/utils.sh | 8++++++++
19 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/src/check.in b/src/check.in @@ -1,4 +1,6 @@ - +# +# Script that counts events in citrun.log files. +# function err { echo "${1}" exit 1 @@ -34,7 +36,7 @@ DESC[9]="Errors during source parsing" desc_len=${#DESC[@]} FINE[0]="Lines of source code" -FINE[1]="Lines of instrumentation header" +FINE[1]="Milliseconds spent transforming source" FINE[2]="Functions called 'main'" FINE[3]="Function definitions" FINE[4]="If statements" @@ -49,10 +51,10 @@ FINE[12]="Binary operators" FINE[13]="Errors rewriting source" fine_len=${#FINE[@]} -echo -n Checking . +[ -t 1 ] && echo -n Checking . let COUNT[0]=0 for d in `find $dir -name citrun.log`; do - echo -n . + [ -t 1 ] && echo -n . let COUNT[0]++ let i=1 @@ -74,9 +76,9 @@ for d in `find $dir -name citrun.log`; do let i++ done done -echo done +[ -t 1 ] && echo done +[ -t 1 ] && echo -echo echo Summary: [ ${COUNT[0]} -eq 0 ] && err " 0 ${DESC[0]}" let i=0 diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -18,6 +18,7 @@ #include <sys/utsname.h> // uname +#include <chrono> // std::chrono::high_resolution_clock #include <cstring> // strcmp #include <err.h> #include <libgen.h> // basename @@ -93,6 +94,9 @@ print_toolinfo(InstrumentLogger &llog, const char *argv0) int main(int argc, char *argv[]) { + std::chrono::high_resolution_clock::time_point m_start_time = + std::chrono::high_resolution_clock::now(); + char *base_name; if ((base_name = basename(argv[0])) == NULL) err(1, "basename"); @@ -112,13 +116,19 @@ main(int argc, char *argv[]) setprogname("citrun-inst"); if (is_citruninst == false && clean_PATH(llog) != 0) - // We were not called as citrun-inst and path cleaning failed. + // We were not called as citrun-inst and PATH cleaning failed. return 1; CitrunInst main(argc, argv, &llog, is_citruninst); main.process_cmdline(); int ret = main.instrument(); + + std::chrono::high_resolution_clock::time_point now = + std::chrono::high_resolution_clock::now(); + llog << std::chrono::duration_cast<std::chrono::milliseconds>(now - m_start_time).count() + << " Milliseconds spent transforming source.\n"; + if (is_citruninst) return ret; if (ret) diff --git a/t/check_empty.t b/t/check_empty.t @@ -8,8 +8,6 @@ echo 1..2 $TEST_TOOLS/citrun-check > check.out cat <<EOF > check.good -Checking .done - Summary: 0 Log files found EOF diff --git a/t/inst_binop.t b/t/inst_binop.t @@ -46,8 +46,6 @@ int main(void) {citrun_start();++_citrun[13]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -68,4 +66,4 @@ $TEST_TOOLS/citrun-inst -c enum.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff enum.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_correct.t b/t/inst_correct.t @@ -29,8 +29,6 @@ int main(int argc, char *argv[]) { EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -53,7 +51,7 @@ EOF $TEST_TOOLS/citrun-wrap cc -o fib fib.c $TEST_TOOLS/citrun-check > check.out -diff -u check.good check.out && echo "ok 2 citrun.log diff" +check_diff 2 export CITRUN_SOCKET= ./fib diff --git a/t/inst_dowhile.t b/t/inst_dowhile.t @@ -24,8 +24,6 @@ int main(int argc, char *argv[]) {citrun_start();++_citrun[0]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -46,4 +44,4 @@ $TEST_TOOLS/citrun-inst -c while.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff while.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_for.t b/t/inst_for.t @@ -24,8 +24,6 @@ int main(int argc, char *argv[]) {citrun_start();++_citrun[0]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -45,4 +43,4 @@ $TEST_TOOLS/citrun-inst -c for.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff for.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_funcdef.t b/t/inst_funcdef.t @@ -28,8 +28,6 @@ other(int a, EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -46,4 +44,4 @@ $TEST_TOOLS/citrun-inst -c funcdef.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff funcdef.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_if.t b/t/inst_if.t @@ -34,8 +34,6 @@ int main(int argc, char *argv[]) {citrun_start();++_citrun[0]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -56,4 +54,4 @@ $TEST_TOOLS/citrun-inst -c if.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff if.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_link_multiple.t b/t/inst_link_multiple.t @@ -37,8 +37,6 @@ $TEST_TOOLS/citrun-wrap jam && echo "ok - source compiled" $TEST_TOOLS/citrun-check > check.out && echo ok cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 3 Source files input @@ -56,4 +54,4 @@ Totals: 13 Total statements EOF -diff -u check.good check.out && echo ok +check_diff 4 diff --git a/t/inst_log.t b/t/inst_log.t @@ -41,6 +41,7 @@ $TEST_TOOLS/citrun-wrap jam && echo "ok 4 - source compiled" sed -e "s,^.*: ,," \ -e "s,'.*',''," \ -e "s,(.*),()," \ + -e "/Milliseconds/d" \ < citrun.log > citrun.log.proc \ && echo "ok 5 - processed citrun.log" diff --git a/t/inst_macro.t b/t/inst_macro.t @@ -25,8 +25,6 @@ int main(int argc, char *argv[]) {citrun_start();++_citrun[2]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -45,4 +43,4 @@ $TEST_TOOLS/citrun-inst -c macro.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff macro.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_return.t b/t/inst_return.t @@ -34,8 +34,6 @@ int main(void) {citrun_start();++_citrun[4]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -56,4 +54,4 @@ $TEST_TOOLS/citrun-inst -c return.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff return.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_src_ext.t b/t/inst_src_ext.t @@ -14,8 +14,6 @@ $TEST_TOOLS/citrun-wrap c++ -c main.cpp $TEST_TOOLS/citrun-wrap cc -c main.C cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 4 Source files input @@ -28,4 +26,4 @@ Totals: EOF $TEST_TOOLS/citrun-check > check.out -diff -u check.out check.good && echo ok 2 +check_diff 2 diff --git a/t/inst_stdout.t b/t/inst_stdout.t @@ -15,8 +15,6 @@ int main(void) { EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -40,4 +38,4 @@ $TEST_TOOLS/citrun-check > check.out export CITRUN_SOCKET= [ "`./hello`" = "hello, world!" ] && echo ok program prints -diff -u check.good check.out && echo ok citrun-check diff +check_diff 3 diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh # # Make sure that switch statement condition instrumentation works. # @@ -36,8 +36,6 @@ int main(void) {citrun_start();++_citrun[0]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -57,4 +55,4 @@ $TEST_TOOLS/citrun-inst -c switch.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff switch.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/t/inst_two_src.t b/t/inst_two_src.t @@ -19,8 +19,6 @@ int other(void) { EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 2 Source files input @@ -40,4 +38,4 @@ EOF $TEST_TOOLS/citrun-wrap cc -o main main.c other.c && echo "ok - source compiled" $TEST_TOOLS/citrun-check > check.out -diff -u check.good check.out && echo ok - citrun-check diff +check_diff 3 diff --git a/t/inst_while.t b/t/inst_while.t @@ -26,8 +26,6 @@ int main(int argc, char *argv[]) {citrun_start();++_citrun[0]; EOF cat <<EOF > check.good -Checking ..done - Summary: 1 Log files found 1 Source files input @@ -48,4 +46,4 @@ $TEST_TOOLS/citrun-inst -c while.c > citrun.log $TEST_TOOLS/citrun-check > check.out inst_diff while.c 2 -diff -u check.good check.out && echo "ok 3 - citrun.log diff" +check_diff 3 diff --git a/test/utils.sh b/test/utils.sh @@ -13,3 +13,11 @@ function inst_diff tail -n +33 $file.citrun > $file.inst_proc diff -u $file.inst_good $file.inst_proc && echo "ok $test_num - instrumented source diff" } + +function check_diff +{ + test_num="${1}" + + grep -v "Milliseconds" check.out > check.proc + diff -u check.good check.proc && echo ok $test_num - citrun-check diff +}