From: Brian Demsky <bdemsky@uci.edu>
Date: Mon, 6 May 2013 20:25:00 +0000 (-0700)
Subject: document and extend trace analysis interface
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f817fff71c1cc97fe1bd55fa791f0d68af88ed1a;p=cdsspec-compiler.git

document and extend trace analysis interface
---

diff --git a/model.cc b/model.cc
index d9caf9a..90ef906 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 13aada1..96dec70 100644
--- a/scanalysis.cc
+++ b/scanalysis.cc
@@ -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) {
diff --git a/scanalysis.h b/scanalysis.h
index 3ad69e5..d68f4c1 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 fe60591..df3356a 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