1 | /* Copyright 2015 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 | #include "tensorflow/tsl/platform/tracing.h" |
17 | |
18 | #include <array> |
19 | #include <atomic> |
20 | |
21 | #include "tensorflow/tsl/platform/hash.h" |
22 | |
23 | namespace tsl { |
24 | namespace tracing { |
25 | namespace { |
26 | std::atomic<uint64> unique_arg{1}; |
27 | } // namespace |
28 | |
29 | const char* GetEventCategoryName(EventCategory category) { |
30 | switch (category) { |
31 | case EventCategory::kScheduleClosure: |
32 | return "ScheduleClosure"; |
33 | case EventCategory::kRunClosure: |
34 | return "RunClosure"; |
35 | case EventCategory::kCompute: |
36 | return "Compute"; |
37 | default: |
38 | return "Unknown"; |
39 | } |
40 | } |
41 | |
42 | std::array<const EventCollector*, GetNumEventCategories()> |
43 | EventCollector::instances_; |
44 | |
45 | void SetEventCollector(EventCategory category, |
46 | const EventCollector* collector) { |
47 | EventCollector::instances_[static_cast<unsigned>(category)] = collector; |
48 | } |
49 | |
50 | uint64 GetUniqueArg() { |
51 | return unique_arg.fetch_add(1, std::memory_order_relaxed); |
52 | } |
53 | |
54 | uint64 GetArgForName(StringPiece name) { |
55 | return Hash64(name.data(), name.size()); |
56 | } |
57 | |
58 | } // namespace tracing |
59 | } // namespace tsl |
60 |