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_TFPROF_OPTIONS_H_ |
17 | #define TENSORFLOW_CORE_PROFILER_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, int64_t min_bytes, int64_t min_peak_bytes, |
110 | int64_t min_residual_bytes, int64_t min_output_bytes, |
111 | int64_t min_micros, int64_t min_accelerator_micros, |
112 | int64_t min_cpu_micros, int64_t min_params, int64_t min_float_ops, |
113 | int64_t min_occurrence, int64_t step, const string& order_by, |
114 | const std::vector<string>& account_type_regexes, |
115 | const std::vector<string>& start_name_regexes, |
116 | const std::vector<string>& trim_name_regexes, |
117 | const std::vector<string>& show_name_regexes, |
118 | const std::vector<string>& hide_name_regexes, |
119 | bool account_displayed_op_only, const std::vector<string>& select, |
120 | const string& output_type, |
121 | const std::map<string, string>& output_options) |
122 | : max_depth(max_depth), |
123 | min_bytes(min_bytes), |
124 | min_peak_bytes(min_peak_bytes), |
125 | min_residual_bytes(min_residual_bytes), |
126 | min_output_bytes(min_output_bytes), |
127 | min_micros(min_micros), |
128 | min_accelerator_micros(min_accelerator_micros), |
129 | min_cpu_micros(min_cpu_micros), |
130 | min_params(min_params), |
131 | min_float_ops(min_float_ops), |
132 | min_occurrence(min_occurrence), |
133 | step(step), |
134 | order_by(order_by), |
135 | account_type_regexes(account_type_regexes), |
136 | start_name_regexes(start_name_regexes), |
137 | trim_name_regexes(trim_name_regexes), |
138 | show_name_regexes(show_name_regexes), |
139 | hide_name_regexes(hide_name_regexes), |
140 | account_displayed_op_only(account_displayed_op_only), |
141 | select(select.begin(), select.end()), |
142 | output_type(output_type), |
143 | output_options(output_options) {} |
144 | |
145 | string ToString() const; |
146 | |
147 | int max_depth; |
148 | int64_t min_bytes; |
149 | int64_t min_peak_bytes; |
150 | int64_t min_residual_bytes; |
151 | int64_t min_output_bytes; |
152 | int64_t min_micros; |
153 | int64_t min_accelerator_micros; |
154 | int64_t min_cpu_micros; |
155 | int64_t min_params; |
156 | int64_t min_float_ops; |
157 | int64_t min_occurrence; |
158 | int64_t step; |
159 | string order_by; |
160 | |
161 | std::vector<string> account_type_regexes; |
162 | std::vector<string> start_name_regexes; |
163 | std::vector<string> trim_name_regexes; |
164 | std::vector<string> show_name_regexes; |
165 | std::vector<string> hide_name_regexes; |
166 | bool account_displayed_op_only; |
167 | |
168 | std::set<string> select; |
169 | |
170 | string output_type; |
171 | std::map<string, string> output_options; |
172 | }; |
173 | |
174 | // Parse the -output option. |
175 | // 'output_opt': User input string with format: output_type:key=value,key=value. |
176 | // 'output_type' and 'output_options' are extracted from 'output_opt'. |
177 | tensorflow::Status ParseOutput(const string& output_opt, string* output_type, |
178 | std::map<string, string>* output_options); |
179 | |
180 | } // namespace tfprof |
181 | } // namespace tensorflow |
182 | |
183 | #endif // TENSORFLOW_CORE_PROFILER_TFPROF_OPTIONS_H_ |
184 | |