1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
23namespace tsl {
24namespace tracing {
25namespace {
26std::atomic<uint64> unique_arg{1};
27} // namespace
28
29const 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
42std::array<const EventCollector*, GetNumEventCategories()>
43 EventCollector::instances_;
44
45void SetEventCollector(EventCategory category,
46 const EventCollector* collector) {
47 EventCollector::instances_[static_cast<unsigned>(category)] = collector;
48}
49
50uint64 GetUniqueArg() {
51 return unique_arg.fetch_add(1, std::memory_order_relaxed);
52}
53
54uint64 GetArgForName(StringPiece name) {
55 return Hash64(name.data(), name.size());
56}
57
58} // namespace tracing
59} // namespace tsl
60