From f817fff71c1cc97fe1bd55fa791f0d68af88ed1a Mon Sep 17 00:00:00 2001 From: Brian Demsky Date: Mon, 6 May 2013 13:25:00 -0700 Subject: [PATCH] document and extend trace analysis interface --- model.cc | 4 ++++ scanalysis.cc | 27 +++++++++++++++++++++++++-- scanalysis.h | 8 ++++++++ traceanalysis.h | 21 +++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/model.cc b/model.cc index d9caf9a9..90ef906e 100644 --- a/model.cc +++ b/model.cc @@ -483,4 +483,8 @@ void ModelChecker::run() model_print("******* Model-checking complete: *******\n"); print_stats(); + + /* Have the trace analyses dump their output. */ + for (unsigned int i = 0; i < trace_analyses.size(); i++) + trace_analyses[i]->finish(); } diff --git a/scanalysis.cc b/scanalysis.cc index 13aada1a..96dec706 100644 --- a/scanalysis.cc +++ b/scanalysis.cc @@ -3,6 +3,8 @@ #include "threads-model.h" #include "clockvector.h" #include "execution.h" +#include + SCAnalysis::SCAnalysis() : cvmap(), @@ -12,11 +14,14 @@ SCAnalysis::SCAnalysis() : threadlists(1), execution(NULL), print_always(false), - print_buggy(true) + print_buggy(true), + time(false), + stats((struct sc_statistics *)model_calloc(1, sizeof(struct sc_statistics))) { } SCAnalysis::~SCAnalysis() { + delete(stats); } void SCAnalysis::setExecution(ModelExecution * execution) { @@ -28,6 +33,11 @@ const char * SCAnalysis::name() { return name; } +void SCAnalysis::finish() { + if (time) + model_print("Elapsed time in usec %llu\n", stats->elapsedtime); +} + bool SCAnalysis::option(char * opt) { if (strcmp(opt, "verbose")==0) { print_always=true; @@ -37,7 +47,10 @@ bool SCAnalysis::option(char * opt) { } else if (strcmp(opt, "quiet")==0) { print_buggy=false; return false; - } if (strcmp(opt, "help") != 0) { + } else if (strcmp(opt, "time")==0) { + time=true; + return false; + } else if (strcmp(opt, "help") != 0) { model_print("Unrecognized option: %s\n", opt); } @@ -45,6 +58,7 @@ bool SCAnalysis::option(char * opt) { model_print("verbose -- print all feasible executions\n"); model_print("buggy -- print only buggy executions (default)\n"); model_print("quiet -- print nothing\n"); + model_print("time -- time execution of scanalysis\n"); model_print("\n"); return true; @@ -73,10 +87,19 @@ void SCAnalysis::print_list(action_list_t *list) { } void SCAnalysis::analyze(action_list_t *actions) { + + struct timeval start; + struct timeval finish; + if (time) + gettimeofday(&start, NULL); action_list_t *list = generateSC(actions); check_rf(list); if (print_always || (print_buggy && execution->have_bug_reports())) print_list(list); + if (time) { + gettimeofday(&finish, NULL); + stats->elapsedtime+=((finish.tv_sec*1000000+finish.tv_usec)-(start.tv_sec*1000000+start.tv_usec)); + } } void SCAnalysis::check_rf(action_list_t *list) { diff --git a/scanalysis.h b/scanalysis.h index 3ad69e57..d68f4c11 100644 --- a/scanalysis.h +++ b/scanalysis.h @@ -3,6 +3,10 @@ #include "traceanalysis.h" #include "hashtable.h" +struct sc_statistics { + unsigned long long elapsedtime; +}; + class SCAnalysis : public TraceAnalysis { public: SCAnalysis(); @@ -11,6 +15,8 @@ class SCAnalysis : public TraceAnalysis { virtual void analyze(action_list_t *); virtual const char * name(); virtual bool option(char *); + virtual void finish(); + SNAPSHOTALLOC private: @@ -35,5 +41,7 @@ class SCAnalysis : public TraceAnalysis { ModelExecution *execution; bool print_always; bool print_buggy; + bool time; + struct sc_statistics *stats; }; #endif diff --git a/traceanalysis.h b/traceanalysis.h index fe60591f..df3356ad 100644 --- a/traceanalysis.h +++ b/traceanalysis.h @@ -4,11 +4,32 @@ class TraceAnalysis { public: + /** setExecution is called once after installation with a reference to + * the ModelExecution object. */ + virtual void setExecution(ModelExecution * execution) = 0; + + /** analyze is called once for each feasible trace with the complete + * action_list object. */ + virtual void analyze(action_list_t *) = 0; + + /** name returns the analysis name string */ + virtual const char * name() = 0; + + /** Each analysis option is passed into the option method. This + * occurs before installation (i.e., you don't have a + * ModelExecution object yet). A TraceAnalysis object should + * support the option "help" */ + virtual bool option(char *) = 0; + /** The finish method is called once at the end. This should be + * used to print out results. */ + + virtual void finish() = 0; + SNAPSHOTALLOC }; #endif -- 2.34.1