Home | History | Annotate | Download | only in profiler
      1 /* Copyright 2016 The TensorFlow Authors All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OPTIONS_H_
     17 #define TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OPTIONS_H_
     18 
     19 #include <set>
     20 #include <string>
     21 #include <utility>
     22 #include <vector>
     23 
     24 #include "tensorflow/core/framework/types.h"
     25 #include "tensorflow/core/lib/core/status.h"
     26 
     27 namespace tensorflow {
     28 namespace tfprof {
     29 static const char* const kOptions[] = {
     30     "-max_depth",
     31     "-min_bytes",
     32     "-min_peak_bytes",
     33     "-min_residual_bytes",
     34     "-min_output_bytes",
     35     "-min_micros",
     36     "-min_accelerator_micros",
     37     "-min_cpu_micros",
     38     "-min_params",
     39     "-min_float_ops",
     40     "-min_occurrence",
     41     "-step",
     42     "-order_by",
     43     "-account_type_regexes",
     44     "-start_name_regexes",
     45     "-trim_name_regexes",
     46     "-show_name_regexes",
     47     "-hide_name_regexes",
     48     "-account_displayed_op_only",
     49     "-select",
     50     "-output",
     51 };
     52 
     53 static const char* const kOrderBy[] = {
     54     "name",         "bytes",     "peak_bytes",         "residual_bytes",
     55     "output_bytes", "micros",    "accelerator_micros", "cpu_micros",
     56     "params",       "float_ops", "occurrence",
     57 };
     58 
     59 // Append Only.
     60 // TODO(xpan): As we are adding more fields to be selected, we
     61 // need to have a way to tell users what fields are available in which view.
     62 static const char* const kShown[] = {"bytes",          "micros",
     63                                      "params",         "float_ops",
     64                                      "tensor_value",   "device",
     65                                      "op_types",       "occurrence",
     66                                      "input_shapes",   "accelerator_micros",
     67                                      "cpu_micros",     "peak_bytes",
     68                                      "residual_bytes", "output_bytes"};
     69 
     70 static const char* const kCmds[] = {
     71     "scope", "graph", "code", "op", "advise", "set", "help",
     72 };
     73 
     74 static const char* const kOutput[] = {"timeline", "stdout", "file", "pprof",
     75                                       "none"};
     76 
     77 static const char* const kTimelineOpts[] = {
     78     "outfile",
     79 };
     80 
     81 static const char* const kTimelineRequiredOpts[] = {"outfile"};
     82 
     83 static const char* const kFileOpts[] = {
     84     "outfile",
     85 };
     86 
     87 static const char* const kFileRequiredOpts[] = {
     88     "outfile",
     89 };
     90 
     91 static const char* const kPprofOpts[] = {
     92     "outfile",
     93 };
     94 
     95 static const char* const kPprofRequiredOpts[] = {
     96     "outfile",
     97 };
     98 
     99 struct Options {
    100  public:
    101   static tensorflow::Status FromProtoStr(const string& opts_proto_str,
    102                                          Options* opts);
    103 
    104   virtual ~Options() {}
    105   Options()
    106       : Options(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", {}, {}, {}, {}, {},
    107                 false, {}, "", {}) {}
    108 
    109   Options(int max_depth, tensorflow::int64 min_bytes,
    110           tensorflow::int64 min_peak_bytes,
    111           tensorflow::int64 min_residual_bytes,
    112           tensorflow::int64 min_output_bytes, tensorflow::int64 min_micros,
    113           tensorflow::int64 min_accelerator_micros,
    114           tensorflow::int64 min_cpu_micros, tensorflow::int64 min_params,
    115           tensorflow::int64 min_float_ops, tensorflow::int64 min_occurrence,
    116           tensorflow::int64 step, const string& order_by,
    117           const std::vector<string>& account_type_regexes,
    118           const std::vector<string>& start_name_regexes,
    119           const std::vector<string>& trim_name_regexes,
    120           const std::vector<string>& show_name_regexes,
    121           const std::vector<string>& hide_name_regexes,
    122           bool account_displayed_op_only, const std::vector<string>& select,
    123           const string& output_type,
    124           const std::map<string, string>& output_options)
    125       : max_depth(max_depth),
    126         min_bytes(min_bytes),
    127         min_peak_bytes(min_peak_bytes),
    128         min_residual_bytes(min_residual_bytes),
    129         min_output_bytes(min_output_bytes),
    130         min_micros(min_micros),
    131         min_accelerator_micros(min_accelerator_micros),
    132         min_cpu_micros(min_cpu_micros),
    133         min_params(min_params),
    134         min_float_ops(min_float_ops),
    135         min_occurrence(min_occurrence),
    136         step(step),
    137         order_by(order_by),
    138         account_type_regexes(account_type_regexes),
    139         start_name_regexes(start_name_regexes),
    140         trim_name_regexes(trim_name_regexes),
    141         show_name_regexes(show_name_regexes),
    142         hide_name_regexes(hide_name_regexes),
    143         account_displayed_op_only(account_displayed_op_only),
    144         select(select.begin(), select.end()),
    145         output_type(output_type),
    146         output_options(output_options) {}
    147 
    148   string ToString() const;
    149 
    150   int max_depth;
    151   tensorflow::int64 min_bytes;
    152   tensorflow::int64 min_peak_bytes;
    153   tensorflow::int64 min_residual_bytes;
    154   tensorflow::int64 min_output_bytes;
    155   tensorflow::int64 min_micros;
    156   tensorflow::int64 min_accelerator_micros;
    157   tensorflow::int64 min_cpu_micros;
    158   tensorflow::int64 min_params;
    159   tensorflow::int64 min_float_ops;
    160   tensorflow::int64 min_occurrence;
    161   tensorflow::int64 step;
    162   string order_by;
    163 
    164   std::vector<string> account_type_regexes;
    165   std::vector<string> start_name_regexes;
    166   std::vector<string> trim_name_regexes;
    167   std::vector<string> show_name_regexes;
    168   std::vector<string> hide_name_regexes;
    169   bool account_displayed_op_only;
    170 
    171   std::set<string> select;
    172 
    173   string output_type;
    174   std::map<string, string> output_options;
    175 };
    176 
    177 // Parse the -output option.
    178 // 'output_opt': User input string with format: output_type:key=value,key=value.
    179 // 'output_type' and 'output_options' are extracted from 'output_opt'.
    180 tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
    181                                std::map<string, string>* output_options);
    182 
    183 }  // namespace tfprof
    184 }  // namespace tensorflow
    185 
    186 #endif  // TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OPTIONS_H_
    187