an error if no system is running.
)doc");
-} // namespace tensorflow
+REGISTER_OP("SessionStatus")
+ .Input("fetch_start_timestamp: double")
+ .Output("status: string")
+ .SetShapeFn(shape_inference::ScalarShape)
+ .Doc(R"doc(
+Not for public usage.
+
+Returns messages from the current session as a serialized SessionStatusProto.
+
+This includes the current state of the compiler, along with any critical
+logging or warning messages.
+
+fetch_start_timestamp: any messages earlier than this will be excluded from the
+returned proto.
+)doc");
+
+} // end namespace tensorflow
"protobuf/rewriter_config.proto",
"protobuf/tensor_bundle.proto",
"protobuf/saver.proto",
+ "util/event.proto",
"util/memmapped_file_system.proto",
"util/saved_tensor_slice.proto",
]
"protobuf/named_tensor.proto",
"protobuf/saved_model.proto",
"protobuf/tensorflow_server.proto",
- "util/event.proto",
"util/test_log.proto",
]
)
cc_library(
+ name = "session_message",
+ srcs = ["util/session_message.cc"],
+ hdrs = ["util/session_message.h"],
+ deps = [
+ ":framework",
+ ":lib",
+ ":protos_all_cc",
+ ],
+)
+
+cc_library(
name = "stacktrace_handler",
srcs = ["platform/stacktrace_handler.cc"],
hdrs = ["platform/stacktrace_handler.h"],
"framework/reader_base.*",
"util/memmapped_file_system.*",
"util/memmapped_file_system_writer.*",
+ "util/session_message.*",
"util/version_info.cc",
],
) + select({
"framework/resource_handle.cc",
"util/memmapped_file_system.*",
"util/memmapped_file_system_writer.*",
+ "util/session_message.cc",
"util/version_info.cc",
],
) + select({
// deserialization.
bytes run_metadata = 2;
}
+
+// For communicating live events back to a coordinator
+message SessionStatus {
+ repeated Event event = 1;
+}
--- /dev/null
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#include "tensorflow/core/util/session_message.h"
+#include "tensorflow/core/framework/op_kernel.h"
+#include "tensorflow/core/framework/resource_mgr.h"
+#include "tensorflow/core/lib/strings/stringprintf.h"
+#include "tensorflow/core/util/event.pb.h"
+
+static const int kMaxLogEvents = 1000;
+
+namespace tensorflow {
+
+SessionLogger::SessionLogger() : status_(new SessionStatus) {}
+
+SessionLogger::~SessionLogger() {}
+
+string SessionLogger::DebugString() { return "SessionLogger"; }
+
+void SessionLogger::Log(StringPiece message) {
+ mutex_lock lock(mu_);
+
+ Event* event = status_->add_event();
+ event->set_wall_time(Env::Default()->NowMicros());
+ event->set_step(0);
+ LogMessage* log = event->mutable_log_message();
+ log->set_message(message.ToString());
+ log->set_level(LogMessage::INFO);
+
+ // Clip log events by 10% if we overflow
+ if (status_->event_size() > kMaxLogEvents) {
+ auto events = status_->mutable_event();
+ events->DeleteSubrange(0, kMaxLogEvents / 10);
+ }
+}
+
+SessionLogger* GetSessionLogger(ResourceMgr* rm) {
+ SessionLogger* logger;
+
+ std::function<Status(SessionLogger**)> status_creator =
+ [](SessionLogger** result) {
+ *result = new SessionLogger();
+ return Status::OK();
+ };
+
+ if (!rm->LookupOrCreate<SessionLogger>("session", "status", &logger,
+ status_creator)
+ .ok()) {
+ return nullptr;
+ }
+
+ return logger;
+}
+
+void LogSessionMessage(ResourceMgr* rm, StringPiece message) {
+ return GetSessionLogger(rm)->Log(message);
+}
+
+} // namespace tensorflow
--- /dev/null
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#ifndef TENSORFLOW_CORE_UTIL_SESSION_MESSAGE_H_
+#define TENSORFLOW_CORE_UTIL_SESSION_MESSAGE_H_
+
+#include "tensorflow/core/framework/resource_mgr.h"
+#include "tensorflow/core/lib/core/stringpiece.h"
+#include "tensorflow/core/platform/mutex.h"
+
+namespace tensorflow {
+
+class ResourceMgr;
+class SessionStatus;
+
+class SessionLogger : public ResourceBase {
+ public:
+ SessionLogger();
+ ~SessionLogger();
+
+ void Log(StringPiece message);
+ string DebugString() override;
+
+ const SessionStatus& status() { return *status_; }
+
+ private:
+ std::unique_ptr<SessionStatus> status_;
+ mutex mu_;
+};
+
+// Return a SessionLogger instance for the current session. If the logger
+// will be used across multiple computations, you must explicitly acquire
+// and release references using Ref()/Unref().
+//
+// Returns nullptr if a logger cannot be created.
+SessionLogger* GetSessionLogger(ResourceMgr* rm);
+
+// Attach `message` to the logger for the current session.
+void LogSessionMessage(ResourceMgr* rm, StringPiece message);
+
+} // namespace tensorflow
+
+#endif // TENSORFLOW_CORE_UTIL_SESSION_MESSAGE_H