| 30 | namespace test { |
| 31 | |
| 32 | ::grpc::Status TestEventListenerImpl::SendEvents( |
| 33 | ::grpc::ServerContext* context, |
| 34 | ::grpc::ServerReaderWriter<::tensorflow::EventReply, ::tensorflow::Event>* |
| 35 | stream) { |
| 36 | Event event; |
| 37 | |
| 38 | while (stream->Read(&event)) { |
| 39 | if (event.has_log_message()) { |
| 40 | debug_metadata_strings.push_back(event.log_message().message()); |
| 41 | stream->Write(EventReply()); |
| 42 | } else if (!event.graph_def().empty()) { |
| 43 | encoded_graph_defs.push_back(event.graph_def()); |
| 44 | stream->Write(EventReply()); |
| 45 | } else if (event.has_summary()) { |
| 46 | const Summary::Value& val = event.summary().value(0); |
| 47 | |
| 48 | std::vector<string> name_items = |
| 49 | tensorflow::str_util::Split(val.node_name(), ':'); |
| 50 | |
| 51 | const string node_name = name_items[0]; |
| 52 | const string debug_op = name_items[2]; |
| 53 | |
| 54 | const TensorProto& tensor_proto = val.tensor(); |
| 55 | Tensor tensor(tensor_proto.dtype()); |
| 56 | if (!tensor.FromProto(tensor_proto)) { |
| 57 | return ::grpc::Status::CANCELLED; |
| 58 | } |
| 59 | |
| 60 | // Obtain the device name, which is encoded in JSON. |
| 61 | third_party::tensorflow::core::debug::DebuggerEventMetadata metadata; |
| 62 | if (val.metadata().plugin_data().plugin_name() != "debugger") { |
| 63 | // This plugin data was meant for another plugin. |
| 64 | continue; |
| 65 | } |
| 66 | auto status = tensorflow::protobuf::util::JsonStringToMessage( |
| 67 | val.metadata().plugin_data().content(), &metadata); |
| 68 | if (!status.ok()) { |
| 69 | // The device name could not be determined. |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | device_names.push_back(metadata.device()); |
| 74 | node_names.push_back(node_name); |
| 75 | output_slots.push_back(metadata.output_slot()); |
| 76 | debug_ops.push_back(debug_op); |
| 77 | debug_tensors.push_back(tensor); |
| 78 | |
| 79 | // If the debug node is currently in the READ_WRITE mode, send an |
| 80 | // EventReply to 1) unblock the execution and 2) optionally modify the |
| 81 | // value. |
| 82 | const DebugNodeKey debug_node_key(metadata.device(), node_name, |
| 83 | metadata.output_slot(), debug_op); |
| 84 | if (write_enabled_debug_node_keys_.find(debug_node_key) != |
| 85 | write_enabled_debug_node_keys_.end()) { |
| 86 | stream->Write(EventReply()); |
| 87 | } |
| 88 | } |
| 89 | } |
no test coverage detected