Expand reporting of timing information.

1. Add an ExecutionSummary object to record execution
   information about Ceres objects.
2. Add an EventLogger object to log events in a function call.
3. Add a ScopedExecutionTimer object to log times in ExecutionSummary.
4. Instrument ProgramEvaluator and all the linear solvers
   to report their timing statistics.
5. Connect the timing statistics to Summary::FullReport.
6. Add high precision timer on unix systems using
   gettimeofday() call.
7. Various minor clean ups all around.

Change-Id: I5e09804b730b09535484124be7dbc1c58eccd1d4
diff --git a/internal/ceres/execution_summary.h b/internal/ceres/execution_summary.h
index 02a4448..2eb3c1a 100644
--- a/internal/ceres/execution_summary.h
+++ b/internal/ceres/execution_summary.h
@@ -35,6 +35,8 @@
 #include <string>
 
 #include "ceres/internal/port.h"
+#include "ceres/wall_time.h"
+#include "ceres/mutex.h"
 
 namespace ceres {
 namespace internal {
@@ -42,8 +44,44 @@
 // Struct used by various objects to report statistics and other
 // information about their execution. e.g., ExecutionSummary::times
 // can be used for reporting times associated with various activities.
-struct ExecutionSummary {
-  map<string, double> times;
+class ExecutionSummary {
+ public:
+  void IncrementTimeBy(const string& name, const double value) {
+    CeresMutexLock l(&times_mutex_);
+    times_[name] += value;
+  }
+
+  void IncrementCall(const string& name) {
+    CeresMutexLock l(&calls_mutex_);
+    calls_[name] += 1;
+  }
+
+  const map<string, double>& times() const { return times_; };
+  const map<string, int>& calls() const { return calls_; };
+
+ private:
+  Mutex times_mutex_;
+  map<string, double> times_;
+
+  Mutex calls_mutex_;
+  map<string, int> calls_;
+};
+
+class ScopedExecutionTimer {
+ public:
+  ScopedExecutionTimer(const string& name, ExecutionSummary* summary)
+      : start_time_(WallTimeInSeconds()),
+        name_(name),
+        summary_(summary) {}
+
+  ~ScopedExecutionTimer() {
+    summary_->IncrementTimeBy(name_, WallTimeInSeconds() - start_time_);
+  }
+
+ private:
+  const double start_time_;
+  const string name_;
+  ExecutionSummary* summary_;
 };
 
 }  // namespace internal