Expose ProfilerJoinPath so that it can be used by other libs.
PiperOrigin-RevId: 331062809 Change-Id: I4a27ed39b1ab88e82c0f8de63fb3ab4d2e64a0f1
This commit is contained in:
parent
03ebe7a82f
commit
97bd961988
@ -41,6 +41,7 @@ cc_library(
|
||||
"//tensorflow/core:lib",
|
||||
"//tensorflow/core:lib_internal",
|
||||
"//tensorflow/core/profiler:profiler_service_proto_cc",
|
||||
"//tensorflow/core/profiler/utils:file_system_utils",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/time",
|
||||
],
|
||||
|
@ -15,7 +15,6 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/core/profiler/rpc/client/save_profile.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -35,6 +34,7 @@ limitations under the License.
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
#include "tensorflow/core/platform/status.h"
|
||||
#include "tensorflow/core/profiler/profiler_service.pb.h"
|
||||
#include "tensorflow/core/profiler/utils/file_system_utils.h"
|
||||
|
||||
// Windows.h #defines ERROR, but it is also used in
|
||||
// tensorflow/core/util/event.proto
|
||||
@ -45,40 +45,6 @@ namespace tensorflow {
|
||||
namespace profiler {
|
||||
namespace {
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
const absl::string_view kPathSep = "\\";
|
||||
#else
|
||||
const absl::string_view kPathSep = "/";
|
||||
#endif
|
||||
|
||||
std::string ProfilerJoinPathImpl(
|
||||
std::initializer_list<absl::string_view> paths) {
|
||||
std::string result;
|
||||
for (absl::string_view path : paths) {
|
||||
if (path.empty()) continue;
|
||||
|
||||
if (result.empty()) {
|
||||
result = std::string(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
path = absl::StripPrefix(path, kPathSep);
|
||||
if (absl::EndsWith(result, kPathSep)) {
|
||||
absl::StrAppend(&result, path);
|
||||
} else {
|
||||
absl::StrAppend(&result, kPathSep, path);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// A local duplication of ::tensorflow::io::JoinPath that supports windows.
|
||||
// TODO(b/150699701): revert to use ::tensorflow::io::JoinPath when fixed.
|
||||
template <typename... T>
|
||||
std::string ProfilerJoinPath(const T&... args) {
|
||||
return ProfilerJoinPathImpl({args...});
|
||||
}
|
||||
|
||||
constexpr char kProtoTraceFileName[] = "trace";
|
||||
constexpr char kTfStatsHelperSuffix[] = "tf_stats_helper_result";
|
||||
@ -115,7 +81,7 @@ Status WriteGzippedDataToFile(const std::string& filepath,
|
||||
Status GetOrCreateRunDir(const std::string& repository_root,
|
||||
const std::string& run, std::string* run_dir,
|
||||
std::ostream* os) {
|
||||
// Dumps profile data to <repository_root>/<run>/.
|
||||
// Creates a directory to <repository_root>/<run>/.
|
||||
*run_dir = ProfilerJoinPath(repository_root, run);
|
||||
*os << "Creating directory: " << *run_dir;
|
||||
TF_RETURN_IF_ERROR(Env::Default()->RecursivelyCreateDir(*run_dir));
|
||||
|
@ -442,3 +442,12 @@ cc_library(
|
||||
"//tensorflow/core:lib",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "file_system_utils",
|
||||
hdrs = ["file_system_utils.h"],
|
||||
deps = [
|
||||
"//tensorflow/core/platform",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
69
tensorflow/core/profiler/utils/file_system_utils.h
Normal file
69
tensorflow/core/profiler/utils/file_system_utils.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* Copyright 2020 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_PROFILER_UTILS_FILE_SYSTEM_UTILS_H_
|
||||
#define TENSORFLOW_CORE_PROFILER_UTILS_FILE_SYSTEM_UTILS_H_
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/strings/strip.h"
|
||||
#include "tensorflow/core/platform/platform.h"
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
const absl::string_view kPathSep = "\\";
|
||||
#else
|
||||
const absl::string_view kPathSep = "/";
|
||||
#endif
|
||||
|
||||
namespace tensorflow {
|
||||
namespace profiler {
|
||||
|
||||
inline std::string ProfilerJoinPathImpl(
|
||||
std::initializer_list<absl::string_view> paths) {
|
||||
std::string result;
|
||||
for (absl::string_view path : paths) {
|
||||
if (path.empty()) continue;
|
||||
|
||||
if (result.empty()) {
|
||||
result = std::string(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
path = absl::StripPrefix(path, kPathSep);
|
||||
if (absl::EndsWith(result, kPathSep)) {
|
||||
absl::StrAppend(&result, path);
|
||||
} else {
|
||||
absl::StrAppend(&result, kPathSep, path);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// A local duplication of ::tensorflow::io::JoinPath that supports windows.
|
||||
// TODO(b/150699701): revert to use ::tensorflow::io::JoinPath when fixed.
|
||||
template <typename... T>
|
||||
std::string ProfilerJoinPath(const T&... args) {
|
||||
return ProfilerJoinPathImpl({args...});
|
||||
}
|
||||
|
||||
} // namespace profiler
|
||||
} // namespace tensorflow
|
||||
|
||||
#endif // TENSORFLOW_CORE_PROFILER_UTILS_FILE_SYSTEM_UTILS_H_
|
Loading…
Reference in New Issue
Block a user