citrun

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

commit 32d8bb7488a50fb1e7a0b3834645dfe006c11090
parent 43eef2864a1dd55abcef89b10e4aa6f7744a53d0
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 17 Dec 2016 23:27:14 -0700

src: add new 'exited' header field

Diffstat:
Msrc/gl_procfile.cc | 10++++------
Msrc/lib.c | 17+++++++++++++----
Msrc/lib.h | 1+
Mt/inst_preamble.sh | 1+
Mt/lib_header.t | 5+++--
Mt/shm.pm | 3++-
Mt/utils.subr | 2+-
7 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/gl_procfile.cc b/src/gl_procfile.cc @@ -62,12 +62,10 @@ GlProcessFile::GlProcessFile(std::string const &path, demo_font_t *font) : assert(m_header->major == citrun_major); std::stringstream ss; - ss << "Program Name:" << m_header->progname << std::endl; - ss << "Translation Units:" << m_header->units << std::endl; - ss << "Lines of Code:" << m_header->loc << std::endl; - ss << "Process Id:" << m_header->pids[0] << std::endl; - ss << "Parent Process Id:" << m_header->pids[1] << std::endl; - ss << "Process Group:" << m_header->pids[2] << std::endl; + ss << "Program: " << m_header->progname << std::endl; + ss << "Translation Units: " << m_header->units << std::endl; + ss << "Lines of Code: " << m_header->loc << std::endl; + ss << "Done: " << m_header->exited << std::endl; m_glbuffer.add_text(ss.str().c_str(), font, 2); glyphy_point_t cur_pos; diff --git a/src/lib.c b/src/lib.c @@ -21,14 +21,14 @@ #include <errno.h> /* EEXIST */ #include <fcntl.h> /* O_CREAT */ #include <limits.h> /* PATH_MAX */ -#include <stdlib.h> /* get{env,progname} */ +#include <stdlib.h> /* atexit, get{env,progname} */ #include <string.h> /* str{l,n}cpy */ #include <unistd.h> /* lseek get{cwd,pid,ppid,pgrp} */ #include "lib.h" /* citrun_*, struct citrun_{header,node} */ -static int fd = 0; +static int fd; static struct citrun_header *header; /* @@ -88,6 +88,15 @@ open_fd() } /* + * Called by atexit(3), which doesn't always get called (this is unreliable). + */ +static void +set_exited() +{ + header->exited = 1; +} + +/* * Extends the memory mapping and puts a struct citrun_header on top of it. */ static void @@ -106,14 +115,14 @@ add_header() header->pids[0] = getpid(); header->pids[1] = getppid(); header->pids[2] = getpgrp(); - header->units = 0; - header->loc = 0; /* getprogname() should never fail. */ strlcpy(header->progname, getprogname(), sizeof(header->progname)); if (getcwd(header->cwd, sizeof(header->cwd)) == NULL) strlcpy(header->cwd, "<none>", 7); + + atexit(set_exited); } /* diff --git a/src/lib.h b/src/lib.h @@ -8,6 +8,7 @@ struct citrun_header { unsigned int pids[3]; unsigned int units; unsigned int loc; + unsigned int exited; char progname[1024]; char cwd[1024]; }; diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh @@ -26,6 +26,7 @@ struct citrun_header { unsigned int pids[3]; unsigned int units; unsigned int loc; + unsigned int done; char progname[1024]; char cwd[1024]; }; diff --git a/t/lib_header.t b/t/lib_header.t @@ -3,7 +3,7 @@ # use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 16; use t::program; use t::shm; use t::tmpdir; @@ -22,7 +22,8 @@ is $shm->{magic}, "ctrn", "is correct file magic"; is $shm->{major}, 0, "is correct major"; is $shm->{minor}, 0, "is correct minor"; is $shm->{units}, 3, "is correct number of translation units"; -is $shm->{loc}, 40, "is correct number of translation units"; +is $shm->{loc}, 40, "is loc right "; +is $shm->{done}, 1, "is done signalled"; my ($pid, $ppid, $pgrp) = @{ $shm->{pids} }; cmp_ok $pid, '<', 100 * 1000, "is pid < max pid"; diff --git a/t/shm.pm b/t/shm.pm @@ -20,9 +20,10 @@ sub new { $self->{pids}[0], $self->{pids}[1], $self->{pids}[2], $self->{units}, $self->{loc}, + $self->{done}, $self->{progname}, $self->{cwd} - ) = unpack("Z4I7Z1024Z1024", xread($fh, $pagesize)); + ) = unpack("Z4I8Z1024Z1024", xread($fh, $pagesize)); my @translation_units; $self->{size} = (stat $procfile)[7]; diff --git a/t/utils.subr b/t/utils.subr @@ -1,7 +1,7 @@ strip_preamble() { file="${1}" - tail -n +38 $file.citrun > $file.citrun_nohdr + tail -n +39 $file.citrun > $file.citrun_nohdr } strip_log()