commit a75d0189c08051080a1d647f8a3c4917af290504
parent fff318ed57724ef210355ea75fe4de0b6b41b88b
Author: Kyle Milz <kyle@0x30.net>
Date: Sun, 7 Aug 2016 21:58:22 -0600
src: only print instrumentation summary values when > 0
Diffstat:
10 files changed, 49 insertions(+), 87 deletions(-)
diff --git a/src/inst_action.cc b/src/inst_action.cc
@@ -76,19 +76,29 @@ InstrumentAction::EndSourceFileAction()
return;
}
- RewriteASTVisitor v = m_InstrumentASTConsumer->get_visitor();
*m_log << m_pfx << "Instrumentation of '" << file_name << "' finished:\n";
*m_log << m_pfx << " " << num_lines << " Lines of source code\n";
*m_log << m_pfx << " " << header_sz << " Lines of instrumentation header\n";
- *m_log << m_pfx << " " << v.m_mainfunc << " Functions called 'main'\n";
- *m_log << m_pfx << " " << v.m_funcdecl << " Function declarations\n";
- *m_log << m_pfx << " " << v.m_ifstmt << " If statements\n";
- *m_log << m_pfx << " " << v.m_forstmt << " For statements\n";
- *m_log << m_pfx << " " << v.m_whilestmt << " While statements\n";
- *m_log << m_pfx << " " << v.m_switchstmt << " Switch statements\n";
- *m_log << m_pfx << " " << v.m_returnstmt << " Return statement values\n";
- *m_log << m_pfx << " " << v.m_callexpr << " Call expressions\n";
- *m_log << m_pfx << " " << v.m_totalstmt << " Total statements in source\n";
+
+ std::vector<std::string> counter_descr;
+ counter_descr.push_back("Functions called 'main'");
+ counter_descr.push_back("Function definitions");
+ counter_descr.push_back("If statements");
+ counter_descr.push_back("For statements");
+ counter_descr.push_back("While statements");
+ counter_descr.push_back("Switch statements");
+ counter_descr.push_back("Return statement values");
+ counter_descr.push_back("Call expressions");
+ counter_descr.push_back("Total statements");
+
+ RewriteASTVisitor v = m_InstrumentASTConsumer->get_visitor();
+ for (int i = 0; i < 9; i++) {
+ int count = v.m_counters[i];
+ if (count == 0)
+ continue;
+ *m_log << m_pfx << " " << count << " " << counter_descr[i]
+ << "\n";
+ }
std::string out_file(file_name);
if (m_is_citruninst) {
diff --git a/src/inst_ast_visitor.cc b/src/inst_ast_visitor.cc
@@ -29,37 +29,37 @@ RewriteASTVisitor::VisitVarDecl(clang::VarDecl *d)
bool
RewriteASTVisitor::VisitStmt(clang::Stmt *s)
{
- m_totalstmt++;
+ m_counters[8]++;
if (clang::isa<clang::IfStmt>(s)) {
s = clang::cast<clang::IfStmt>(s)->getCond();
if (modify_stmt(s) == false)
return true;
- m_ifstmt++;
+ m_counters[2]++;
}
else if (clang::isa<clang::ForStmt>(s)) {
s = clang::cast<clang::ForStmt>(s)->getCond();
if (modify_stmt(s) == false)
return true;
- m_forstmt++;
+ m_counters[3]++;
}
else if (clang::isa<clang::WhileStmt>(s)) {
s = clang::cast<clang::WhileStmt>(s)->getCond();
if (modify_stmt(s) == false)
return true;
- m_whilestmt++;
+ m_counters[4]++;
}
else if (clang::isa<clang::SwitchStmt>(s)) {
s = clang::cast<clang::SwitchStmt>(s)->getCond();
if (modify_stmt(s) == false)
return true;
- m_switchstmt++;
+ m_counters[5]++;
}
else if (clang::isa<clang::ReturnStmt>(s)) {
s = clang::cast<clang::ReturnStmt>(s)->getRetValue();
if (modify_stmt(s) == false)
return true;
- m_returnstmt++;
+ m_counters[6]++;
}
/*
else if (isa<BreakStmt>(s) || isa<ContinueStmt>(s) ||
@@ -71,7 +71,7 @@ RewriteASTVisitor::VisitStmt(clang::Stmt *s)
else if (clang::isa<clang::CallExpr>(s)) {
if (modify_stmt(s) == false)
return true;
- m_callexpr++;
+ m_counters[7]++;
}
return true;
@@ -107,7 +107,7 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f)
// main() is a special case because it must start the runtime thread.
clang::DeclarationName DeclName = f->getNameInfo().getName();
if (DeclName.getAsString() == "main") {
- m_mainfunc++;
+ m_counters[0]++;
rewrite_text << "citrun_start();";
}
@@ -123,7 +123,7 @@ RewriteASTVisitor::VisitFunctionDecl(clang::FunctionDecl *f)
// Rewrite the function source right after the beginning curly brace.
m_TheRewriter.InsertTextBefore(curly_brace, rewrite_text.str());
- m_funcdecl++;
+ m_counters[1]++;
return true;
}
diff --git a/src/inst_ast_visitor.h b/src/inst_ast_visitor.h
@@ -4,32 +4,17 @@
class RewriteASTVisitor : public clang::RecursiveASTVisitor<RewriteASTVisitor> {
public:
RewriteASTVisitor(clang::Rewriter &R) :
- m_totalstmt(0),
- m_funcdecl(0),
- m_ifstmt(0),
- m_forstmt(0),
- m_whilestmt(0),
- m_switchstmt(0),
- m_returnstmt(0),
- m_callexpr(0),
- m_mainfunc(0),
+ m_counters(9, 0),
m_TheRewriter(R),
m_SM(R.getSourceMgr())
- {}
+ {}
bool VisitVarDecl(clang::VarDecl *d);
bool VisitStmt(clang::Stmt *s);
bool VisitFunctionDecl(clang::FunctionDecl *f);
- unsigned int m_totalstmt;
- unsigned int m_funcdecl;
- unsigned int m_ifstmt;
- unsigned int m_forstmt;
- unsigned int m_whilestmt;
- unsigned int m_switchstmt;
- unsigned int m_returnstmt;
- unsigned int m_callexpr;
- unsigned int m_mainfunc;
+ // Order defined by descriptions in inst_action.cc.
+ std::vector<int> m_counters;
private:
bool modify_stmt(clang::Stmt *);
diff --git a/t/inst_for.t b/t/inst_for.t
@@ -41,14 +41,10 @@ Instrumentation of '' finished:
11 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 4 Function declarations
- 0 If statements
+ 4 Function definitions
1 For statements
- 0 While statements
- 0 Switch statements
1 Return statement values
- 0 Call expressions
- 155 Total statements in source
+ 155 Total statements
Writing modified source to ''.
Modified source written successfully.
Instrumentation successful.
diff --git a/t/inst_if.t b/t/inst_if.t
@@ -55,14 +55,11 @@ Instrumentation of '' finished:
18 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 4 Function declarations
+ 4 Function definitions
3 If statements
- 0 For statements
- 0 While statements
- 0 Switch statements
4 Return statement values
2 Call expressions
- 173 Total statements in source
+ 173 Total statements
Writing modified source to ''.
Modified source written successfully.
Instrumentation successful.
diff --git a/t/inst_log.t b/t/inst_log.t
@@ -54,14 +54,11 @@ Instrumentation of '' finished:
22 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 5 Function declarations
+ 5 Function definitions
2 If statements
- 0 For statements
- 0 While statements
- 0 Switch statements
5 Return statement values
4 Call expressions
- 198 Total statements in source
+ 198 Total statements
Modified source written successfully.
Instrumentation successful.
Running native compiler on modified source code.
diff --git a/t/inst_return.t b/t/inst_return.t
@@ -43,14 +43,10 @@ Instrumentation of '' finished:
12 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 2 Function declarations
- 0 If statements
- 0 For statements
- 0 While statements
- 0 Switch statements
+ 2 Function definitions
4 Return statement values
1 Call expressions
- 14 Total statements in source
+ 14 Total statements
Writing modified source to ''.
Modified source written successfully.
Instrumentation successful.
diff --git a/t/inst_switch.t b/t/inst_switch.t
@@ -49,14 +49,10 @@ Instrumentation of '' finished:
15 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 1 Function declarations
- 0 If statements
- 0 For statements
- 0 While statements
+ 1 Function definitions
1 Switch statements
1 Return statement values
- 0 Call expressions
- 14 Total statements in source
+ 14 Total statements
Writing modified source to ''.
Modified source written successfully.
Instrumentation successful.
diff --git a/t/inst_two_src_one_cmd.t b/t/inst_two_src_one_cmd.t
@@ -49,27 +49,16 @@ Instrumentation of '' finished:
6 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 1 Function declarations
- 0 If statements
- 0 For statements
- 0 While statements
- 0 Switch statements
+ 1 Function definitions
1 Return statement values
- 0 Call expressions
- 3 Total statements in source
+ 3 Total statements
Modified source written successfully.
Instrumentation of '' finished:
6 Lines of source code
30 Lines of instrumentation header
- 0 Functions called ''
- 1 Function declarations
- 0 If statements
- 0 For statements
- 0 While statements
- 0 Switch statements
+ 1 Function definitions
1 Return statement values
- 0 Call expressions
- 3 Total statements in source
+ 3 Total statements
Modified source written successfully.
Instrumentation successful.
Running native compiler on modified source code.
diff --git a/t/inst_while.t b/t/inst_while.t
@@ -39,14 +39,10 @@ Instrumentation of '' finished:
10 Lines of source code
30 Lines of instrumentation header
1 Functions called ''
- 1 Function declarations
- 0 If statements
- 0 For statements
+ 1 Function definitions
2 While statements
- 0 Switch statements
1 Return statement values
- 0 Call expressions
- 18 Total statements in source
+ 18 Total statements
Writing modified source to ''.
Modified source written successfully.
Instrumentation successful.