document and extend trace analysis interface
authorBrian Demsky <bdemsky@uci.edu>
Mon, 6 May 2013 20:25:00 +0000 (13:25 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Mon, 6 May 2013 20:41:06 +0000 (13:41 -0700)
model.cc
scanalysis.cc
scanalysis.h
traceanalysis.h

index d9caf9a91e72ef727835a24433ba3496c74f7cd6..90ef906ef6348ed9cdfc6717c1eaab1fb3d9e886 100644 (file)
--- 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();
 }
index 13aada1a8fee202149f11b94b8ab3a9078971d39..96dec70694d3264f40fee10633c340beef22b0fd 100644 (file)
@@ -3,6 +3,8 @@
 #include "threads-model.h"
 #include "clockvector.h"
 #include "execution.h"
+#include <sys/time.h>
+
 
 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) {
index 3ad69e57023b074993083c4268c74aac0ec341c9..d68f4c114f43d71fdd646ec945861d701182cc39 100644 (file)
@@ -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
index fe60591f68603d55dcc2a5c546c11099c2866050..df3356ad50d422c08a3a2ba7d09234ccec394f5f 100644 (file)
@@ -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