MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / InitIfNeeded

Method InitIfNeeded

tensorflow/core/util/events_writer.cc:50–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50Status EventsWriter::InitIfNeeded() {
51 if (recordio_writer_ != nullptr) {
52 CHECK(!filename_.empty());
53 if (!FileStillExists().ok()) {
54 // Warn user of data loss and let .reset() below do basic cleanup.
55 if (num_outstanding_events_ > 0) {
56 LOG(WARNING) << "Re-initialization, attempting to open a new file, "
57 << num_outstanding_events_ << " events will be lost.";
58 }
59 } else {
60 // No-op: File is present and writer is initialized.
61 return Status::OK();
62 }
63 }
64
65 int64 time_in_seconds = env_->NowMicros() / 1000000;
66
67 filename_ =
68 strings::Printf("%s.out.tfevents.%010lld.%s%s", file_prefix_.c_str(),
69 static_cast<int64>(time_in_seconds),
70 port::Hostname().c_str(), file_suffix_.c_str());
71
72 // Reset recordio_writer (which has a reference to recordio_file_) so final
73 // Flush() and Close() call have access to recordio_file_.
74 recordio_writer_.reset();
75
76 TF_RETURN_WITH_CONTEXT_IF_ERROR(
77 env_->NewWritableFile(filename_, &recordio_file_),
78 "Creating writable file ", filename_);
79 recordio_writer_.reset(new io::RecordWriter(recordio_file_.get()));
80 if (recordio_writer_ == nullptr) {
81 return errors::Unknown("Could not create record writer");
82 }
83 num_outstanding_events_ = 0;
84 VLOG(1) << "Successfully opened events file: " << filename_;
85 {
86 // Write the first event with the current version, and flush
87 // right away so the file contents will be easily determined.
88
89 Event event;
90 event.set_wall_time(time_in_seconds);
91 event.set_file_version(strings::StrCat(kVersionPrefix, kCurrentVersion));
92 WriteEvent(event);
93 TF_RETURN_WITH_CONTEXT_IF_ERROR(Flush(), "Flushing first event.");
94 }
95 return Status::OK();
96}
97
98string EventsWriter::FileName() {
99 if (filename_.empty()) {

Callers

nothing calls this directly

Calls 11

PrintfFunction · 0.85
c_strMethod · 0.80
HostnameFunction · 0.50
UnknownClass · 0.50
StrCatFunction · 0.50
emptyMethod · 0.45
okMethod · 0.45
NowMicrosMethod · 0.45
resetMethod · 0.45
NewWritableFileMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected