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 #include "tensorflow/core/debug/debug_node_key.h"
17
18 #include "tensorflow/core/lib/strings/str_util.h"
19
20 namespace tensorflow {
21
22 const char* const DebugNodeKey::kMetadataFilePrefix = "_tfdbg_";
23
24 const char* const DebugNodeKey::kDeviceTag = "device_";
25
DebugNodeKey(const string & device_name,const string & node_name,const int32 output_slot,const string & debug_op)26 DebugNodeKey::DebugNodeKey(const string& device_name, const string& node_name,
27 const int32 output_slot, const string& debug_op)
28 : device_name(device_name),
29 node_name(node_name),
30 output_slot(output_slot),
31 debug_op(debug_op),
32 debug_node_name(
33 strings::StrCat(node_name, ":", output_slot, ":", debug_op)),
34 device_path(DeviceNameToDevicePath(device_name)) {}
35
operator ==(const DebugNodeKey & other) const36 bool DebugNodeKey::operator==(const DebugNodeKey& other) const {
37 return (device_name == other.device_name && node_name == other.node_name &&
38 output_slot == other.output_slot && debug_op == other.debug_op);
39 }
40
operator !=(const DebugNodeKey & other) const41 bool DebugNodeKey::operator!=(const DebugNodeKey& other) const {
42 return !((*this) == other);
43 }
44
DeviceNameToDevicePath(const string & device_name)45 const string DebugNodeKey::DeviceNameToDevicePath(const string& device_name) {
46 return strings::StrCat(
47 kMetadataFilePrefix, kDeviceTag,
48 str_util::StringReplace(
49 str_util::StringReplace(device_name, ":", "_", true), "/", ",",
50 true));
51 }
52
53 } // namespace tensorflow
54