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/debugger_state_impl.h" |
17 | |
18 | #include "tensorflow/core/debug/debug_graph_utils.h" |
19 | #include "tensorflow/core/debug/debug_io_utils.h" |
20 | |
21 | namespace tensorflow { |
22 | |
23 | DebuggerState::DebuggerState(const DebugOptions& debug_options) { |
24 | for (const DebugTensorWatch& watch : |
25 | debug_options.debug_tensor_watch_opts()) { |
26 | for (const string& url : watch.debug_urls()) { |
27 | debug_urls_.insert(url); |
28 | } |
29 | } |
30 | if (debug_options.reset_disk_byte_usage()) { |
31 | DebugFileIO::resetDiskByteUsage(); |
32 | } |
33 | } |
34 | |
35 | DebuggerState::~DebuggerState() { |
36 | for (const string& debug_url : debug_urls_) { |
37 | DebugIO::CloseDebugURL(debug_url).IgnoreError(); |
38 | } |
39 | } |
40 | |
41 | Status DebuggerState::PublishDebugMetadata( |
42 | const int64_t global_step, const int64_t session_run_index, |
43 | const int64_t executor_step_index, const std::vector<string>& input_names, |
44 | const std::vector<string>& output_names, |
45 | const std::vector<string>& target_names) { |
46 | return DebugIO::PublishDebugMetadata(global_step, session_run_index, |
47 | executor_step_index, input_names, |
48 | output_names, target_names, debug_urls_); |
49 | } |
50 | |
51 | Status DebugGraphDecorator::DecorateGraph(Graph* graph, Device* device) { |
52 | DebugNodeInserter::DeparallelizeWhileLoops(graph, device); |
53 | return DebugNodeInserter::InsertNodes( |
54 | debug_options_.debug_tensor_watch_opts(), graph, device); |
55 | } |
56 | |
57 | Status DebugGraphDecorator::PublishGraph(const Graph& graph, |
58 | const string& device_name) { |
59 | std::unordered_set<string> debug_urls; |
60 | for (const DebugTensorWatch& watch : |
61 | debug_options_.debug_tensor_watch_opts()) { |
62 | for (const string& url : watch.debug_urls()) { |
63 | debug_urls.insert(url); |
64 | } |
65 | } |
66 | |
67 | return DebugIO::PublishGraph(graph, device_name, debug_urls); |
68 | } |
69 | |
70 | } // namespace tensorflow |
71 | |