libmeasurement (for graybox-style fuzzing)

Change-Id: Id5dc59426d2edb8bb5be3319f7e9d5124dc7952f
diff --git a/sysfuzzer/vtscompiler/code_gen/CodeGenBase.cpp b/sysfuzzer/vtscompiler/code_gen/CodeGenBase.cpp
index 05c5462..285b141 100644
--- a/sysfuzzer/vtscompiler/code_gen/CodeGenBase.cpp
+++ b/sysfuzzer/vtscompiler/code_gen/CodeGenBase.cpp
@@ -46,6 +46,7 @@
 
   cpp_ss << "#include <iostream>" << endl;
   cpp_ss << "#include \"vts_datatype.h\"" << endl;
+  cpp_ss << "#include \"vts_measurement.h\"" << endl;
   for (auto const& header : message.header()) {
     cpp_ss << "#include " << header << endl;
   }
@@ -140,5 +141,17 @@
   ss << "}  // namespace android" << endl;
 }
 
+
+void CodeGenBase::GenerateCodeToStartMeasurement(std::stringstream& ss) {
+  ss << "VtsMeasurement vts_measurement;" << endl;
+  ss << "vts_measurement.Start();" << endl;
+}
+
+
+void CodeGenBase::GenerateCodeToStopMeasurement(std::stringstream& ss) {
+  ss << "vector<float>* measured = vts_measurement.Stop();" << endl;
+  ss << "cout << \"time \" << (*measured)[0] << endl;" << endl;
+}
+
 }  // namespace vts
 }  // namespace android
diff --git a/sysfuzzer/vtscompiler/code_gen/CodeGenBase.h b/sysfuzzer/vtscompiler/code_gen/CodeGenBase.h
index f1a966b..de32204 100644
--- a/sysfuzzer/vtscompiler/code_gen/CodeGenBase.h
+++ b/sysfuzzer/vtscompiler/code_gen/CodeGenBase.h
@@ -63,6 +63,12 @@
   // Generates code that closes the default namespaces.
   void GenerateCloseNameSpaces(std::stringstream& ss);
 
+  // Generates code that starts the measurement.
+  void GenerateCodeToStartMeasurement(std::stringstream& ss);
+
+  // Generates code that stops the measurement.
+  void GenerateCodeToStopMeasurement(std::stringstream& ss);
+
  private:
   const char* input_vts_file_path_;
   const char* vts_name_;
diff --git a/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp b/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
index 0d3ddb8..955fc55 100644
--- a/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
+++ b/sysfuzzer/vtscompiler/code_gen/HalCodeGen.cpp
@@ -76,6 +76,7 @@
     }
 
     // actual function call
+    GenerateCodeToStartMeasurement(cpp_ss);
     cpp_ss << "    ";
     if (api.return_type().has_primitive_type()
         && !strcmp(api.return_type().primitive_type().c_str(), "void")) {
@@ -98,6 +99,7 @@
       cpp_ss << "))";
     }
     cpp_ss << ");" << endl;
+    GenerateCodeToStopMeasurement(cpp_ss);
     cpp_ss << "cout << \"called\" << endl;" << endl;
     cpp_ss << "    return true;" << endl;
     cpp_ss << "  }" << endl;