Skip to content

Commit

Permalink
Save an empty event file when StartTracing is called.
Browse files Browse the repository at this point in the history
This is to help with TensorBoard subdirectory searching.

PiperOrigin-RevId: 236260947
  • Loading branch information
tensorflower-gardener committed Mar 1, 2019
1 parent 4eeb271 commit 23d8e38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tensorflow/core/profiler/rpc/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tf_cuda_library(
deps = [
":dump_tpu_profile",
"//tensorflow:grpc++",
"//tensorflow/core:framework_internal",
"//tensorflow/core:framework",
"//tensorflow/core:grpc_services",
"//tensorflow/core:lib",
"//tensorflow/core/distributed_runtime/rpc:grpc_util",
Expand Down
20 changes: 19 additions & 1 deletion tensorflow/core/profiler/rpc/client/capture_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/grpc_services.h"
#include "tensorflow/core/profiler/rpc/client/dump_tpu_profile.h"
#include "tensorflow/core/util/events_writer.h"

namespace tensorflow {
namespace profiler {
Expand Down Expand Up @@ -162,6 +163,22 @@ Status NewSession(const string& service_addr,
return Status::OK();
}

// Creates an empty event file if not already exists, which indicates that we
// have a profile/plugin/ directory in the current logdir.
Status MaybeCreateEmptyEventFile(const tensorflow::string& logdir) {
// Suffix for an empty event file.
constexpr char kProfileEmptySuffix[] = ".profile-empty";
std::vector<string> children;
TF_RETURN_IF_ERROR(Env::Default()->GetChildren(logdir, &children));
for (const string& child : children) {
if (str_util::EndsWith(child, kProfileEmptySuffix)) {
return Status::OK();
}
}
EventsWriter event_writer(io::JoinPath(logdir, "events"));
return event_writer.InitWithSuffix(kProfileEmptySuffix);
}

// Starts tracing on a single or multiple TPU hosts and saves the result in the
// given logdir. If no trace was collected, retries tracing for
// num_tracing_attempts.
Expand All @@ -178,6 +195,8 @@ Status StartTracing(const tensorflow::string& service_addr,
std::vector<tensorflow::string> hostnames =
tensorflow::str_util::Split(workers_list, ",");

TF_RETURN_IF_ERROR(MaybeCreateEmptyEventFile(logdir));

Status status = Status::OK();
int remaining_attempts = num_tracing_attempts;
tensorflow::ProfileOptions opts;
Expand Down Expand Up @@ -248,4 +267,3 @@ void StartMonitoring(const tensorflow::string& service_addr, int duration_ms,
} // namespace client
} // namespace profiler
} // namespace tensorflow

0 comments on commit 23d8e38

Please sign in to comment.