Home | History | Annotate | Download | only in perfprofd
      1 /*
      2 **
      3 ** Copyright 2015, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #ifndef SYSTEM_EXTRAS_PERFPROFD_CONFIGREADER_H_
     19 #define SYSTEM_EXTRAS_PERFPROFD_CONFIGREADER_H_
     20 
     21 #include <string>
     22 #include <map>
     23 
     24 //
     25 // This table describes the perfprofd config file syntax in terms of
     26 // key/value pairs.  Values come in two flavors: strings, or unsigned
     27 // integers. In the latter case the reader sets allowable
     28 // minimum/maximum for the setting.
     29 //
     30 class ConfigReader {
     31 
     32  public:
     33   ConfigReader();
     34   ~ConfigReader();
     35 
     36   // Ask for the current setting of a config item
     37   unsigned getUnsignedValue(const char *key) const;
     38   std::string getStringValue(const char *key) const;
     39 
     40   // read the specified config file, applying any settings it contains
     41   // returns true for successful read, false if conf file cannot be opened.
     42   bool readFile();
     43 
     44   // set/get path to config file
     45   static void setConfigFilePath(const char *path);
     46   static const char *getConfigFilePath();
     47 
     48   // override a config item (for unit testing purposes)
     49   void overrideUnsignedEntry(const char *key, unsigned new_value);
     50 
     51  private:
     52   void addUnsignedEntry(const char *key,
     53                         unsigned default_value,
     54                         unsigned min_value,
     55                         unsigned max_value);
     56   void addStringEntry(const char *key, const char *default_value);
     57   void addDefaultEntries();
     58   void parseLine(const char *key, const char *value, unsigned linecount);
     59 
     60   typedef struct { unsigned minv, maxv; } values;
     61   std::map<std::string, values> u_info;
     62   std::map<std::string, unsigned> u_entries;
     63   std::map<std::string, std::string> s_entries;
     64   bool trace_config_read;
     65 };
     66 
     67 #endif
     68