• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_UTILS_PARSE_ANNOTATION_H_
17 #define TENSORFLOW_CORE_PROFILER_UTILS_PARSE_ANNOTATION_H_
18 
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 
23 namespace tensorflow {
24 namespace profiler {
25 
26 // Parses a string passed to TraceMe or ScopedAnnotation.
27 // Expect the format will be "<name>#<metadata>#".
28 // <metadata> is a comma-separated list of "<key>=<value>" pairs.
29 // If the format does not match, the result will be empty.
30 struct Annotation {
31   absl::string_view name;
32   struct Metadata {
33     absl::string_view key;
34     absl::string_view value;
35   };
36   std::vector<Metadata> metadata;
37 };
38 Annotation ParseAnnotation(absl::string_view annotation);
39 
HasMetadata(absl::string_view annotation)40 inline bool HasMetadata(absl::string_view annotation) {
41   constexpr char kUserMetadataMarker = '#';
42   return !annotation.empty() && annotation.back() == kUserMetadataMarker;
43 }
44 
45 std::vector<Annotation> ParseAnnotationStack(
46     absl::string_view annotation_stack);
47 
48 }  // namespace profiler
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_CORE_PROFILER_UTILS_PARSE_ANNOTATION_H_
52