citrun

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

commit 60121ac2de15df16365a375b5a4ae6ae9ade7b0f
parent 357b5f535a3c83fdfd58f54f1fec0c4a445bb92a
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 16 Jul 2016 10:19:30 -0600

lib: send program name and total code lines

Diffstat:
MTest/Viewer.pm | 11++++++++++-
Mlib/runtime.c | 22+++++++++++++++++-----
Msrc/gl_runtime_conn.cc | 10+++++++++-
Msrc/gl_runtime_conn.h | 2++
4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/Test/Viewer.pm b/Test/Viewer.pm @@ -32,10 +32,19 @@ sub accept { my $client = $socket->accept(); $self->{client_socket} = $client; + # Read arbitrarily sized program name string + my $buf = read_all($client, 8); + my $progname_sz = unpack("Q", $buf); + my $progname = read_all($client, $progname_sz); + # Read the total number of instrumented translation units. my $buf = read_all($client, 8); $self->{num_tus} = unpack("Q", $buf); + # Read total code lines in program. + $buf = read_all($client, 8); + $self->{lines_total} = unpack("Q", $buf); + # Read three 4 byte pid_t's $buf = read_all($client, 12); ($self->{pid}, $self->{ppid}, $self->{pgrp}) = unpack("L3", $buf); @@ -52,7 +61,7 @@ sub accept { my @tus; for (1..$self->{num_tus}) { # Size of absolute file path. - my $buf = read_all($client, 8); + $buf = read_all($client, 8); my $file_name_sz = unpack("Q", $buf); # Absolute file path. diff --git a/lib/runtime.c b/lib/runtime.c @@ -32,6 +32,7 @@ static struct citrun_node *nodes_head; static uint64_t nodes_total; +static uint64_t lines_total; static void *relay_thread(void *); @@ -49,6 +50,7 @@ citrun_node_add(struct citrun_node *n) err(1, "calloc"); nodes_total++; + lines_total += n->size; /* If the list is empty or we need to replace the list head */ if (nodes_head == NULL || nodes_head->size >= n->size) { @@ -128,10 +130,13 @@ xwrite(int d, const void *buf, size_t bytes_total) /* * Send static information contained in each instrumented node. * Sent program wide values: + * - length of program name + * - program name * - total number of translation units + * - total number of lines in program * - process id, parent process id, group process id * Sent for each instrumented translation unit: - * - length of the original source file name + * - length of source file name * - source file name * - size of the execution counters * - number of instrumentation sites. @@ -142,10 +147,17 @@ send_static(int fd) struct citrun_node node; pid_t pids[3]; struct citrun_node *w; - size_t file_name_sz; + const char *progname; + size_t sz; int i; + progname = getprogname(); + sz = strlen(progname); + + xwrite(fd, &sz, sizeof(sz)); + xwrite(fd, progname, sz); xwrite(fd, &nodes_total, sizeof(nodes_total)); + xwrite(fd, &lines_total, sizeof(lines_total)); pids[0] = getpid(); pids[1] = getppid(); @@ -156,10 +168,10 @@ send_static(int fd) for (i = 0, w = nodes_head; i < nodes_total && w != NULL; i++, w = w->next) { node = *w; + sz = strnlen(node.file_name, PATH_MAX); - file_name_sz = strnlen(node.file_name, PATH_MAX); - xwrite(fd, &file_name_sz, sizeof(file_name_sz)); - xwrite(fd, node.file_name, file_name_sz); + xwrite(fd, &sz, sizeof(sz)); + xwrite(fd, node.file_name, sz); xwrite(fd, &node.size, sizeof(node.size)); xwrite(fd, &node.inst_sites, sizeof(node.size)); } diff --git a/src/gl_runtime_conn.cc b/src/gl_runtime_conn.cc @@ -13,17 +13,25 @@ RuntimeProcess::RuntimeProcess(af_unix *sock, demo_buffer_t *buf, demo_font_t *f buffer(buf), font(f) { + uint64_t sz; + socket->read_all(sz); + program_name.resize(sz); + socket->read_all((uint8_t *)&program_name[0], sz); + uint64_t num_tus; socket->read_all(num_tus); translation_units.resize(num_tus); + socket->read_all(lines_total); + assert(sizeof(pid_t) == 4); socket->read_all(process_id); socket->read_all(parent_process_id); socket->read_all(process_group); std::stringstream ss; - ss << "program name:\t" << "prog" << std::endl; + ss << "program name:\t" << program_name << std::endl; + ss << "code lines:\t" << lines_total << std::endl; ss << "trnsltn units:\t" << num_tus << std::endl; ss << "process id:\t" << process_id << std::endl; ss << "parent pid:\t" << parent_process_id << std::endl; diff --git a/src/gl_runtime_conn.h b/src/gl_runtime_conn.h @@ -26,6 +26,8 @@ public: private: void read_file(std::string, glyphy_point_t); + std::string program_name; + uint64_t lines_total; pid_t process_id; pid_t parent_process_id; pid_t process_group;