| 35 | } // namespace |
| 36 | |
| 37 | tensorflow::Status ParseOutput(const string& output_opt, string* output_type, |
| 38 | std::map<string, string>* output_options) { |
| 39 | // The default is to use stdout. |
| 40 | if (output_opt.empty()) { |
| 41 | *output_type = kOutput[1]; |
| 42 | return tensorflow::Status::OK(); |
| 43 | } |
| 44 | |
| 45 | std::set<string> output_types(kOutput, |
| 46 | kOutput + sizeof(kOutput) / sizeof(*kOutput)); |
| 47 | auto opt_split = output_opt.find(":"); |
| 48 | std::vector<string> kv_split; |
| 49 | if (opt_split == output_opt.npos) { |
| 50 | if (output_types.find(output_opt) == output_types.end()) { |
| 51 | return tensorflow::Status( |
| 52 | tensorflow::error::INVALID_ARGUMENT, |
| 53 | strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n", |
| 54 | output_opt.c_str(), |
| 55 | absl::StrJoin(output_types, ",").c_str())); |
| 56 | } |
| 57 | *output_type = output_opt; |
| 58 | } else { |
| 59 | *output_type = output_opt.substr(0, opt_split); |
| 60 | if (output_types.find(*output_type) == output_types.end()) { |
| 61 | return tensorflow::Status( |
| 62 | tensorflow::error::INVALID_ARGUMENT, |
| 63 | strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n", |
| 64 | output_type->c_str(), |
| 65 | absl::StrJoin(output_types, ",").c_str())); |
| 66 | } |
| 67 | kv_split = str_util::Split(output_opt.substr(opt_split + 1), ",", |
| 68 | str_util::SkipEmpty()); |
| 69 | } |
| 70 | |
| 71 | std::set<string> valid_options; |
| 72 | std::set<string> required_options; |
| 73 | if (*output_type == kOutput[0]) { |
| 74 | valid_options.insert( |
| 75 | kTimelineOpts, |
| 76 | kTimelineOpts + sizeof(kTimelineOpts) / sizeof(*kTimelineOpts)); |
| 77 | required_options.insert( |
| 78 | kTimelineRequiredOpts, |
| 79 | kTimelineRequiredOpts + |
| 80 | sizeof(kTimelineRequiredOpts) / sizeof(*kTimelineRequiredOpts)); |
| 81 | } else if (*output_type == kOutput[2]) { |
| 82 | valid_options.insert(kFileOpts, |
| 83 | kFileOpts + sizeof(kFileOpts) / sizeof(*kFileOpts)); |
| 84 | required_options.insert(kFileRequiredOpts, |
| 85 | kFileRequiredOpts + sizeof(kFileRequiredOpts) / |
| 86 | sizeof(*kFileRequiredOpts)); |
| 87 | } else if (*output_type == kOutput[3]) { |
| 88 | valid_options.insert(kPprofOpts, |
| 89 | kPprofOpts + sizeof(kPprofOpts) / sizeof(*kPprofOpts)); |
| 90 | required_options.insert( |
| 91 | kPprofRequiredOpts, |
| 92 | kPprofRequiredOpts + |
| 93 | sizeof(kPprofRequiredOpts) / sizeof(*kPprofRequiredOpts)); |
| 94 | } |