Home | History | Annotate | Download | only in profiler
      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_COMPILATION_TOOLS_VTSC_CODE_GEN_PROFILER_PROFILERCODEGENBASE_H_
     18 #define VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_PROFILER_PROFILERCODEGENBASE_H_
     19 
     20 #include <hidl-util/Formatter.h>
     21 #include <hidl-util/FQName.h>
     22 #include <iostream>
     23 #include <string>
     24 
     25 #include "test/vts/proto/ComponentSpecificationMessage.pb.h"
     26 
     27 namespace android {
     28 namespace vts {
     29 /**
     30  * Base class that generates the profiler code for HAL interfaces.
     31  * It takes the input of a vts proto (i.e. ComponentSpecificationMessage) and
     32  * generates the header and source file of the corresponding profiler.
     33  *
     34  * All the profiler generator for a particular HAL type (e.g. Hidl Hal,
     35  * Legacy Hal etc.) should derive from this class.
     36  */
     37 class ProfilerCodeGenBase {
     38  public:
     39   ProfilerCodeGenBase(){};
     40 
     41   virtual ~ProfilerCodeGenBase(){};
     42 
     43   // Generates both the header and source file for profiler.
     44   void GenerateAll(Formatter& header_out, Formatter& source_out,
     45     const ComponentSpecificationMessage& message);
     46 
     47   // Generates the header file for profiler.
     48   virtual void GenerateHeaderFile(Formatter &out,
     49     const ComponentSpecificationMessage &message);
     50 
     51   // Generates the source file for profiler.
     52   virtual void GenerateSourceFile(Formatter &out,
     53     const ComponentSpecificationMessage &message);
     54 
     55  protected:
     56   // Generates the profiler code for scalar type.
     57   virtual void GenerateProfilerForScalarVariable(Formatter& out,
     58     const VariableSpecificationMessage& val, const std::string& arg_name,
     59     const std::string& arg_value) = 0;
     60 
     61   // Generates the profiler code for string type.
     62   virtual void GenerateProfilerForStringVariable(Formatter& out,
     63     const VariableSpecificationMessage& val, const std::string& arg_name,
     64     const std::string& arg_value) = 0;
     65 
     66   // Generates the profiler code for enum type.
     67   virtual void GenerateProfilerForEnumVariable(Formatter& out,
     68     const VariableSpecificationMessage& val, const std::string& arg_name,
     69     const std::string& arg_value) = 0;
     70 
     71   // Generates the profiler code for vector type.
     72   virtual void GenerateProfilerForVectorVariable(Formatter& out,
     73     const VariableSpecificationMessage& val, const std::string& arg_name,
     74     const std::string& arg_value) = 0;
     75 
     76   // Generates the profiler code for array type.
     77   virtual void GenerateProfilerForArrayVariable(Formatter& out,
     78     const VariableSpecificationMessage& val, const std::string& arg_name,
     79     const std::string& arg_value) = 0;
     80 
     81   // Generates the profiler code for struct type.
     82   virtual void GenerateProfilerForStructVariable(Formatter& out,
     83     const VariableSpecificationMessage& val, const std::string& arg_name,
     84     const std::string& arg_value) = 0;
     85 
     86   // Generates the profiler code for union type.
     87   virtual void GenerateProfilerForUnionVariable(Formatter& out,
     88     const VariableSpecificationMessage& val, const std::string& arg_name,
     89     const std::string& arg_value) = 0;
     90 
     91   // Generates the profiler code for hidl callback type.
     92   virtual void GenerateProfilerForHidlCallbackVariable(Formatter& out,
     93       const VariableSpecificationMessage& val, const std::string& arg_name,
     94       const std::string& arg_value) = 0;
     95 
     96   // Generates the profiler code for hidl interface type.
     97   virtual void GenerateProfilerForHidlInterfaceVariable(Formatter& out,
     98       const VariableSpecificationMessage& val, const std::string& arg_name,
     99       const std::string& arg_value) = 0;
    100 
    101   // Generates the profiler code for mask type.
    102   virtual void GenerateProfilerForMaskVariable(
    103       Formatter& out, const VariableSpecificationMessage& val,
    104       const std::string& arg_name, const std::string& arg_value) = 0;
    105 
    106   // Generates the profiler code for handle type.
    107   virtual void GenerateProfilerForHandleVariable(
    108       Formatter& out, const VariableSpecificationMessage& val,
    109       const std::string& arg_name, const std::string& arg_value) = 0;
    110 
    111   // Generates the profiler code for hidl memory type.
    112   virtual void GenerateProfilerForHidlMemoryVariable(Formatter& out,
    113       const VariableSpecificationMessage& val, const std::string& arg_name,
    114       const std::string& arg_value) = 0;
    115 
    116   // Generates the profiler code for pointer type.
    117   virtual void GenerateProfilerForPointerVariable(Formatter& out,
    118       const VariableSpecificationMessage& val, const std::string& arg_name,
    119       const std::string& arg_value) = 0;
    120 
    121   // Generates the profiler code for fmq sync type.
    122   virtual void GenerateProfilerForFMQSyncVariable(Formatter& out,
    123       const VariableSpecificationMessage& val, const std::string& arg_name,
    124       const std::string& arg_value) = 0;
    125 
    126   // Generates the profiler code for fmq unsync type.
    127   virtual void GenerateProfilerForFMQUnsyncVariable(Formatter& out,
    128       const VariableSpecificationMessage& val, const std::string& arg_name,
    129       const std::string& arg_value) = 0;
    130 
    131   // Generates the profiler code for method.
    132   virtual void GenerateProfilerForMethod(Formatter& out,
    133     const FunctionSpecificationMessage& method) = 0;
    134 
    135   // Generates the necessary "#include" code for header file of profiler.
    136   virtual void GenerateHeaderIncludeFiles(Formatter& out,
    137     const ComponentSpecificationMessage& message) = 0;
    138   // Generates the necessary "#include" code for source file of profiler.
    139   virtual void GenerateSourceIncludeFiles(Formatter& out,
    140     const ComponentSpecificationMessage& message) = 0;
    141   // Generates the necessary "using" code for profiler.
    142   virtual void GenerateUsingDeclaration(Formatter& out,
    143     const ComponentSpecificationMessage& message) = 0;
    144   // Generates the necessary "#define" code for profiler.
    145   virtual void GenerateMacros(Formatter&,
    146       const ComponentSpecificationMessage&) {};
    147   // Generates sanity check for profiler. These codes will be generated at the
    148   // beginning of the main profiler function.
    149   virtual void GenerateProfilerSanityCheck(
    150       Formatter&, const ComponentSpecificationMessage&){};
    151   // Generate local variable definition. These codes will be generated after
    152   // the sanity check code.
    153   virtual void GenerateLocalVariableDefinition(Formatter&,
    154     const ComponentSpecificationMessage&) {};
    155 
    156   // Generates the profiler code for a typed variable.
    157   virtual void GenerateProfilerForTypedVariable(Formatter& out,
    158     const VariableSpecificationMessage& val, const std::string& arg_name,
    159     const std::string& arg_value);
    160 
    161   // Generates the profiler method declaration for a user defined type.
    162   // (e.g. attributes within an interface).
    163   // The method signature is:
    164   // void profile__UDTName(VariableSpecificationMessage* arg_name,
    165   //                       UDTName arg_val_name);
    166   virtual void GenerateProfilerMethodDeclForAttribute(Formatter& out,
    167     const VariableSpecificationMessage& attribute);
    168 
    169   // Generates the profiler method implementation for a user defined type.
    170   virtual void GenerateProfilerMethodImplForAttribute(Formatter& out,
    171     const VariableSpecificationMessage& attribute);
    172 
    173   //**********   Utility functions   *****************
    174   virtual void GenerateOpenNameSpaces(Formatter& out,
    175       const ComponentSpecificationMessage& message);
    176   virtual void GenerateCloseNameSpaces(Formatter& out,
    177       const ComponentSpecificationMessage& message);
    178 
    179   std::string input_vts_file_path_;
    180   DISALLOW_COPY_AND_ASSIGN (ProfilerCodeGenBase);
    181 };
    182 
    183 }  // namespace vts
    184 }  // namespace android
    185 
    186 #endif  // VTS_COMPILATION_TOOLS_VTSC_CODE_GEN_PROFILER_PROFILERCODEGENBASE_H_
    187