diff options
author | 2017-04-10 13:37:39 -0800 | |
---|---|---|
committer | 2017-04-10 15:13:42 -0700 | |
commit | 7a2b8153a3eb8ca21224c84857fe054060256ef6 (patch) | |
tree | 7822302fb2c6e9a360b9cb9e83a148061a591f7c /tensorflow/core/util | |
parent | 5720f05489b247b7503640d4d1f70a5f5766e887 (diff) |
Allows summary writer to take an optional suffix= argument, which
is appended to every summary file name.
Change: 152736272
Diffstat (limited to 'tensorflow/core/util')
-rw-r--r-- | tensorflow/core/util/events_writer.cc | 13 | ||||
-rw-r--r-- | tensorflow/core/util/events_writer.h | 14 |
2 files changed, 17 insertions, 10 deletions
diff --git a/tensorflow/core/util/events_writer.cc b/tensorflow/core/util/events_writer.cc index fa23ff2bcb..60ba39dab1 100644 --- a/tensorflow/core/util/events_writer.cc +++ b/tensorflow/core/util/events_writer.cc @@ -35,7 +35,7 @@ EventsWriter::EventsWriter(const string& file_prefix) file_prefix_(file_prefix), num_outstanding_events_(0) {} -bool EventsWriter::Init() { +bool EventsWriter::InitIfNeeded() { if (recordio_writer_.get() != nullptr) { CHECK(!filename_.empty()); if (FileHasDisappeared()) { @@ -52,9 +52,10 @@ bool EventsWriter::Init() { int64 time_in_seconds = env_->NowMicros() / 1000000; - filename_ = strings::Printf( - "%s.out.tfevents.%010lld.%s", file_prefix_.c_str(), - static_cast<long long>(time_in_seconds), port::Hostname().c_str()); + filename_ = + strings::Printf("%s.out.tfevents.%010lld.%s%s", file_prefix_.c_str(), + static_cast<int64>(time_in_seconds), + port::Hostname().c_str(), file_suffix_.c_str()); port::AdjustFilenameForLogging(&filename_); Status s = env_->NewWritableFile(filename_, &recordio_file_); @@ -84,14 +85,14 @@ bool EventsWriter::Init() { string EventsWriter::FileName() { if (filename_.empty()) { - Init(); + InitIfNeeded(); } return filename_; } void EventsWriter::WriteSerializedEvent(StringPiece event_str) { if (recordio_writer_.get() == NULL) { - if (!Init()) { + if (!InitIfNeeded()) { LOG(ERROR) << "Write failed because file could not be opened."; return; } diff --git a/tensorflow/core/util/events_writer.h b/tensorflow/core/util/events_writer.h index 2604ebdda2..a1a8cf790d 100644 --- a/tensorflow/core/util/events_writer.h +++ b/tensorflow/core/util/events_writer.h @@ -35,10 +35,10 @@ class EventsWriter { #endif // Events files typically have a name of the form - // '/some/file/path/my.file.out.events.[timestamp].[hostname]' + // '/some/file/path/my.file.out.events.[timestamp].[hostname][suffix]' // To create and EventWriter, the user should provide file_prefix = // '/some/file/path/my.file' - // The EventsWriter will append '.out.events.[timestamp].[hostname]' + // The EventsWriter will append '.out.events.[timestamp].[hostname][suffix]' // to the ultimate filename once Init() is called. // Note that it is not recommended to simultaneously have two // EventWriters writing to the same file_prefix. @@ -51,10 +51,14 @@ class EventsWriter { // and is open this is a no-op. If on the other hand the file was opened, // but has since disappeared (e.g. deleted by another process), this will open // a new file with a new timestamp in its filename. - bool Init(); + bool Init() { return InitWithSuffix(""); } + bool InitWithSuffix(const string& suffix) { + file_suffix_ = suffix; + return InitIfNeeded(); + } // Returns the filename for the current events file: - // filename_ = [file_prefix_].out.events.[timestamp].[hostname] + // filename_ = [file_prefix_].out.events.[timestamp].[hostname][suffix] string FileName(); // Append "event" to the file. The "tensorflow::" part is for swig happiness. @@ -78,9 +82,11 @@ class EventsWriter { private: bool FileHasDisappeared(); // True if event_file_path_ does not exist. + bool InitIfNeeded(); Env* env_; const string file_prefix_; + string file_suffix_; string filename_; std::unique_ptr<WritableFile> recordio_file_; std::unique_ptr<io::RecordWriter> recordio_writer_; |