commit c81f25b4245f311bb0261da2ba3eb96ad65bfd1b
parent 051749802d66bed46fc5577789b700ebdd907f86
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 16 Dec 2016 00:17:48 -0700
src: keep track of loc and translation units in runtime header
Diffstat:
5 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/src/rt.c b/src/rt.c
@@ -28,7 +28,8 @@
#include "rt.h" /* citrun_*, struct citrun_{header,node} */
-static int shm_fd = 0;
+static int shm_fd = 0;
+static struct citrun_header *shm_header;
/*
* Extends the file and memory mapping length of shm_fd by a requested amount of
@@ -71,7 +72,6 @@ shm_create()
{
char *procdir;
char procfile[PATH_MAX];
- struct citrun_header *header;
/* User of this env var must give trailing slash */
if ((procdir = getenv("CITRUN_PROCDIR")) == NULL)
@@ -89,21 +89,23 @@ shm_create()
/* Add header. */
assert(sizeof(struct citrun_header) < getpagesize());
- header = shm_extend(sizeof(struct citrun_header));
+ shm_header = shm_extend(sizeof(struct citrun_header));
/* Purposefully not null terminated. */
- strncpy(header->magic, "ctrn", sizeof(header->magic));
+ strncpy(shm_header->magic, "ctrn", sizeof(shm_header->magic));
- header->major = citrun_major;
- header->minor = citrun_minor;
- header->pids[0] = getpid();
- header->pids[1] = getppid();
- header->pids[2] = getpgrp();
+ shm_header->major = citrun_major;
+ shm_header->minor = citrun_minor;
+ shm_header->pids[0] = getpid();
+ shm_header->pids[1] = getppid();
+ shm_header->pids[2] = getpgrp();
+ shm_header->units = 0;
+ shm_header->loc = 0;
/* getprogname() should never fail. */
- strlcpy(header->progname, getprogname(), sizeof(header->progname));
+ strlcpy(shm_header->progname, getprogname(), sizeof(shm_header->progname));
- if (getcwd(header->cwd, sizeof(header->cwd)) == NULL)
+ if (getcwd(shm_header->cwd, sizeof(shm_header->cwd)) == NULL)
err(1, "getcwd");
}
@@ -131,6 +133,9 @@ citrun_node_add(unsigned int major, unsigned int minor, struct citrun_node *n)
sz = sizeof(struct citrun_node);
sz += n->size * sizeof(unsigned long long);
+ shm_header->units++;
+ shm_header->loc += n->size;
+
shm_node = shm_extend(sz);
shm_node->size = n->size;
diff --git a/src/rt.h b/src/rt.h
@@ -6,6 +6,8 @@ struct citrun_header {
unsigned int major;
unsigned int minor;
unsigned int pids[3];
+ unsigned int units;
+ unsigned int loc;
char progname[1024];
char cwd[1024];
};
diff --git a/t/inst_preamble.sh b/t/inst_preamble.sh
@@ -24,6 +24,8 @@ struct citrun_header {
unsigned int major;
unsigned int minor;
unsigned int pids[3];
+ unsigned int units;
+ unsigned int loc;
char progname[1024];
char cwd[1024];
};
diff --git a/t/shm.pm b/t/shm.pm
@@ -14,14 +14,15 @@ sub new {
open(my $fh, "<:mmap", $procfile) or die $!;
$self->{fh} = $fh;
- $self->{size} = (stat $procfile)[7];
( $self->{magic},
$self->{major}, $self->{minor},
$self->{pids}[0], $self->{pids}[1], $self->{pids}[2],
+ $self->{units},
+ $self->{loc},
$self->{progname},
$self->{cwd}
- ) = unpack("Z4I5Z1024Z1024", xread($fh, $pagesize));
+ ) = unpack("Z4I7Z1024Z1024", xread($fh, $pagesize));
my @translation_units;
while (tell $fh < $self->{size}) {
diff --git a/t/utils.subr b/t/utils.subr
@@ -1,7 +1,7 @@
strip_preamble()
{
file="${1}"
- tail -n +36 $file.citrun > $file.citrun_nohdr
+ tail -n +38 $file.citrun > $file.citrun_nohdr
}
strip_log()