commit 18a6a949b0860b740f9ce88e38dda83e2dfed244
parent f9f1249afe28e4811f9f17743b0f5d0137e510d5
Author: Kyle Milz <kyle@getaddrinfo.net>
Date: Fri, 25 Mar 2016 13:21:41 -0600
instrument: hang onto total number of sites instrumented
Diffstat:
8 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/SCV/Viewer.pm b/SCV/Viewer.pm
@@ -52,10 +52,13 @@ sub get_metadata {
my $file_name = read_all($client, $file_name_sz);
- $buf = read_all($client, 8);
- my $num_lines = unpack("Q", $buf);
+ $buf = read_all($client, 4);
+ my $num_lines = unpack("L", $buf);
- push @tus, { filename => $file_name, lines => $num_lines };
+ $buf = read_all($client, 4);
+ my $inst_sites = unpack("L", $buf);
+
+ push @tus, { filename => $file_name, lines => $num_lines, inst_sites => $inst_sites };
}
$runtime_metadata->{tus} = \@tus;
diff --git a/instrument/instrument_action.cc b/instrument/instrument_action.cc
@@ -97,10 +97,14 @@ InstrumentAction::EndSourceFileAction()
// be a next TU.
ss << "struct _scv_node _scv_node" << tu_number + 1 << ";" << std::endl;
+ // Get visitor instance to check how many times it rewrote something
+ RewriteASTVisitor visitor = InstrumentASTConsumer->get_visitor();
+
// Define this translation units main book keeping data structure
ss << "struct _scv_node _scv_node" << tu_number << " = {" << std::endl
<< " .lines_ptr = _scv_lines," << std::endl
<< " .size = " << num_lines << "," << std::endl
+ << " .inst_sites = " << visitor.GetRewriteCount() << "," << std::endl
<< " .file_name = \"" << file_name << "\"," << std::endl
<< " .next = &_scv_node" << tu_number + 1 << "," << std::endl
<< "};" << std::endl;
diff --git a/instrument/instrument_action.h b/instrument/instrument_action.h
@@ -19,6 +19,7 @@ public:
return true;
}
+ RewriteASTVisitor& get_visitor() { return Visitor; };
private:
RewriteASTVisitor Visitor;
};
diff --git a/instrument/rewrite_ast_visitor.cc b/instrument/rewrite_ast_visitor.cc
@@ -54,6 +54,7 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s)
return true;
TheRewriter.InsertTextAfter(real_loc_end(stmt_to_inst), ")");
+ ++rewrite_count;
return true;
}
diff --git a/instrument/rewrite_ast_visitor.h b/instrument/rewrite_ast_visitor.h
@@ -4,16 +4,17 @@
class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor> {
public:
- RewriteASTVisitor(clang::Rewriter &R) : TheRewriter(R), SM(R.getSourceMgr()) {}
+ RewriteASTVisitor(clang::Rewriter &R) : TheRewriter(R), SM(R.getSourceMgr()), rewrite_count(0) {}
bool VisitVarDecl(clang::VarDecl *d);
bool VisitStmt(clang::Stmt *s);
bool VisitFunctionDecl(clang::FunctionDecl *f);
-
+ unsigned int GetRewriteCount() { return rewrite_count; };
private:
clang::Rewriter &TheRewriter;
clang::SourceManager &SM;
clang::LangOptions lopt;
+ unsigned int rewrite_count;
clang::SourceLocation real_loc_end(clang::Stmt *s);
};
diff --git a/instrument/runtime_h.h b/instrument/runtime_h.h
@@ -1,8 +1,9 @@
-static const char *runtime_h =
+static const char runtime_h[] =
"#include <stdint.h>\n"
"struct _scv_node {\n"
" uint64_t *lines_ptr;\n"
-" uint64_t size;\n"
+" uint32_t size;\n"
+" uint32_t inst_sites;\n"
" const char *file_name;\n"
" struct _scv_node *next;\n"
"};\n"
diff --git a/lib/runtime.c b/lib/runtime.c
@@ -111,6 +111,9 @@ send_metadata(int fd)
/* Send the size of the execution buffers */
xwrite(fd, &walk.size, sizeof(walk.size));
+ /* Send the total number of instrumentation sites */
+ xwrite(fd, &walk.inst_sites, sizeof(walk.size));
+
walk = *walk.next;
}
}
diff --git a/lib/runtime.h b/lib/runtime.h
@@ -1,7 +1,8 @@
#include <stdint.h>
struct _scv_node {
uint64_t *lines_ptr;
- uint64_t size;
+ uint32_t size;
+ uint32_t inst_sites;
const char *file_name;
struct _scv_node *next;
};