commit 98298e859fe6e618a3480ceb29c7947d82014df9
parent 2f256fada03a6425d3f26d5ee03fd9439d04e106
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 9 Jul 2016 15:41:24 -0600
lib: send line count differences instead of absolute num
Diffstat:
6 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/Test/Project.pm b/Test/Project.pm
@@ -62,7 +62,7 @@ sub instrumented_src {
open( my $inst_fh, "<", "$self->{tmp_dir}/source_0.c" );
# Knock off the instrumentation preamble
- my $line = <$inst_fh> for (1..28);
+ my $line = <$inst_fh> for (1..29);
my $inst_src;
while (my $line = <$inst_fh>) {
@@ -78,7 +78,7 @@ sub inst_src_preamble {
open( my $inst_fh, "<", "$self->{tmp_dir}/source_0.c" );
my $preamble;
- for (1..28) {
+ for (1..29) {
my $line = <$inst_fh>;
$preamble .= $line;
}
diff --git a/lib/runtime.c b/lib/runtime.c
@@ -27,6 +27,11 @@ static void *relay_thread(void *);
void
citrun_node_add(struct citrun_node *n)
{
+ /* Used for double buffering line counts. */
+ n->old_lines = calloc(n->size, sizeof(uint64_t));
+ if (n->old_lines == NULL)
+ err(1, "calloc");
+
if (nodes_head == NULL) {
assert(nodes_tail == NULL);
nodes_head = n;
@@ -159,11 +164,23 @@ static void
send_dynamic(int fd)
{
struct citrun_node *w;
+ uint64_t *lines_ptr;
+ uint64_t *old_lines_ptr;
int i;
+ int line;
/* Write execution buffers (one 8 byte counter per source line). */
- for (i = 0, w = nodes_head; i < nodes_total && w != NULL; i++, w = w->next)
- xwrite(fd, w->lines_ptr, w->size * sizeof(uint64_t));
+ for (i = 0, w = nodes_head; i < nodes_total && w != NULL; i++, w = w->next) {
+
+ lines_ptr = w->lines_ptr;
+ old_lines_ptr = w->old_lines;
+ for (line = 0; line < w->size; line++) {
+ uint64_t diff = lines_ptr[line] - old_lines_ptr[line];
+ /* Let's try incremental updating of old_lines. */
+ old_lines_ptr[line] = lines_ptr[line];
+ xwrite(fd, &diff, sizeof(uint64_t));
+ }
+ }
if (i != nodes_total)
warnx("tu chain inconsistent: %i vs %j", i, nodes_total);
diff --git a/lib/runtime.h b/lib/runtime.h
@@ -5,6 +5,7 @@ struct citrun_node {
uint32_t inst_sites;
const char *file_name;
struct citrun_node *next;
+ uint64_t *old_lines;
};
void citrun_node_add(struct citrun_node *);
void citrun_start();
diff --git a/src/runtime_h.h b/src/runtime_h.h
@@ -6,6 +6,7 @@ static const char runtime_h[] =
" uint32_t inst_sites;\n"
" const char *file_name;\n"
" struct citrun_node *next;\n"
+" uint64_t *old_lines;\n"
"};\n"
"void citrun_node_add(struct citrun_node *);\n"
"void citrun_start();\n"
diff --git a/t/inst_preamble.t b/t/inst_preamble.t
@@ -32,6 +32,7 @@ struct citrun_node {
uint32_t inst_sites;
const char *file_name;
struct citrun_node *next;
+ uint64_t *old_lines;
};
void citrun_node_add(struct citrun_node *);
void citrun_start();
diff --git a/t/runtime_counters_increase.t b/t/runtime_counters_increase.t
@@ -1,7 +1,7 @@
use strict;
use Data::Dumper;
-use Test::More tests => 25;
+use Test::More tests => 19;
use Test::Differences;
use Test::Project;
@@ -54,15 +54,10 @@ my $data = $viewer->get_dynamic_data();
ok( keys %$data == 1, "single dynamic data key" );
my ($exec_lines1) = values %$data;
-my $data = $viewer->get_dynamic_data();
-ok( keys %$data == 1, "single dynamic data key" );
-my ($exec_lines2) = values %$data;
-
# Only lines 8 - 12 in the source code above are executing
for (8..12) {
+ # Runtime sends execution differences.
cmp_ok( $exec_lines1->[$_], ">", 0, "line $_ executed nonzero times" );
- # Make sure the second time we queried the execution counts they were higher
- cmp_ok( $exec_lines2->[$_], ">=", $exec_lines1->[$_], "line $_ after > before" );
}
$project->kill();