Home | History | Annotate | Download | only in libprofiling
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef __VTS_DRIVER_PROFILING_INTERFACE_H_
     18 #define __VTS_DRIVER_PROFILING_INTERFACE_H_
     19 
     20 #include <android-base/macros.h>
     21 #include <google/protobuf/io/zero_copy_stream_impl.h>
     22 #include <hidl/HidlSupport.h>
     23 #include <utils/Condition.h>
     24 #include <fstream>
     25 
     26 #include "test/vts/proto/ComponentSpecificationMessage.pb.h"
     27 
     28 using namespace std;
     29 
     30 namespace android {
     31 namespace vts {
     32 
     33 // Library class to trace, record, replay, and profile a HIDL HAL
     34 // implementation.
     35 class VtsProfilingInterface {
     36  public:
     37   // for the API entry on the stub side.
     38   static const int kProfilingPointEntry;
     39   // for the synchronous callback event on the stub side.
     40   static const int kProfilingPointCallback;
     41   // for the API exit on the stub side.
     42   static const int kProfilingPointExit;
     43 
     44   explicit VtsProfilingInterface(const string& trace_file_path);
     45 
     46   virtual ~VtsProfilingInterface();
     47 
     48   void Init();
     49 
     50   // Get and create the VtsProfilingInterface singleton.
     51   static VtsProfilingInterface& getInstance(const string& trace_file_path);
     52 
     53   // returns true if the given message is added to the tracing queue.
     54   bool AddTraceEvent(
     55       android::hardware::details::HidlInstrumentor::InstrumentationEvent event,
     56       const char* package, const char* version, const char* interface,
     57       const FunctionSpecificationMessage& message);
     58 
     59  private:
     60   string trace_file_path_;  // Path of the trace file.
     61   // Writer to the trace file.
     62   std::unique_ptr<google::protobuf::io::FileOutputStream> trace_output_;
     63   Mutex mutex_;  // Mutex used to synchronize the writing to the trace file.
     64   bool initialized_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(VtsProfilingInterface);
     67 };
     68 
     69 }  // namespace vts
     70 }  // namespace android
     71 
     72 #endif  // __VTS_DRIVER_PROFILING_INTERFACE_H_
     73