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 <fstream> 22 #include <hidl/HidlSupport.h> 23 #include <utils/Condition.h> 24 25 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 26 27 using namespace std; 28 29 namespace android { 30 namespace vts { 31 32 // Library class to trace, record, replay, and profile a HIDL HAL 33 // implementation. 34 class VtsProfilingInterface { 35 public: 36 // for the API entry on the stub side. 37 static const int kProfilingPointEntry; 38 // for the synchronous callback event on the stub side. 39 static const int kProfilingPointCallback; 40 // for the API exit on the stub side. 41 static const int kProfilingPointExit; 42 43 explicit VtsProfilingInterface(const string& trace_file_path); 44 45 virtual ~VtsProfilingInterface(); 46 47 void Init(); 48 49 // Get and create the VtsProfilingInterface singleton. 50 static VtsProfilingInterface& getInstance(const string& trace_file_path); 51 52 // returns true if the given message is added to the tracing queue. 53 bool AddTraceEvent(android::hardware::details::HidlInstrumentor::InstrumentationEvent event, 54 const char* package, const char* version, const char* interface, 55 const FunctionSpecificationMessage& message); 56 57 private: 58 string trace_file_path_; // Path of the trace file. 59 std::ofstream trace_output_; // Writer to the trace file. 60 Mutex mutex_; // Mutex used to synchronize the writing to the trace file. 61 bool initialized_; 62 bool stop_trace_recording_ = false; 63 const size_t kTraceFileSizeLimit = 64 50 * 1024 * 1024; /* limit trace file to 50MB */ 65 66 DISALLOW_COPY_AND_ASSIGN (VtsProfilingInterface); 67 }; 68 69 } // namespace vts 70 } // namespace android 71 72 #endif // __VTS_DRIVER_PROFILING_INTERFACE_H_ 73