Use Abseil string utilities in the TensorFlow Profiler.
PiperOrigin-RevId: 284597520 Change-Id: I5df43eeff1913f95ff726b40f51c51e9ae015de9
This commit is contained in:
parent
8ccf72521d
commit
59329ef58f
@ -103,6 +103,8 @@ cc_library(
|
|||||||
":protos_all_cc",
|
":protos_all_cc",
|
||||||
"//tensorflow/core:framework_headers_lib",
|
"//tensorflow/core:framework_headers_lib",
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,8 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,6 +39,8 @@ cc_library(
|
|||||||
":tfprof_utils",
|
":tfprof_utils",
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
"//tensorflow/core:protos_all_cc",
|
"//tensorflow/core:protos_all_cc",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
"@jsoncpp_git//:jsoncpp",
|
"@jsoncpp_git//:jsoncpp",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -52,6 +56,7 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,6 +78,7 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -86,13 +92,14 @@ cc_library(
|
|||||||
":tfprof_show_multi",
|
":tfprof_show_multi",
|
||||||
":tfprof_tensor",
|
":tfprof_tensor",
|
||||||
":tfprof_utils",
|
":tfprof_utils",
|
||||||
"//tensorflow/c:c_api",
|
|
||||||
"//tensorflow/c:checkpoint_reader",
|
"//tensorflow/c:checkpoint_reader",
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
"//tensorflow/core:protos_all_cc",
|
"//tensorflow/core:protos_all_cc",
|
||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -115,6 +122,8 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -134,6 +143,7 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -169,6 +179,8 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -191,6 +203,8 @@ cc_library(
|
|||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -253,6 +267,8 @@ cc_library(
|
|||||||
"//tensorflow/core:protos_all_cc",
|
"//tensorflow/core:protos_all_cc",
|
||||||
"//tensorflow/core:regexp_internal",
|
"//tensorflow/core:regexp_internal",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -275,6 +291,7 @@ cc_library(
|
|||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:tfprof_options",
|
"//tensorflow/core/profiler:tfprof_options",
|
||||||
"//tensorflow/core/profiler/internal/advisor:tfprof_advisor",
|
"//tensorflow/core/profiler/internal/advisor:tfprof_advisor",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
alwayslink = 1,
|
alwayslink = 1,
|
||||||
)
|
)
|
||||||
@ -314,6 +331,8 @@ cc_library(
|
|||||||
"//tensorflow/core:framework",
|
"//tensorflow/core:framework",
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -399,6 +418,7 @@ tf_cc_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":traceme_recorder",
|
":traceme_recorder",
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
"@com_google_googletest//:gtest_main",
|
"@com_google_googletest//:gtest_main",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -30,6 +30,7 @@ cc_library(
|
|||||||
hdrs = ["accelerator_utilization_checker.h"],
|
hdrs = ["accelerator_utilization_checker.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":checker",
|
":checker",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ cc_library(
|
|||||||
hdrs = ["operation_checker.h"],
|
hdrs = ["operation_checker.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":checker",
|
":checker",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,6 +48,8 @@ cc_library(
|
|||||||
hdrs = ["expensive_operation_checker.h"],
|
hdrs = ["expensive_operation_checker.h"],
|
||||||
deps = [
|
deps = [
|
||||||
":checker",
|
":checker",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,6 +63,7 @@ cc_library(
|
|||||||
":internal_checker_runner_dummy",
|
":internal_checker_runner_dummy",
|
||||||
":operation_checker",
|
":operation_checker",
|
||||||
"//tensorflow/core/profiler:protos_all_cc",
|
"//tensorflow/core/profiler:protos_all_cc",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_ACCELERATOR_UTILIZATION_CHECKER_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_ACCELERATOR_UTILIZATION_CHECKER_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_ACCELERATOR_UTILIZATION_CHECKER_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_ACCELERATOR_UTILIZATION_CHECKER_H_
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -39,8 +40,8 @@ class AcceleratorUtilizationChecker : public Checker {
|
|||||||
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
||||||
const TFStats* stats) override {
|
const TFStats* stats) override {
|
||||||
if (!stats) {
|
if (!stats) {
|
||||||
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
|
absl::FPrintF(
|
||||||
name().c_str());
|
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
|
||||||
return reports_;
|
return reports_;
|
||||||
}
|
}
|
||||||
for (const auto& n : stats->nodes()) {
|
for (const auto& n : stats->nodes()) {
|
||||||
@ -56,14 +57,14 @@ class AcceleratorUtilizationChecker : public Checker {
|
|||||||
if (total_micros <= 0) continue;
|
if (total_micros <= 0) continue;
|
||||||
double utilization = 1.0 * stat.exec_micros / total_micros;
|
double utilization = 1.0 * stat.exec_micros / total_micros;
|
||||||
if (utilization >= 0.5) {
|
if (utilization >= 0.5) {
|
||||||
reports_.add_reports(strings::Printf("device: %s utilization: %.2f",
|
reports_.add_reports(absl::StrFormat("device: %s utilization: %.2f",
|
||||||
s.first.c_str(), utilization));
|
s.first, utilization));
|
||||||
} else if (utilization < 0.5 && utilization > 0.2) {
|
} else if (utilization < 0.5 && utilization > 0.2) {
|
||||||
reports_.add_reports(strings::Printf("device: %s low utilization: %.2f",
|
reports_.add_reports(absl::StrFormat("device: %s low utilization: %.2f",
|
||||||
s.first.c_str(), utilization));
|
s.first, utilization));
|
||||||
} else if (utilization <= 0.2) {
|
} else if (utilization <= 0.2) {
|
||||||
reports_.add_reports(strings::Printf("device: %s low utilization: %.2f",
|
reports_.add_reports(absl::StrFormat("device: %s low utilization: %.2f",
|
||||||
s.first.c_str(), utilization));
|
s.first, utilization));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reports_;
|
return reports_;
|
||||||
|
|||||||
@ -16,7 +16,6 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_CHECKER_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_CHECKER_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_CHECKER_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_CHECKER_H_
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
|
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
|
||||||
#include "tensorflow/core/profiler/tfprof_options.pb.h"
|
#include "tensorflow/core/profiler/tfprof_options.pb.h"
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_EXPENSIVE_OPERATION_CHECKER_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_EXPENSIVE_OPERATION_CHECKER_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_EXPENSIVE_OPERATION_CHECKER_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_EXPENSIVE_OPERATION_CHECKER_H_
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_join.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -29,12 +31,12 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
||||||
const TFStats* stats) override {
|
const TFStats* stats) override {
|
||||||
if (!stats) {
|
if (!stats) {
|
||||||
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
|
absl::FPrintF(
|
||||||
name().c_str());
|
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
|
||||||
return reports_;
|
return reports_;
|
||||||
}
|
}
|
||||||
if (stats->steps().empty()) {
|
if (stats->steps().empty()) {
|
||||||
fprintf(stderr, "Missing RunMetadata info. Skip %s\n", name().c_str());
|
absl::FPrintF(stderr, "Missing RunMetadata info. Skip %s\n", name());
|
||||||
}
|
}
|
||||||
CheckOpView(stats);
|
CheckOpView(stats);
|
||||||
CheckScopeView(stats);
|
CheckScopeView(stats);
|
||||||
@ -44,7 +46,7 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
|
|
||||||
void CheckOpView(const TFStats* stats) {
|
void CheckOpView(const TFStats* stats) {
|
||||||
if (stats->steps().empty()) {
|
if (stats->steps().empty()) {
|
||||||
fprintf(stderr, "Missing run_meta for %s\n", name().c_str());
|
absl::FPrintF(stderr, "Missing run_meta for %s\n", name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Options opts(3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, "micros", {".*"}, {".*"},
|
Options opts(3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, "micros", {".*"}, {".*"},
|
||||||
@ -57,21 +59,20 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
std::vector<string> outputs;
|
std::vector<string> outputs;
|
||||||
for (int i = 0; i < 3 && node->children_size() > 0; ++i) {
|
for (int i = 0; i < 3 && node->children_size() > 0; ++i) {
|
||||||
node = &node->children(0);
|
node = &node->children(0);
|
||||||
outputs.push_back(strings::Printf(
|
outputs.push_back(absl::StrFormat(
|
||||||
"top %d operation type: %s, "
|
"top %d operation type: %s, "
|
||||||
"cpu: %s, accelerator: %s, total: %s (%.2f%%)",
|
"cpu: %s, accelerator: %s, total: %s (%.2f%%)",
|
||||||
i + 1, node->name().c_str(),
|
i + 1, node->name(), FormatTime(node->cpu_exec_micros()),
|
||||||
FormatTime(node->cpu_exec_micros()).c_str(),
|
FormatTime(node->accelerator_exec_micros()),
|
||||||
FormatTime(node->accelerator_exec_micros()).c_str(),
|
FormatTime(node->exec_micros()),
|
||||||
FormatTime(node->exec_micros()).c_str(),
|
|
||||||
100.0 * node->exec_micros() / (root.total_exec_micros() + 1e-10)));
|
100.0 * node->exec_micros() / (root.total_exec_micros() + 1e-10)));
|
||||||
}
|
}
|
||||||
reports_.add_reports(str_util::Join(outputs, "\n"));
|
reports_.add_reports(absl::StrJoin(outputs, "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckCodeView(const TFStats* stats) {
|
void CheckCodeView(const TFStats* stats) {
|
||||||
if (!stats->has_code_traces()) {
|
if (!stats->has_code_traces()) {
|
||||||
fprintf(stderr, "Missing op_log (code traces) for %s\n", name().c_str());
|
absl::FPrintF(stderr, "Missing op_log (code traces) for %s\n", name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Options opts(100, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, "micros", {".*"},
|
Options opts(100, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, "micros", {".*"},
|
||||||
@ -89,7 +90,7 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
|
|
||||||
std::vector<string> outputs;
|
std::vector<string> outputs;
|
||||||
CodeViewHelper(node, 0, &outputs);
|
CodeViewHelper(node, 0, &outputs);
|
||||||
reports_.add_reports(str_util::Join(outputs, "\n"));
|
reports_.add_reports(absl::StrJoin(outputs, "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckScopeView(const TFStats* stats) {
|
void CheckScopeView(const TFStats* stats) {
|
||||||
@ -102,13 +103,13 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
std::vector<string> outputs;
|
std::vector<string> outputs;
|
||||||
for (int i = 0; i < 3 && i < root.children_size(); ++i) {
|
for (int i = 0; i < 3 && i < root.children_size(); ++i) {
|
||||||
const GraphNodeProto& node = root.children(i);
|
const GraphNodeProto& node = root.children(i);
|
||||||
outputs.push_back(strings::Printf(
|
outputs.push_back(absl::StrFormat(
|
||||||
"top %d graph node: %s, cpu: %s, accelerator: %s, total: %s", i + 1,
|
"top %d graph node: %s, cpu: %s, accelerator: %s, total: %s", i + 1,
|
||||||
node.name().c_str(), FormatTime(node.cpu_exec_micros()).c_str(),
|
node.name(), FormatTime(node.cpu_exec_micros()),
|
||||||
FormatTime(node.accelerator_exec_micros()).c_str(),
|
FormatTime(node.accelerator_exec_micros()),
|
||||||
FormatTime(node.exec_micros()).c_str()));
|
FormatTime(node.exec_micros())));
|
||||||
}
|
}
|
||||||
reports_.add_reports(str_util::Join(outputs, "\n"));
|
reports_.add_reports(absl::StrJoin(outputs, "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeViewHelper(const MultiGraphNodeProto* node, int depth,
|
void CodeViewHelper(const MultiGraphNodeProto* node, int depth,
|
||||||
@ -121,12 +122,12 @@ class ExpensiveOperationChecker : public Checker {
|
|||||||
if (c->total_exec_micros() < 1000) {
|
if (c->total_exec_micros() < 1000) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
outputs->push_back(strings::Printf(
|
outputs->push_back(
|
||||||
"%s%s, cpu: %s, accelerator: %s, total: %s",
|
absl::StrFormat("%s%s, cpu: %s, accelerator: %s, total: %s",
|
||||||
string(depth * 2, ' ').c_str(), c->name().c_str(),
|
std::string(depth * 2, ' '), c->name(),
|
||||||
FormatTime(c->total_cpu_exec_micros()).c_str(),
|
FormatTime(c->total_cpu_exec_micros()),
|
||||||
FormatTime(c->total_accelerator_exec_micros()).c_str(),
|
FormatTime(c->total_accelerator_exec_micros()),
|
||||||
FormatTime(c->total_exec_micros()).c_str()));
|
FormatTime(c->total_exec_micros())));
|
||||||
CodeViewHelper(c, depth + 1, outputs);
|
CodeViewHelper(c, depth + 1, outputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_OPERATION_CHECKER_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_OPERATION_CHECKER_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_OPERATION_CHECKER_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_OPERATION_CHECKER_H_
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -30,8 +31,8 @@ class OperationChecker : public Checker {
|
|||||||
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
|
||||||
const TFStats* stats) override {
|
const TFStats* stats) override {
|
||||||
if (!stats) {
|
if (!stats) {
|
||||||
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
|
absl::FPrintF(
|
||||||
name().c_str());
|
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
|
||||||
return reports_;
|
return reports_;
|
||||||
}
|
}
|
||||||
bool use_batch_norm = false;
|
bool use_batch_norm = false;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_TFPROF_ADVISOR_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_TFPROF_ADVISOR_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_TFPROF_ADVISOR_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_ADVISOR_TFPROF_ADVISOR_H_
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/accelerator_utilization_checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/accelerator_utilization_checker.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/checker.h"
|
||||||
#include "tensorflow/core/profiler/internal/advisor/expensive_operation_checker.h"
|
#include "tensorflow/core/profiler/internal/advisor/expensive_operation_checker.h"
|
||||||
@ -62,9 +63,9 @@ class Advisor {
|
|||||||
stats_));
|
stats_));
|
||||||
}
|
}
|
||||||
for (const auto& checker : ret.checkers()) {
|
for (const auto& checker : ret.checkers()) {
|
||||||
fprintf(stdout, "\n%s:\n", checker.first.c_str());
|
absl::FPrintF(stdout, "\n%s:\n", checker.first);
|
||||||
for (const string& r : checker.second.reports()) {
|
for (const string& r : checker.second.reports()) {
|
||||||
fprintf(stdout, "%s\n", r.c_str());
|
absl::FPrintF(stdout, "%s\n", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|||||||
@ -16,7 +16,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/advisor/tfprof_advisor.h"
|
#include "tensorflow/core/profiler/internal/advisor/tfprof_advisor.h"
|
||||||
|
|
||||||
#include "tensorflow/core/lib/io/path.h"
|
#include "tensorflow/core/lib/io/path.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/platform/test.h"
|
#include "tensorflow/core/platform/test.h"
|
||||||
|
|
||||||
|
|||||||
@ -21,12 +21,11 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "absl/container/fixed_array.h"
|
#include "absl/container/fixed_array.h"
|
||||||
#include "absl/strings/str_cat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/common_runtime/step_stats_collector.h"
|
#include "tensorflow/core/common_runtime/step_stats_collector.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/platform/abi.h"
|
#include "tensorflow/core/platform/abi.h"
|
||||||
#include "tensorflow/core/platform/macros.h"
|
#include "tensorflow/core/platform/macros.h"
|
||||||
#include "tensorflow/core/platform/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/annotation_stack.h"
|
#include "tensorflow/core/profiler/internal/annotation_stack.h"
|
||||||
#include "tensorflow/core/profiler/internal/gpu/cupti_tracer.h"
|
#include "tensorflow/core/profiler/internal/gpu/cupti_tracer.h"
|
||||||
#include "tensorflow/core/profiler/internal/gpu/cupti_wrapper.h"
|
#include "tensorflow/core/profiler/internal/gpu/cupti_wrapper.h"
|
||||||
@ -165,8 +164,8 @@ class CuptiTraceCollectorImpl : public CuptiTraceCollector {
|
|||||||
ns->set_node_name(activity_name);
|
ns->set_node_name(activity_name);
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case CuptiTracerEventType::Kernel: {
|
case CuptiTracerEventType::Kernel: {
|
||||||
const std::string details = strings::Printf(
|
const std::string details = absl::StrFormat(
|
||||||
"regs:%llu shm:%llu grid:%llu,%llu,%llu block:%llu,%llu,%llu",
|
"regs:%u shm:%u grid:%u,%u,%u block:%u,%u,%u",
|
||||||
event.kernel_info.registers_per_thread,
|
event.kernel_info.registers_per_thread,
|
||||||
event.kernel_info.static_shared_memory_usage,
|
event.kernel_info.static_shared_memory_usage,
|
||||||
event.kernel_info.grid_x, event.kernel_info.grid_y,
|
event.kernel_info.grid_x, event.kernel_info.grid_y,
|
||||||
|
|||||||
@ -16,9 +16,11 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/print_model_analysis.h"
|
#include "tensorflow/core/profiler/internal/print_model_analysis.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/c/checkpoint_reader.h"
|
#include "tensorflow/c/checkpoint_reader.h"
|
||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
@ -40,7 +42,7 @@ string RunProfile(const string& command, const string& options,
|
|||||||
if (command == kCmds[4]) {
|
if (command == kCmds[4]) {
|
||||||
AdvisorOptionsProto option_pb;
|
AdvisorOptionsProto option_pb;
|
||||||
if (!option_pb.ParseFromString(options)) {
|
if (!option_pb.ParseFromString(options)) {
|
||||||
fprintf(stderr, "Cannot parse AdvisorOptionsProto\n");
|
absl::FPrintF(stderr, "Cannot parse AdvisorOptionsProto\n");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
tf_stats->BuildAllViews();
|
tf_stats->BuildAllViews();
|
||||||
@ -52,23 +54,26 @@ string RunProfile(const string& command, const string& options,
|
|||||||
Options opts;
|
Options opts;
|
||||||
tensorflow::Status s = Options::FromProtoStr(options, &opts);
|
tensorflow::Status s = Options::FromProtoStr(options, &opts);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "%s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "%s\n", s.ToString());
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.output_type == kOutput[1]) {
|
if (opts.output_type == kOutput[1]) {
|
||||||
printf("\n=========================Options=============================\n");
|
absl::PrintF(
|
||||||
printf("%s", opts.ToString().c_str());
|
"\n=========================Options=============================\n");
|
||||||
printf("\n==================Model Analysis Report======================\n");
|
absl::PrintF("%s", opts.ToString());
|
||||||
|
absl::PrintF(
|
||||||
|
"\n==================Model Analysis Report======================\n");
|
||||||
string ret = "";
|
string ret = "";
|
||||||
if (command == kCmds[2] || command == kCmds[3]) {
|
if (command == kCmds[2] || command == kCmds[3]) {
|
||||||
ret = tf_stats->ShowMultiGraphNode(command, opts).SerializeAsString();
|
ret = tf_stats->ShowMultiGraphNode(command, opts).SerializeAsString();
|
||||||
} else if (command == kCmds[0] || command == kCmds[1]) {
|
} else if (command == kCmds[0] || command == kCmds[1]) {
|
||||||
ret = tf_stats->ShowGraphNode(command, opts).SerializeAsString();
|
ret = tf_stats->ShowGraphNode(command, opts).SerializeAsString();
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown command: %s\n", command.c_str());
|
absl::FPrintF(stderr, "Unknown command: %s\n", command);
|
||||||
}
|
}
|
||||||
printf("\n======================End of Report==========================\n");
|
absl::PrintF(
|
||||||
|
"\n======================End of Report==========================\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -77,7 +82,7 @@ string RunProfile(const string& command, const string& options,
|
|||||||
} else if (command == kCmds[0] || command == kCmds[1]) {
|
} else if (command == kCmds[0] || command == kCmds[1]) {
|
||||||
return tf_stats->ShowGraphNode(command, opts).SerializeAsString();
|
return tf_stats->ShowGraphNode(command, opts).SerializeAsString();
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown command: %s\n", command.c_str());
|
absl::FPrintF(stderr, "Unknown command: %s\n", command);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +93,7 @@ bool NewProfiler(const string* graph, const string* op_log) {
|
|||||||
if (graph && !graph->empty()) {
|
if (graph && !graph->empty()) {
|
||||||
if (!graph_ptr->ParseFromString(*graph)) {
|
if (!graph_ptr->ParseFromString(*graph)) {
|
||||||
if (!protobuf::TextFormat::ParseFromString(*graph, graph_ptr.get())) {
|
if (!protobuf::TextFormat::ParseFromString(*graph, graph_ptr.get())) {
|
||||||
fprintf(stderr, "Failed to parse graph\n");
|
absl::FPrintF(stderr, "Failed to parse graph\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +103,7 @@ bool NewProfiler(const string* graph, const string* op_log) {
|
|||||||
if (op_log && !op_log->empty()) {
|
if (op_log && !op_log->empty()) {
|
||||||
op_log_ptr.reset(new OpLogProto());
|
op_log_ptr.reset(new OpLogProto());
|
||||||
if (!op_log_ptr->ParseFromString(*op_log)) {
|
if (!op_log_ptr->ParseFromString(*op_log)) {
|
||||||
fprintf(stderr, "Failed to parse OpLogProto.\n");
|
absl::FPrintF(stderr, "Failed to parse OpLogProto.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +133,7 @@ double AddStep(int64 step, const string* graph, const string* run_meta,
|
|||||||
std::unique_ptr<GraphDef> graph_ptr(new GraphDef());
|
std::unique_ptr<GraphDef> graph_ptr(new GraphDef());
|
||||||
if (!graph_ptr->ParseFromString(*graph)) {
|
if (!graph_ptr->ParseFromString(*graph)) {
|
||||||
if (!protobuf::TextFormat::ParseFromString(*graph, graph_ptr.get())) {
|
if (!protobuf::TextFormat::ParseFromString(*graph, graph_ptr.get())) {
|
||||||
fprintf(stderr, "Failed to parse graph\n");
|
absl::FPrintF(stderr, "Failed to parse graph\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tf_stat->AddGraph(std::move(graph_ptr));
|
tf_stat->AddGraph(std::move(graph_ptr));
|
||||||
|
|||||||
@ -16,16 +16,16 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_code.h"
|
#include "tensorflow/core/profiler/internal/tfprof_code.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/c/c_api.h"
|
#include "tensorflow/c/c_api.h"
|
||||||
#include "tensorflow/core/framework/tensor.h"
|
#include "tensorflow/core/framework/tensor.h"
|
||||||
#include "tensorflow/core/lib/io/path.h"
|
#include "tensorflow/core/lib/io/path.h"
|
||||||
#include "tensorflow/core/lib/io/zlib_compression_options.h"
|
#include "tensorflow/core/lib/io/zlib_compression_options.h"
|
||||||
#include "tensorflow/core/lib/io/zlib_outputbuffer.h"
|
#include "tensorflow/core/lib/io/zlib_outputbuffer.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
|
|
||||||
@ -36,13 +36,13 @@ namespace {
|
|||||||
const char* const kGradientSuffix = " (gradient)";
|
const char* const kGradientSuffix = " (gradient)";
|
||||||
|
|
||||||
// Convert to Trace proto into a short readable string.
|
// Convert to Trace proto into a short readable string.
|
||||||
string GetTraceString(const CallStack::Trace& trace) {
|
std::string GetTraceString(const CallStack::Trace& trace) {
|
||||||
string ntrace(io::Basename(trace.file()));
|
std::string ntrace =
|
||||||
ntrace += strings::StrCat(":", trace.lineno());
|
absl::StrCat(io::Basename(trace.file()), ":", trace.lineno());
|
||||||
if (trace.function().length() < 20) {
|
if (trace.function().length() < 20) {
|
||||||
ntrace += ":" + trace.function();
|
absl::StrAppend(&ntrace, ":", trace.function());
|
||||||
} else {
|
} else {
|
||||||
ntrace += ":" + trace.function().substr(0, 17) + "...";
|
absl::StrAppend(&ntrace, ":", trace.function().substr(0, 17), "...");
|
||||||
}
|
}
|
||||||
return ntrace;
|
return ntrace;
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ class FunctionTable {
|
|||||||
string file_base(io::Basename(file_path));
|
string file_base(io::Basename(file_path));
|
||||||
file_base = file_base.substr(0, file_base.find_last_of("."));
|
file_base = file_base.substr(0, file_base.find_last_of("."));
|
||||||
func_pb->set_name(
|
func_pb->set_name(
|
||||||
string_table_->GetIndex(strings::StrCat(file_base, ":", func_name)));
|
string_table_->GetIndex(absl::StrCat(file_base, ":", func_name)));
|
||||||
func_pb->set_filename(string_table_->GetIndex(file_path));
|
func_pb->set_filename(string_table_->GetIndex(file_path));
|
||||||
func_pb->set_start_line(func_start_line);
|
func_pb->set_start_line(func_start_line);
|
||||||
return func_pb->id();
|
return func_pb->id();
|
||||||
@ -229,7 +229,7 @@ class Samples {
|
|||||||
} else if (type == kShown[3]) {
|
} else if (type == kShown[3]) {
|
||||||
sample_pb->mutable_value()->Add(gn->float_ops(node->node->step()));
|
sample_pb->mutable_value()->Add(gn->float_ops(node->node->step()));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "pprof doesn't support -select=%s\n", type.c_str());
|
absl::FPrintF(stderr, "pprof doesn't support -select=%s\n", type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,8 +309,9 @@ class PprofProfileImpl : public PprofProfile {
|
|||||||
delete zlib_output_buffer;
|
delete zlib_output_buffer;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "\nRun pprof -png --nodecount=100 --sample_index=1 <%s>\n",
|
absl::FPrintF(stdout,
|
||||||
filename.c_str());
|
"\nRun pprof -png --nodecount=100 --sample_index=1 <%s>\n",
|
||||||
|
filename);
|
||||||
delete zlib_output_buffer;
|
delete zlib_output_buffer;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -364,7 +365,7 @@ class PprofProfileImpl : public PprofProfile {
|
|||||||
profile_pb->mutable_comment()->Add(string_table_.GetIndex(
|
profile_pb->mutable_comment()->Add(string_table_.GetIndex(
|
||||||
"Model float operations (Only available if defined)."));
|
"Model float operations (Only available if defined)."));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "pprof doesn't support selecting: %s\n", type.c_str());
|
absl::FPrintF(stderr, "pprof doesn't support selecting: %s\n", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const string& str : string_table_.strings()) {
|
for (const string& str : string_table_.strings()) {
|
||||||
@ -459,7 +460,8 @@ void TFCode::Build() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unaccounted_nodes > 0) {
|
if (unaccounted_nodes > 0) {
|
||||||
fprintf(stderr, "%lld gradient nodes not accounted\n", unaccounted_nodes);
|
absl::FPrintF(stderr, "%d gradient nodes not accounted\n",
|
||||||
|
unaccounted_nodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,19 +470,20 @@ const ShowMultiNode* TFCode::ShowInternal(const Options& opts,
|
|||||||
root_->ResetTotalStats();
|
root_->ResetTotalStats();
|
||||||
if (opts.output_type == kOutput[3]) {
|
if (opts.output_type == kOutput[3]) {
|
||||||
if (opts.select.size() != 1) {
|
if (opts.select.size() != 1) {
|
||||||
fprintf(stderr, "Can only select 1 attribute for pprof output.\n");
|
absl::FPrintF(stderr, "Can only select 1 attribute for pprof output.\n");
|
||||||
return root_.get();
|
return root_.get();
|
||||||
}
|
}
|
||||||
string select = *opts.select.begin();
|
string select = *opts.select.begin();
|
||||||
if (select != kShown[0] && select != kShown[1] && select != kShown[2] &&
|
if (select != kShown[0] && select != kShown[1] && select != kShown[2] &&
|
||||||
select != kShown[3] && select != kShown[9] && select != kShown[10] &&
|
select != kShown[3] && select != kShown[9] && select != kShown[10] &&
|
||||||
select != kShown[11] && select != kShown[12] && select != kShown[13]) {
|
select != kShown[11] && select != kShown[12] && select != kShown[13]) {
|
||||||
fprintf(stderr, "pprof doesn't support -select=%s\n", select.c_str());
|
absl::FPrintF(stderr, "pprof doesn't support -select=%s\n", select);
|
||||||
return root_.get();
|
return root_.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opts.account_displayed_op_only) {
|
if (opts.account_displayed_op_only) {
|
||||||
fprintf(stderr, "Note: code view ignores account_displayed_op_only\n");
|
absl::FPrintF(stderr,
|
||||||
|
"Note: code view ignores account_displayed_op_only\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CodeNode*> roots = Account(root_->children, opts);
|
std::vector<CodeNode*> roots = Account(root_->children, opts);
|
||||||
@ -508,7 +511,7 @@ const ShowMultiNode* TFCode::ShowInternal(const Options& opts,
|
|||||||
Status s = pprof_profile_->WritePprofProfile(
|
Status s = pprof_profile_->WritePprofProfile(
|
||||||
opts.output_options.at(kPprofOpts[0]));
|
opts.output_options.at(kPprofOpts[0]));
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "%s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "%s\n", s.ToString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Format(root, root->show_children, opts, &root->formatted_str,
|
Format(root, root->show_children, opts, &root->formatted_str,
|
||||||
@ -593,7 +596,7 @@ std::vector<CodeNode*> TFCode::PrintScope(const std::vector<CodeNode*> roots,
|
|||||||
node->formatted_str = FormatNode(node, opts, last_ident);
|
node->formatted_str = FormatNode(node, opts, last_ident);
|
||||||
|
|
||||||
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
||||||
fprintf(stderr, "code view has no tensor value to show\n");
|
absl::FPrintF(stderr, "code view has no tensor value to show\n");
|
||||||
}
|
}
|
||||||
show_nodes.push_back(node);
|
show_nodes.push_back(node);
|
||||||
} else {
|
} else {
|
||||||
@ -690,15 +693,14 @@ string TFCode::FormatNode(CodeNode* node, const Options& opts,
|
|||||||
}
|
}
|
||||||
if (opts.select.find(kShown[7]) != opts.select.end()) {
|
if (opts.select.find(kShown[7]) != opts.select.end()) {
|
||||||
// TODO(xpan): Make op count available in code view?
|
// TODO(xpan): Make op count available in code view?
|
||||||
attrs.push_back(strings::Printf("%s N/A in code view", kShown[7]));
|
attrs.push_back(absl::StrFormat("%s N/A in code view", kShown[7]));
|
||||||
}
|
}
|
||||||
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
||||||
attrs.push_back(strings::Printf("%s N/A in code view", kShown[8]));
|
attrs.push_back(absl::StrFormat("%s N/A in code view", kShown[8]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings::Printf("%s%s (%s)\n", string(indent, ' ').c_str(),
|
return absl::StrFormat("%s%s (%s)\n", std::string(indent, ' '), node->name(),
|
||||||
node->name().c_str(),
|
absl::StrJoin(attrs, ", "));
|
||||||
absl::StrJoin(attrs, ", ").c_str());
|
|
||||||
}
|
}
|
||||||
} // namespace tfprof
|
} // namespace tfprof
|
||||||
} // namespace tensorflow
|
} // namespace tensorflow
|
||||||
|
|||||||
@ -16,10 +16,10 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_graph.h"
|
#include "tensorflow/core/profiler/internal/tfprof_graph.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
||||||
@ -74,13 +74,14 @@ const ShowNode* TFGraph::ShowInternal(const Options& opts, Timeline* timeline) {
|
|||||||
root_->show_children.clear();
|
root_->show_children.clear();
|
||||||
|
|
||||||
if (opts.output_type == kOutput[3]) {
|
if (opts.output_type == kOutput[3]) {
|
||||||
fprintf(stderr, "Only 'code' view supports pprof output now.\n");
|
absl::FPrintF(stderr, "Only 'code' view supports pprof output now.\n");
|
||||||
return root_;
|
return root_;
|
||||||
}
|
}
|
||||||
if (timeline && timeline->step() < 0) {
|
if (timeline && timeline->step() < 0) {
|
||||||
// TODO(xpan): Maybe pick a default step for users.
|
// TODO(xpan): Maybe pick a default step for users.
|
||||||
fprintf(stderr,
|
absl::FPrintF(
|
||||||
"Must specify -step option to generate timeline in graph view.\n");
|
stderr,
|
||||||
|
"Must specify -step option to generate timeline in graph view.\n");
|
||||||
return root_;
|
return root_;
|
||||||
}
|
}
|
||||||
// 1. Account and aggregate the stats based on the graph structure.
|
// 1. Account and aggregate the stats based on the graph structure.
|
||||||
@ -188,9 +189,8 @@ std::vector<GraphNode*> TFGraph::PrintGraph(const std::vector<GraphNode*> roots,
|
|||||||
node->AggregateTotalStats(sc);
|
node->AggregateTotalStats(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node->formatted_str =
|
node->formatted_str = absl::StrFormat(
|
||||||
strings::Printf("%s%s\n", string(last_ident, ' ').c_str(),
|
"%s%s\n", std::string(last_ident, ' '), FormatNode(node, opts));
|
||||||
FormatNode(node, opts).c_str());
|
|
||||||
|
|
||||||
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
||||||
std::unique_ptr<TFProfTensor> tfprof_tensor;
|
std::unique_ptr<TFProfTensor> tfprof_tensor;
|
||||||
|
|||||||
@ -85,8 +85,8 @@ void ExecStep::AddMemoryStats(const string& dev,
|
|||||||
exec_mem.set_memory_micros(step_stat.all_start_micros() +
|
exec_mem.set_memory_micros(step_stat.all_start_micros() +
|
||||||
step_stat.op_end_rel_micros());
|
step_stat.op_end_rel_micros());
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s has no start time, skipping\n",
|
absl::FPrintF(stderr, "%s has no start time, skipping\n",
|
||||||
step_stat.node_name().c_str());
|
step_stat.node_name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +106,8 @@ void ExecStep::AddMemoryStats(const string& dev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (accelerator_allocator_cnt > 1) {
|
if (accelerator_allocator_cnt > 1) {
|
||||||
fprintf(stderr, "found %d gpu allocator for 1 node\n",
|
absl::FPrintF(stderr, "found %d gpu allocator for 1 node\n",
|
||||||
accelerator_allocator_cnt);
|
accelerator_allocator_cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 total_output_bytes = 0;
|
int64 total_output_bytes = 0;
|
||||||
|
|||||||
@ -21,6 +21,7 @@ limitations under the License.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/framework/allocation_description.pb.h"
|
#include "tensorflow/core/framework/allocation_description.pb.h"
|
||||||
#include "tensorflow/core/framework/attr_value.pb.h"
|
#include "tensorflow/core/framework/attr_value.pb.h"
|
||||||
#include "tensorflow/core/framework/node_def.pb.h"
|
#include "tensorflow/core/framework/node_def.pb.h"
|
||||||
@ -28,8 +29,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/framework/tensor_description.pb.h"
|
#include "tensorflow/core/framework/tensor_description.pb.h"
|
||||||
#include "tensorflow/core/framework/tensor_shape.pb.h"
|
#include "tensorflow/core/framework/tensor_shape.pb.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/tfprof_log.pb.h"
|
#include "tensorflow/core/profiler/tfprof_log.pb.h"
|
||||||
#include "tensorflow/core/profiler/tfprof_options.h"
|
#include "tensorflow/core/profiler/tfprof_options.h"
|
||||||
@ -326,13 +325,13 @@ class TFGraphNode {
|
|||||||
(*node_.mutable_attrs())[attr.first].MergeFrom(attr.second);
|
(*node_.mutable_attrs())[attr.first].MergeFrom(attr.second);
|
||||||
if (attr.first == "shape" && attr.second.has_shape()) {
|
if (attr.first == "shape" && attr.second.has_shape()) {
|
||||||
if (!shape_.empty()) {
|
if (!shape_.empty()) {
|
||||||
fprintf(stderr, "Found duplicated shapes!\n");
|
absl::FPrintF(stderr, "Found duplicated shapes!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
shape_ = ShapeProtoToVec(attr.second.shape());
|
shape_ = ShapeProtoToVec(attr.second.shape());
|
||||||
} else if (attr.first == "_output_shapes" && attr.second.has_list()) {
|
} else if (attr.first == "_output_shapes" && attr.second.has_list()) {
|
||||||
if (!output_shapes_.empty()) {
|
if (!output_shapes_.empty()) {
|
||||||
fprintf(stderr, "Found duplicated output shapes!\n");
|
absl::FPrintF(stderr, "Found duplicated output shapes!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < attr.second.list().shape_size(); ++i) {
|
for (int i = 0; i < attr.second.list().shape_size(); ++i) {
|
||||||
@ -669,7 +668,7 @@ class TFGraphNode {
|
|||||||
if (complete_shape) {
|
if (complete_shape) {
|
||||||
return params;
|
return params;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Incomplete shape.\n");
|
absl::FPrintF(stderr, "Incomplete shape.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -14,9 +14,6 @@ limitations under the License.
|
|||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
namespace tfprof {
|
namespace tfprof {
|
||||||
namespace {}
|
namespace {}
|
||||||
|
|||||||
@ -16,10 +16,11 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_op.h"
|
#include "tensorflow/core/profiler/internal/tfprof_op.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
||||||
@ -38,11 +39,10 @@ string FormatToalExecTime(const ShowMultiNode* node,
|
|||||||
100.0 * node->proto().exec_micros() / root->proto().total_exec_micros();
|
100.0 * node->proto().exec_micros() / root->proto().total_exec_micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings::Printf(
|
return absl::StrFormat(
|
||||||
"%30s", strings::Printf("%s (%.2f%%, %.2f%%)",
|
"%30s",
|
||||||
FormatTime(node->proto().exec_micros()).c_str(),
|
absl::StrFormat("%s (%.2f%%, %.2f%%)",
|
||||||
accu_pct, pct)
|
FormatTime(node->proto().exec_micros()), accu_pct, pct));
|
||||||
.c_str());
|
|
||||||
}
|
}
|
||||||
string FormatCPUExecTime(const ShowMultiNode* node, const ShowMultiNode* root) {
|
string FormatCPUExecTime(const ShowMultiNode* node, const ShowMultiNode* root) {
|
||||||
double accu_pct = 0.0;
|
double accu_pct = 0.0;
|
||||||
@ -54,12 +54,10 @@ string FormatCPUExecTime(const ShowMultiNode* node, const ShowMultiNode* root) {
|
|||||||
root->proto().total_cpu_exec_micros();
|
root->proto().total_cpu_exec_micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings::Printf(
|
return absl::StrFormat(
|
||||||
"%30s",
|
"%30s", absl::StrFormat("%s (%.2f%%, %.2f%%)",
|
||||||
strings::Printf("%s (%.2f%%, %.2f%%)",
|
FormatTime(node->proto().cpu_exec_micros()),
|
||||||
FormatTime(node->proto().cpu_exec_micros()).c_str(),
|
accu_pct, pct));
|
||||||
accu_pct, pct)
|
|
||||||
.c_str());
|
|
||||||
}
|
}
|
||||||
string FormatAcceleratorExecTime(const ShowMultiNode* node,
|
string FormatAcceleratorExecTime(const ShowMultiNode* node,
|
||||||
const ShowMultiNode* root) {
|
const ShowMultiNode* root) {
|
||||||
@ -72,12 +70,11 @@ string FormatAcceleratorExecTime(const ShowMultiNode* node,
|
|||||||
root->proto().total_accelerator_exec_micros();
|
root->proto().total_accelerator_exec_micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings::Printf(
|
return absl::StrFormat(
|
||||||
"%30s", strings::Printf(
|
"%30s",
|
||||||
"%s (%.2f%%, %.2f%%)",
|
absl::StrFormat("%s (%.2f%%, %.2f%%)",
|
||||||
FormatTime(node->proto().accelerator_exec_micros()).c_str(),
|
FormatTime(node->proto().accelerator_exec_micros()),
|
||||||
accu_pct, pct)
|
accu_pct, pct));
|
||||||
.c_str());
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -106,16 +103,16 @@ const ShowMultiNode* TFOp::ShowInternal(const Options& opts,
|
|||||||
Timeline* timeline) {
|
Timeline* timeline) {
|
||||||
root_->ResetTotalStats();
|
root_->ResetTotalStats();
|
||||||
if (opts.output_type == kOutput[3]) {
|
if (opts.output_type == kOutput[3]) {
|
||||||
fprintf(stderr, "Only 'code' view supports pprof output now.\n");
|
absl::FPrintF(stderr, "Only 'code' view supports pprof output now.\n");
|
||||||
return root_.get();
|
return root_.get();
|
||||||
}
|
}
|
||||||
if (opts.output_type == kOutput[1] || opts.output_type == kOutput[2]) {
|
if (opts.output_type == kOutput[1] || opts.output_type == kOutput[2]) {
|
||||||
root_->formatted_str = FormatNode(root_.get(), root_.get(), opts);
|
root_->formatted_str = FormatNode(root_.get(), root_.get(), opts);
|
||||||
}
|
}
|
||||||
if (timeline) {
|
if (timeline) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"op view doesn't support timeline yet. "
|
"op view doesn't support timeline yet. "
|
||||||
"Consider graph/scope/code view.\n");
|
"Consider graph/scope/code view.\n");
|
||||||
return root_.get();
|
return root_.get();
|
||||||
}
|
}
|
||||||
if (cnodes_map_.empty()) {
|
if (cnodes_map_.empty()) {
|
||||||
@ -216,10 +213,9 @@ string TFOp::FormatMemoryNode(int64 node_total_bytes, int64 root_total_bytes,
|
|||||||
accu_pct = 100.0 * node_total_bytes / root_total_bytes;
|
accu_pct = 100.0 * node_total_bytes / root_total_bytes;
|
||||||
pct = 100.0 * node_bytes / root_total_bytes;
|
pct = 100.0 * node_bytes / root_total_bytes;
|
||||||
}
|
}
|
||||||
return strings::Printf(
|
return absl::StrFormat(
|
||||||
"%30s", strings::Printf("%s (%.2f%%, %.2f%%)",
|
"%30s", absl::StrFormat("%s (%.2f%%, %.2f%%)", FormatMemory(node_bytes),
|
||||||
FormatMemory(node_bytes).c_str(), accu_pct, pct)
|
accu_pct, pct));
|
||||||
.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string TFOp::FormatNode(OpNode* node, OpNode* root, const Options& opts) const {
|
string TFOp::FormatNode(OpNode* node, OpNode* root, const Options& opts) const {
|
||||||
@ -270,12 +266,10 @@ string TFOp::FormatNode(OpNode* node, OpNode* root, const Options& opts) const {
|
|||||||
pct =
|
pct =
|
||||||
100.0 * node->proto().parameters() / root->proto().total_parameters();
|
100.0 * node->proto().parameters() / root->proto().total_parameters();
|
||||||
}
|
}
|
||||||
attrs.push_back(strings::Printf(
|
attrs.push_back(absl::StrFormat(
|
||||||
"%30s",
|
"%30s", absl::StrFormat("%s params (%.2f%%, %.2f%%)",
|
||||||
strings::Printf("%s params (%.2f%%, %.2f%%)",
|
FormatNumber(node->proto().parameters()),
|
||||||
FormatNumber(node->proto().parameters()).c_str(),
|
accu_pct, pct)));
|
||||||
accu_pct, pct)
|
|
||||||
.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.select.find(kShown[3]) != opts.select.end()) {
|
if (opts.select.find(kShown[3]) != opts.select.end()) {
|
||||||
@ -287,11 +281,10 @@ string TFOp::FormatNode(OpNode* node, OpNode* root, const Options& opts) const {
|
|||||||
pct = 100.0 * node->proto().float_ops() / root->proto().total_float_ops();
|
pct = 100.0 * node->proto().float_ops() / root->proto().total_float_ops();
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs.push_back(strings::Printf(
|
attrs.push_back(absl::StrFormat(
|
||||||
"%30s", strings::Printf("%s float_ops (%.2f%%, %.2f%%)",
|
"%30s", absl::StrFormat("%s float_ops (%.2f%%, %.2f%%)",
|
||||||
FormatNumber(node->proto().float_ops()).c_str(),
|
FormatNumber(node->proto().float_ops()),
|
||||||
accu_pct, pct)
|
accu_pct, pct)));
|
||||||
.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.select.find(kShown[5]) != opts.select.end()) {
|
if (opts.select.find(kShown[5]) != opts.select.end()) {
|
||||||
@ -308,20 +301,18 @@ string TFOp::FormatNode(OpNode* node, OpNode* root, const Options& opts) const {
|
|||||||
for (const auto& gnode : node->proto().graph_nodes()) {
|
for (const auto& gnode : node->proto().graph_nodes()) {
|
||||||
total_runs += gnode.run_count();
|
total_runs += gnode.run_count();
|
||||||
}
|
}
|
||||||
attrs.push_back(strings::Printf(
|
attrs.push_back(absl::StrFormat(
|
||||||
"%10s",
|
"%10s", absl::StrFormat("%d|%d", total_runs,
|
||||||
strings::Printf("%lld|%d", total_runs, node->proto().graph_nodes_size())
|
node->proto().graph_nodes_size())));
|
||||||
.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string node_str = strings::Printf("%-25s%s\n", node->name().c_str(),
|
string node_str =
|
||||||
absl::StrJoin(attrs, ", ").c_str());
|
absl::StrFormat("%-25s%s\n", node->name(), absl::StrJoin(attrs, ", "));
|
||||||
|
|
||||||
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
||||||
string input_shape_str = FormatInputShapes(node->proto());
|
string input_shape_str = FormatInputShapes(node->proto());
|
||||||
if (!input_shape_str.empty()) {
|
if (!input_shape_str.empty()) {
|
||||||
node_str = strings::Printf("%s\n%s\n\n", node_str.c_str(),
|
node_str = absl::StrFormat("%s\n%s\n\n", node_str, input_shape_str);
|
||||||
input_shape_str.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return node_str;
|
return node_str;
|
||||||
|
|||||||
@ -16,11 +16,12 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
|
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/c/c_api.h"
|
#include "tensorflow/c/c_api.h"
|
||||||
#include "tensorflow/core/framework/tensor.h"
|
#include "tensorflow/core/framework/tensor.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
||||||
@ -80,7 +81,7 @@ void TFScope::Build() {
|
|||||||
const ShowNode* TFScope::ShowInternal(const Options& opts, Timeline* timeline) {
|
const ShowNode* TFScope::ShowInternal(const Options& opts, Timeline* timeline) {
|
||||||
root_->ResetTotalStats();
|
root_->ResetTotalStats();
|
||||||
if (opts.output_type == kOutput[3]) {
|
if (opts.output_type == kOutput[3]) {
|
||||||
fprintf(stderr, "Only 'code' view supports pprof output now.\n");
|
absl::FPrintF(stderr, "Only 'code' view supports pprof output now.\n");
|
||||||
return root_;
|
return root_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +172,8 @@ std::vector<ScopeNode*> TFScope::PrintScope(const std::vector<ScopeNode*> roots,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node->formatted_str =
|
node->formatted_str = absl::StrFormat(
|
||||||
strings::Printf("%s%s\n", string(last_ident, ' ').c_str(),
|
"%s%s\n", std::string(last_ident, ' '), FormatNode(node, opts));
|
||||||
FormatNode(node, opts).c_str());
|
|
||||||
|
|
||||||
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
if (opts.select.find(kShown[4]) != opts.select.end()) {
|
||||||
std::unique_ptr<TFProfTensor> tfprof_tensor;
|
std::unique_ptr<TFProfTensor> tfprof_tensor;
|
||||||
|
|||||||
@ -18,7 +18,8 @@ limitations under the License.
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_join.h"
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
|
|
||||||
@ -32,19 +33,19 @@ const GraphNodeProto& TFShow::Show(const string& prefix, const Options& opts) {
|
|||||||
} else {
|
} else {
|
||||||
const ShowNode* ret = ShowInternal(opts, nullptr);
|
const ShowNode* ret = ShowInternal(opts, nullptr);
|
||||||
if (opts.output_type == kOutput[1]) {
|
if (opts.output_type == kOutput[1]) {
|
||||||
printf("%s", (prefix + ret->formatted_str).c_str());
|
absl::PrintF("%s", (prefix + ret->formatted_str));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
} else if (opts.output_type == kOutput[2]) {
|
} else if (opts.output_type == kOutput[2]) {
|
||||||
Status s = WriteStringToFile(Env::Default(),
|
Status s = WriteStringToFile(Env::Default(),
|
||||||
opts.output_options.at(kFileOpts[0]),
|
opts.output_options.at(kFileOpts[0]),
|
||||||
prefix + ret->formatted_str);
|
prefix + ret->formatted_str);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "%s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "%s\n", s.ToString());
|
||||||
}
|
}
|
||||||
} else if (opts.output_type == kOutput[3] ||
|
} else if (opts.output_type == kOutput[3] ||
|
||||||
opts.output_type == kOutput[4]) {
|
opts.output_type == kOutput[4]) {
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown output type: %s\n", opts.output_type.c_str());
|
absl::FPrintF(stderr, "Unknown output type: %s\n", opts.output_type);
|
||||||
}
|
}
|
||||||
return ret->proto();
|
return ret->proto();
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ bool TFShow::LookUpCheckPoint(const string& name,
|
|||||||
TF_Status* status = TF_NewStatus();
|
TF_Status* status = TF_NewStatus();
|
||||||
ckpt_reader_->GetTensor(name, &out_tensor, status);
|
ckpt_reader_->GetTensor(name, &out_tensor, status);
|
||||||
if (TF_GetCode(status) != TF_OK) {
|
if (TF_GetCode(status) != TF_OK) {
|
||||||
fprintf(stderr, "%s\n", TF_Message(status));
|
absl::FPrintF(stderr, "%s\n", TF_Message(status));
|
||||||
TF_DeleteStatus(status);
|
TF_DeleteStatus(status);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -227,17 +228,16 @@ string TFShow::FormatNode(ShowNode* node, const Options& opts) const {
|
|||||||
std::vector<string> shape_vec;
|
std::vector<string> shape_vec;
|
||||||
for (const auto& s : node->node->input_shapes()) {
|
for (const auto& s : node->node->input_shapes()) {
|
||||||
if (s.second.empty()) {
|
if (s.second.empty()) {
|
||||||
shape_vec.push_back(strings::Printf("%d:unknown", s.first));
|
shape_vec.push_back(absl::StrFormat("%d:unknown", s.first));
|
||||||
} else {
|
} else {
|
||||||
shape_vec.push_back(strings::Printf(
|
shape_vec.push_back(
|
||||||
"%d:%s", s.first, absl::StrJoin(s.second, "x").c_str()));
|
absl::StrFormat("%d:%s", s.first, absl::StrJoin(s.second, "x")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.push_back(absl::StrJoin(shape_vec, "|"));
|
info.push_back(absl::StrJoin(shape_vec, "|"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings::Printf("%s (%s)", node->name().c_str(),
|
return absl::StrFormat("%s (%s)", node->name(), absl::StrJoin(info, ", "));
|
||||||
absl::StrJoin(info, ", ").c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string TFShow::FormatLegend(const Options& opts) const {
|
string TFShow::FormatLegend(const Options& opts) const {
|
||||||
@ -285,8 +285,7 @@ string TFShow::FormatLegend(const Options& opts) const {
|
|||||||
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
||||||
legends.push_back("input shapes");
|
legends.push_back("input shapes");
|
||||||
}
|
}
|
||||||
return strings::Printf("node name | %s\n",
|
return absl::StrFormat("node name | %s\n", absl::StrJoin(legends, " | "));
|
||||||
absl::StrJoin(legends, " | ").c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tfprof
|
} // namespace tfprof
|
||||||
|
|||||||
@ -25,7 +25,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/c/checkpoint_reader.h"
|
#include "tensorflow/c/checkpoint_reader.h"
|
||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
||||||
|
|||||||
@ -18,8 +18,8 @@ limitations under the License.
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
|
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
|
||||||
@ -35,19 +35,19 @@ const MultiGraphNodeProto& TFMultiShow::Show(const string& prefix,
|
|||||||
} else {
|
} else {
|
||||||
const ShowMultiNode* ret = ShowInternal(opts, nullptr);
|
const ShowMultiNode* ret = ShowInternal(opts, nullptr);
|
||||||
if (opts.output_type == kOutput[1]) {
|
if (opts.output_type == kOutput[1]) {
|
||||||
printf("%s", (prefix + ret->formatted_str).c_str());
|
absl::PrintF("%s%s", prefix, ret->formatted_str);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
} else if (opts.output_type == kOutput[2]) {
|
} else if (opts.output_type == kOutput[2]) {
|
||||||
Status s = WriteStringToFile(Env::Default(),
|
Status s = WriteStringToFile(Env::Default(),
|
||||||
opts.output_options.at(kFileOpts[0]),
|
opts.output_options.at(kFileOpts[0]),
|
||||||
prefix + ret->formatted_str);
|
prefix + ret->formatted_str);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "%s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "%s\n", s.ToString());
|
||||||
}
|
}
|
||||||
} else if (opts.output_type == kOutput[3] ||
|
} else if (opts.output_type == kOutput[3] ||
|
||||||
opts.output_type == kOutput[4]) {
|
opts.output_type == kOutput[4]) {
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown output type: %s\n", opts.output_type.c_str());
|
absl::FPrintF(stderr, "Unknown output type: %s\n", opts.output_type);
|
||||||
}
|
}
|
||||||
return ret->proto();
|
return ret->proto();
|
||||||
}
|
}
|
||||||
@ -158,8 +158,7 @@ string TFMultiShow::FormatLegend(const Options& opts) const {
|
|||||||
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
if (opts.select.find(kShown[8]) != opts.select.end()) {
|
||||||
legends.push_back("input shapes");
|
legends.push_back("input shapes");
|
||||||
}
|
}
|
||||||
return strings::Printf("node name | %s\n",
|
return absl::StrFormat("node name | %s\n", absl::StrJoin(legends, " | "));
|
||||||
absl::StrJoin(legends, " | ").c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
|
string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
|
||||||
@ -176,14 +175,14 @@ string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
|
|||||||
std::vector<string> input_vec;
|
std::vector<string> input_vec;
|
||||||
for (const auto& s : input_shapes) {
|
for (const auto& s : input_shapes) {
|
||||||
if (s.second.empty()) {
|
if (s.second.empty()) {
|
||||||
input_vec.push_back(strings::Printf("%d:unknown", s.first));
|
input_vec.push_back(absl::StrFormat("%d:unknown", s.first));
|
||||||
} else {
|
} else {
|
||||||
input_vec.push_back(strings::Printf(
|
input_vec.push_back(
|
||||||
"%d:%s", s.first, absl::StrJoin(s.second, "x").c_str()));
|
absl::StrFormat("%d:%s", s.first, absl::StrJoin(s.second, "x")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string shape_type_str = strings::Printf(
|
string shape_type_str =
|
||||||
"input_type: %s", absl::StrJoin(input_vec, ",\t").c_str());
|
absl::StrFormat("input_type: %s", absl::StrJoin(input_vec, ",\t"));
|
||||||
auto t = input_shapes_attr.find(shape_type_str);
|
auto t = input_shapes_attr.find(shape_type_str);
|
||||||
if (t == input_shapes_attr.end()) {
|
if (t == input_shapes_attr.end()) {
|
||||||
input_shapes_attr.insert(
|
input_shapes_attr.insert(
|
||||||
@ -211,9 +210,9 @@ string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
|
|||||||
input_types.reserve(shape_count_vec.size());
|
input_types.reserve(shape_count_vec.size());
|
||||||
for (const auto& s : shape_count_vec) {
|
for (const auto& s : shape_count_vec) {
|
||||||
std::tuple<int64, int64, int64> t = s.second;
|
std::tuple<int64, int64, int64> t = s.second;
|
||||||
input_types.push_back(strings::Printf(
|
input_types.push_back(absl::StrFormat(
|
||||||
"%s\t(run*%lld|defined*%lld)\texec_time: %s", s.first.c_str(),
|
"%s\t(run*%d|defined*%d)\texec_time: %s", s.first, std::get<1>(t),
|
||||||
std::get<1>(t), std::get<0>(t), FormatTime(std::get<2>(t)).c_str()));
|
std::get<0>(t), FormatTime(std::get<2>(t))));
|
||||||
}
|
}
|
||||||
return absl::StrJoin(input_types, "\n");
|
return absl::StrJoin(input_types, "\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/c/checkpoint_reader.h"
|
#include "tensorflow/c/checkpoint_reader.h"
|
||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
#include "tensorflow/core/profiler/internal/tfprof_constants.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
||||||
@ -45,8 +44,7 @@ class TFMultiShow {
|
|||||||
virtual ~TFMultiShow() {}
|
virtual ~TFMultiShow() {}
|
||||||
virtual void AddNode(TFGraphNode* node) = 0;
|
virtual void AddNode(TFGraphNode* node) = 0;
|
||||||
virtual void Build() = 0;
|
virtual void Build() = 0;
|
||||||
virtual const MultiGraphNodeProto& Show(const string& prefix,
|
const MultiGraphNodeProto& Show(const string& prefix, const Options& opts);
|
||||||
const Options& opts) final;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const ShowMultiNode* ShowInternal(const Options& opts,
|
virtual const ShowMultiNode* ShowInternal(const Options& opts,
|
||||||
|
|||||||
@ -16,10 +16,13 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
|
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/numbers.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_split.h"
|
||||||
#include "tensorflow/core/framework/step_stats.pb.h"
|
#include "tensorflow/core/framework/step_stats.pb.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_timeline.h"
|
#include "tensorflow/core/profiler/internal/tfprof_timeline.h"
|
||||||
|
|
||||||
@ -55,7 +58,7 @@ TFStats::TFStats(std::unique_ptr<GraphDef> graph,
|
|||||||
ckpt_reader_(std::move(ckpt_reader)) {
|
ckpt_reader_(std::move(ckpt_reader)) {
|
||||||
CHECK(graph) << "Must at least have GraphDef";
|
CHECK(graph) << "Must at least have GraphDef";
|
||||||
|
|
||||||
printf("Parsing Inputs...\n");
|
absl::PrintF("Parsing Inputs...\n");
|
||||||
AddGraph(std::move(graph));
|
AddGraph(std::move(graph));
|
||||||
if (run_meta && run_meta->has_step_stats()) {
|
if (run_meta && run_meta->has_step_stats()) {
|
||||||
AddRunMeta(0, std::move(run_meta));
|
AddRunMeta(0, std::move(run_meta));
|
||||||
@ -80,13 +83,13 @@ TFStats::TFStats(const string& filename,
|
|||||||
string str;
|
string str;
|
||||||
Status s = ReadFileToString(Env::Default(), filename, &str);
|
Status s = ReadFileToString(Env::Default(), filename, &str);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "Failed to read profile: %s", s.ToString().c_str());
|
absl::FPrintF(stderr, "Failed to read profile: %s", s.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileProto profile;
|
ProfileProto profile;
|
||||||
if (!profile.ParseFromString(str)) {
|
if (!profile.ParseFromString(str)) {
|
||||||
fprintf(stderr, "Failed to parse profile\n");
|
absl::FPrintF(stderr, "Failed to parse profile\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const auto& entry : profile.id_to_string()) {
|
for (const auto& entry : profile.id_to_string()) {
|
||||||
@ -163,7 +166,7 @@ const GraphNodeProto& TFStats::ShowGraphNode(const string& cmd,
|
|||||||
}
|
}
|
||||||
return graph_view_->Show(prefix, opts);
|
return graph_view_->Show(prefix, opts);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown command: %s\n", cmd.c_str());
|
absl::FPrintF(stderr, "Unknown command: %s\n", cmd);
|
||||||
return empty_graph_node_;
|
return empty_graph_node_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,14 +181,14 @@ const MultiGraphNodeProto& TFStats::ShowMultiGraphNode(
|
|||||||
|
|
||||||
if (cmd == kCmds[2]) {
|
if (cmd == kCmds[2]) {
|
||||||
if (!has_code_traces()) {
|
if (!has_code_traces()) {
|
||||||
fprintf(stderr, "No code trace information\n");
|
absl::FPrintF(stderr, "No code trace information\n");
|
||||||
return empty_multi_graph_node_;
|
return empty_multi_graph_node_;
|
||||||
}
|
}
|
||||||
return code_view_->Show(prefix, opts);
|
return code_view_->Show(prefix, opts);
|
||||||
} else if (cmd == kCmds[3]) {
|
} else if (cmd == kCmds[3]) {
|
||||||
return op_view_->Show(prefix, opts);
|
return op_view_->Show(prefix, opts);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown command: %s\n", cmd.c_str());
|
absl::FPrintF(stderr, "Unknown command: %s\n", cmd);
|
||||||
return empty_multi_graph_node_;
|
return empty_multi_graph_node_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,11 +215,11 @@ void TFStats::AddGraph(std::unique_ptr<GraphDef> graph) {
|
|||||||
// if not :src_output, then it's the first one (further verify?)
|
// if not :src_output, then it's the first one (further verify?)
|
||||||
auto prefix_pos = node_input.find(":");
|
auto prefix_pos = node_input.find(":");
|
||||||
if (prefix_pos != node_input.npos) {
|
if (prefix_pos != node_input.npos) {
|
||||||
std::vector<string> input_parts = str_util::Split(node_input, ":");
|
std::vector<string> input_parts = absl::StrSplit(node_input, ':');
|
||||||
CHECK(input_parts.size() == 2)
|
DCHECK(input_parts.size() == 2)
|
||||||
<< "Unknown NodeDef.input format: " << node_input;
|
<< "Unknown NodeDef.input format: " << node_input;
|
||||||
node_input = input_parts[0];
|
node_input = input_parts[0];
|
||||||
CHECK(strings::safe_strto32(input_parts[1], &output_idx))
|
DCHECK(absl::SimpleAtoi(input_parts[1], &output_idx))
|
||||||
<< "Failed to parse integer: " << output_idx;
|
<< "Failed to parse integer: " << output_idx;
|
||||||
}
|
}
|
||||||
if (node_input.substr(0, 1) == "^") {
|
if (node_input.substr(0, 1) == "^") {
|
||||||
@ -263,7 +266,7 @@ void TFStats::AddOpLogProto(std::unique_ptr<OpLogProto> op_log) {
|
|||||||
|
|
||||||
void TFStats::AddRunMeta(int64 step, std::unique_ptr<RunMetadata> run_meta) {
|
void TFStats::AddRunMeta(int64 step, std::unique_ptr<RunMetadata> run_meta) {
|
||||||
if (!run_meta || !run_meta->has_step_stats()) {
|
if (!run_meta || !run_meta->has_step_stats()) {
|
||||||
fprintf(stderr, "Invalid RunMetadata for step %lld\n", step);
|
absl::FPrintF(stderr, "Invalid RunMetadata for step %d\n", step);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (steps_.find(step) == steps_.end()) {
|
if (steps_.find(step) == steps_.end()) {
|
||||||
@ -349,18 +352,18 @@ void TFStats::WriteProfile(const string& filename) {
|
|||||||
SerializeToString(&content);
|
SerializeToString(&content);
|
||||||
Status s = WriteStringToFile(Env::Default(), filename, content);
|
Status s = WriteStringToFile(Env::Default(), filename, content);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "%s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "%s\n", s.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TFStats::Validate(const Options& opts) const {
|
bool TFStats::Validate(const Options& opts) const {
|
||||||
if (opts.step >= 0 && steps_.find(opts.step) == steps_.end()) {
|
if (opts.step >= 0 && steps_.find(opts.step) == steps_.end()) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"Options -step=%lld not found.\nAvailable steps: ", opts.step);
|
"Options -step=%d not found.\nAvailable steps: ", opts.step);
|
||||||
for (int64 s : steps_) {
|
for (int64 s : steps_) {
|
||||||
fprintf(stderr, "%lld ", s);
|
absl::FPrintF(stderr, "%d ", s);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
absl::FPrintF(stderr, "\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -33,7 +33,6 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/framework/step_stats.pb.h"
|
#include "tensorflow/core/framework/step_stats.pb.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_code.h"
|
#include "tensorflow/core/profiler/internal/tfprof_code.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_graph.h"
|
#include "tensorflow/core/profiler/internal/tfprof_graph.h"
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node.h"
|
||||||
|
|||||||
@ -15,6 +15,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
|
||||||
|
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
namespace tfprof {
|
namespace tfprof {
|
||||||
void TFProfTensor::Display(string* formatted_str,
|
void TFProfTensor::Display(string* formatted_str,
|
||||||
@ -22,7 +25,7 @@ void TFProfTensor::Display(string* formatted_str,
|
|||||||
if (formatted_str) {
|
if (formatted_str) {
|
||||||
if (formatted_str_.length() >= kTFProfTenosrMaxDisplayLen) {
|
if (formatted_str_.length() >= kTFProfTenosrMaxDisplayLen) {
|
||||||
*formatted_str =
|
*formatted_str =
|
||||||
strings::StrCat(formatted_str_, "...omitted from display\n\n");
|
absl::StrCat(formatted_str_, "...omitted from display\n\n");
|
||||||
} else {
|
} else {
|
||||||
*formatted_str = formatted_str_;
|
*formatted_str = formatted_str_;
|
||||||
}
|
}
|
||||||
@ -68,7 +71,7 @@ void TFProfTensor::Build() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
fprintf(stderr, "Not Supported type %d\n", tensor_->dtype());
|
absl::FPrintF(stderr, "Not Supported type %d\n", tensor_->dtype());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,10 +24,10 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include "absl/strings/numbers.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/framework/tensor.h"
|
#include "tensorflow/core/framework/tensor.h"
|
||||||
#include "tensorflow/core/lib/strings/numbers.h"
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/tfprof_output.pb.h"
|
#include "tensorflow/core/profiler/tfprof_output.pb.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -56,23 +56,21 @@ class TFProfTensor {
|
|||||||
std::ostringstream sstream;
|
std::ostringstream sstream;
|
||||||
sstream << value;
|
sstream << value;
|
||||||
if (typeid(value) == typeid(double)) {
|
if (typeid(value) == typeid(double)) {
|
||||||
double double_val;
|
double double_val = 0.0;
|
||||||
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
|
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
|
||||||
dim->add_value_double(double_val);
|
dim->add_value_double(double_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(&formatted_str_, "%.2f ",
|
||||||
"%.2f ", dim->value_double(dim->value_double_size() - 1));
|
dim->value_double(dim->value_double_size() - 1));
|
||||||
} else if (typeid(value) == typeid(int64)) {
|
} else if (typeid(value) == typeid(int64)) {
|
||||||
int64 int64_val;
|
int64 int64_val = 0;
|
||||||
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
|
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
|
||||||
dim->add_value_int64(int64_val);
|
dim->add_value_int64(int64_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(&formatted_str_, "%d ",
|
||||||
"%lld ",
|
dim->value_int64(dim->value_int64_size() - 1));
|
||||||
static_cast<int64>(dim->value_int64(dim->value_int64_size() - 1)));
|
|
||||||
} else if (typeid(value) == typeid(string)) {
|
} else if (typeid(value) == typeid(string)) {
|
||||||
dim->add_value_str(sstream.str());
|
dim->add_value_str(sstream.str());
|
||||||
formatted_str_ =
|
absl::StrAppend(&formatted_str_, "'",
|
||||||
strings::StrCat(formatted_str_, "'",
|
dim->value_str(dim->value_str_size() - 1), "' ");
|
||||||
dim->value_str(dim->value_str_size() - 1) + "' ");
|
|
||||||
} else {
|
} else {
|
||||||
CHECK(false) << "Unsupported type: " << typeid(value).name();
|
CHECK(false) << "Unsupported type: " << typeid(value).name();
|
||||||
}
|
}
|
||||||
@ -91,23 +89,21 @@ class TFProfTensor {
|
|||||||
sstream << values[nstart];
|
sstream << values[nstart];
|
||||||
|
|
||||||
if (typeid(values[nstart]) == typeid(double)) {
|
if (typeid(values[nstart]) == typeid(double)) {
|
||||||
double double_val;
|
double double_val = 0.0;
|
||||||
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
|
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
|
||||||
dim->add_value_double(double_val);
|
dim->add_value_double(double_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(&formatted_str_, "%.2f ",
|
||||||
"%.2f ", dim->value_double(dim->value_double_size() - 1));
|
dim->value_double(dim->value_double_size() - 1));
|
||||||
} else if (typeid(values[nstart]) == typeid(int64)) {
|
} else if (typeid(values[nstart]) == typeid(int64)) {
|
||||||
int64 int64_val;
|
int64 int64_val = 0;
|
||||||
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
|
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
|
||||||
dim->add_value_int64(int64_val);
|
dim->add_value_int64(int64_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(&formatted_str_, "%d ",
|
||||||
"%lld ",
|
dim->value_int64(dim->value_int64_size() - 1));
|
||||||
static_cast<int64>(dim->value_int64(dim->value_int64_size() - 1)));
|
|
||||||
} else if (typeid(values[nstart]) == typeid(string)) {
|
} else if (typeid(values[nstart]) == typeid(string)) {
|
||||||
dim->add_value_str(sstream.str());
|
dim->add_value_str(sstream.str());
|
||||||
formatted_str_ =
|
absl::StrAppend(&formatted_str_, "'",
|
||||||
strings::StrCat(formatted_str_, "'",
|
dim->value_str(dim->value_str_size() - 1), "' ");
|
||||||
dim->value_str(dim->value_str_size() - 1) + "' ");
|
|
||||||
} else {
|
} else {
|
||||||
CHECK(false) << "Unsupported type: " << typeid(values[nstart]).name();
|
CHECK(false) << "Unsupported type: " << typeid(values[nstart]).name();
|
||||||
}
|
}
|
||||||
@ -119,23 +115,23 @@ class TFProfTensor {
|
|||||||
sstream << values[nstart];
|
sstream << values[nstart];
|
||||||
|
|
||||||
if (typeid(values[nstart]) == typeid(double)) {
|
if (typeid(values[nstart]) == typeid(double)) {
|
||||||
double double_val;
|
double double_val = 0.0;
|
||||||
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
|
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
|
||||||
dim->add_value_double(double_val);
|
dim->add_value_double(double_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(
|
||||||
"%.2f ", dim->value_double(dim->value_double_size() - 1));
|
&formatted_str_, "%.2f ",
|
||||||
|
dim->value_double(dim->value_double_size() - 1));
|
||||||
} else if (typeid(values[nstart]) == typeid(int64)) {
|
} else if (typeid(values[nstart]) == typeid(int64)) {
|
||||||
int64 int64_val;
|
int64 int64_val = 0;
|
||||||
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
|
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
|
||||||
dim->add_value_int64(int64_val);
|
dim->add_value_int64(int64_val);
|
||||||
formatted_str_ += strings::Printf(
|
absl::StrAppendFormat(
|
||||||
"%lld ", static_cast<int64>(
|
&formatted_str_, "%d ",
|
||||||
dim->value_int64(dim->value_int64_size() - 1)));
|
dim->value_int64(dim->value_int64_size() - 1));
|
||||||
} else if (typeid(values[nstart]) == typeid(string)) {
|
} else if (typeid(values[nstart]) == typeid(string)) {
|
||||||
dim->add_value_str(sstream.str());
|
dim->add_value_str(sstream.str());
|
||||||
formatted_str_ = strings::StrCat(
|
absl::StrAppend(&formatted_str_, "'",
|
||||||
formatted_str_, "'",
|
dim->value_str(dim->value_str_size() - 1), "' ");
|
||||||
dim->value_str(dim->value_str_size() - 1) + "' ");
|
|
||||||
} else {
|
} else {
|
||||||
CHECK(false) << "Unsupported type: "
|
CHECK(false) << "Unsupported type: "
|
||||||
<< typeid(values[nstart]).name();
|
<< typeid(values[nstart]).name();
|
||||||
@ -158,7 +154,7 @@ class TFProfTensor {
|
|||||||
void GetValueVec(std::vector<U>* value_vec) {
|
void GetValueVec(std::vector<U>* value_vec) {
|
||||||
// TODO(xpan): Address the huge tensor problem.
|
// TODO(xpan): Address the huge tensor problem.
|
||||||
if (tensor_->NumElements() > kTFProfTensorMaxWarnLen) {
|
if (tensor_->NumElements() > kTFProfTensorMaxWarnLen) {
|
||||||
fprintf(stderr, "Showing huge tensor, the tool might halt...\n");
|
absl::FPrintF(stderr, "Showing huge tensor, the tool might halt...\n");
|
||||||
}
|
}
|
||||||
auto values = tensor_->flat<T>();
|
auto values = tensor_->flat<T>();
|
||||||
for (int64 i = 0; i < tensor_->NumElements(); i++) {
|
for (int64 i = 0; i < tensor_->NumElements(); i++) {
|
||||||
|
|||||||
@ -17,9 +17,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "tensorflow/core/lib/core/status.h"
|
#include "tensorflow/core/lib/core/status.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
|
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -27,15 +27,15 @@ namespace tfprof {
|
|||||||
namespace {
|
namespace {
|
||||||
int kMaxDisplayedMemNode = 10;
|
int kMaxDisplayedMemNode = 10;
|
||||||
|
|
||||||
string GetTimeDevName(const string& dev) {
|
std::string GetTimeDevName(const std::string& dev) {
|
||||||
if (dev.find("stream") != dev.npos) {
|
if (dev.find("stream") != dev.npos) {
|
||||||
return strings::StrCat("Op execution threads: ", dev);
|
return absl::StrCat("Op execution threads: ", dev);
|
||||||
} else {
|
} else {
|
||||||
return strings::StrCat("Op scheduling threads: ", dev);
|
return absl::StrCat("Op scheduling threads: ", dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string GetMemoryLaneName(const string& dev) {
|
std::string GetMemoryLaneName(const std::string& dev) {
|
||||||
return strings::StrCat("mem usage on:", dev);
|
return absl::StrCat("mem usage on:", dev);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ void ChromeTraceFormatter::EmitCounter(
|
|||||||
Json::Value args2(Json::objectValue);
|
Json::Value args2(Json::objectValue);
|
||||||
// Need to reserve the same args for all locations.
|
// Need to reserve the same args for all locations.
|
||||||
for (int i = 1; i < kMaxDisplayedMemNode; ++i) {
|
for (int i = 1; i < kMaxDisplayedMemNode; ++i) {
|
||||||
args2[strings::Printf("Top Allocation %02d", i)] = Json::Value("N/A");
|
args2[absl::StrFormat("Top Allocation %02d", i)] = Json::Value("N/A");
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (auto it = tensor_mem.rbegin(); it != tensor_mem.rend(); ++it) {
|
for (auto it = tensor_mem.rbegin(); it != tensor_mem.rend(); ++it) {
|
||||||
@ -112,14 +112,14 @@ void ChromeTraceFormatter::EmitCounter(
|
|||||||
if (bytes < it->first || count >= kMaxDisplayedMemNode) {
|
if (bytes < it->first || count >= kMaxDisplayedMemNode) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
args2[strings::Printf("Top Allocation %02d", count)] =
|
args2[absl::StrFormat("Top Allocation %02d", count)] =
|
||||||
Json::Value(strings::StrCat(it->first / 1000000.0, " MB from ", t));
|
Json::Value(absl::StrCat(it->first / 1000000.0, " MB from ", t));
|
||||||
++count;
|
++count;
|
||||||
bytes -= it->first;
|
bytes -= it->first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args2[strings::StrCat("Not Displayed")] =
|
args2[std::string("Not Displayed")] =
|
||||||
Json::Value(strings::Printf("%.2f MB", bytes / 1000000.0));
|
Json::Value(absl::StrFormat("%.2f MB", bytes / 1000000.0));
|
||||||
event2["args"] = args2;
|
event2["args"] = args2;
|
||||||
events_.push_back(event2);
|
events_.push_back(event2);
|
||||||
}
|
}
|
||||||
@ -136,10 +136,10 @@ string ChromeTraceFormatter::Format() {
|
|||||||
Json::FastWriter writer;
|
Json::FastWriter writer;
|
||||||
string trace_str = writer.write(trace);
|
string trace_str = writer.write(trace);
|
||||||
if (trace_str.length() > 200 * 1024 * 1024) {
|
if (trace_str.length() > 200 * 1024 * 1024) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"Trace file is over 200MB. Chrome might not be able to "
|
"Trace file is over 200MB. Chrome might not be able to "
|
||||||
"display it. Consider to use filters (e.g. -min_micros "
|
"display it. Consider to use filters (e.g. -min_micros "
|
||||||
"> 1000 or -op_type .*gpu:0.* to reduce the size.\n");
|
"> 1000 or -op_type .*gpu:0.* to reduce the size.\n");
|
||||||
}
|
}
|
||||||
return trace_str;
|
return trace_str;
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ void Timeline::GenerateGraphTimeline(const std::vector<GraphNode*>& gnodes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AllocateLanes();
|
AllocateLanes();
|
||||||
fprintf(stdout, "generating trace file.\n");
|
absl::FPrintF(stdout, "generating trace file.\n");
|
||||||
int64 flow_id = 1;
|
int64 flow_id = 1;
|
||||||
for (const auto& process : alloc_nodes_) {
|
for (const auto& process : alloc_nodes_) {
|
||||||
for (const auto& lane : process.second) {
|
for (const auto& lane : process.second) {
|
||||||
@ -301,8 +301,8 @@ void Timeline::GenerateGraphTimeline(const std::vector<GraphNode*>& gnodes) {
|
|||||||
dev.first, cur_bytes_in_use, tensor_mem);
|
dev.first, cur_bytes_in_use, tensor_mem);
|
||||||
}
|
}
|
||||||
if (IsPlacedOnAccelerator(dev.first)) {
|
if (IsPlacedOnAccelerator(dev.first)) {
|
||||||
fprintf(stdout, "%s peak memory: %.2f MB\n", dev.first.c_str(),
|
absl::FPrintF(stdout, "%s peak memory: %.2f MB\n", dev.first,
|
||||||
max_bytes_in_use / 1000000.0);
|
max_bytes_in_use / 1000000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OutputTimeline();
|
OutputTimeline();
|
||||||
@ -321,21 +321,23 @@ void Timeline::GenerateCodeTimeline(const CodeNode* node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Timeline::OutputTimeline() {
|
void Timeline::OutputTimeline() {
|
||||||
string outfile = strings::Printf("%s_%lld", outfile_.c_str(), step());
|
std::string outfile = absl::StrFormat("%s_%d", outfile_, step());
|
||||||
Status s =
|
Status s =
|
||||||
WriteStringToFile(Env::Default(), outfile, chrome_formatter_.Format());
|
WriteStringToFile(Env::Default(), outfile, chrome_formatter_.Format());
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "Failed to write timeline file: %s\nError: %s\n",
|
absl::FPrintF(stderr, "Failed to write timeline file: %s\nError: %s\n",
|
||||||
outfile.c_str(), s.ToString().c_str());
|
outfile, s.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "\n******************************************************\n");
|
absl::FPrintF(stdout,
|
||||||
fprintf(stdout,
|
"\n******************************************************\n");
|
||||||
"Timeline file is written to %s.\n"
|
absl::FPrintF(stdout,
|
||||||
"Open a Chrome browser, enter URL chrome://tracing and "
|
"Timeline file is written to %s.\n"
|
||||||
"load the timeline file.",
|
"Open a Chrome browser, enter URL chrome://tracing and "
|
||||||
outfile.c_str());
|
"load the timeline file.",
|
||||||
fprintf(stdout, "\n******************************************************\n");
|
outfile);
|
||||||
|
absl::FPrintF(stdout,
|
||||||
|
"\n******************************************************\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,10 @@ limitations under the License.
|
|||||||
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_TIMELINE_H_
|
#ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_TIMELINE_H_
|
||||||
#define TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_TIMELINE_H_
|
#define TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_TIMELINE_H_
|
||||||
|
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include "include/json/json.h"
|
#include "include/json/json.h"
|
||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/framework/step_stats.pb.h"
|
#include "tensorflow/core/framework/step_stats.pb.h"
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
|
||||||
#include "tensorflow/core/protobuf/config.pb.h"
|
#include "tensorflow/core/protobuf/config.pb.h"
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ class Timeline {
|
|||||||
void EmitTreeNode(const Node* node, int64 start_time, int64 duration,
|
void EmitTreeNode(const Node* node, int64 start_time, int64 duration,
|
||||||
int64 depth, std::set<int64>* visited_depth) {
|
int64 depth, std::set<int64>* visited_depth) {
|
||||||
if (visited_depth->find(depth) == visited_depth->end()) {
|
if (visited_depth->find(depth) == visited_depth->end()) {
|
||||||
chrome_formatter_.EmitPID(strings::StrCat("Scope:", depth), depth);
|
chrome_formatter_.EmitPID(absl::StrCat("Scope:", depth), depth);
|
||||||
visited_depth->insert(depth);
|
visited_depth->insert(depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,16 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
|
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "tensorflow/core/lib/strings/numbers.h"
|
#include "absl/strings/match.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
#include "absl/strings/numbers.h"
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_split.h"
|
||||||
#include "tensorflow/core/platform/protobuf.h"
|
#include "tensorflow/core/platform/protobuf.h"
|
||||||
#include "tensorflow/core/platform/regexp.h"
|
#include "tensorflow/core/platform/regexp.h"
|
||||||
|
|
||||||
@ -31,33 +33,33 @@ namespace tensorflow {
|
|||||||
namespace tfprof {
|
namespace tfprof {
|
||||||
string FormatNumber(int64 n) {
|
string FormatNumber(int64 n) {
|
||||||
if (n < 1000) {
|
if (n < 1000) {
|
||||||
return strings::Printf("%lld", n);
|
return absl::StrFormat("%d", n);
|
||||||
} else if (n < 1000000) {
|
} else if (n < 1000000) {
|
||||||
return strings::Printf("%.2fk", n / 1000.0);
|
return absl::StrFormat("%.2fk", n / 1000.0);
|
||||||
} else if (n < 1000000000) {
|
} else if (n < 1000000000) {
|
||||||
return strings::Printf("%.2fm", n / 1000000.0);
|
return absl::StrFormat("%.2fm", n / 1000000.0);
|
||||||
} else {
|
} else {
|
||||||
return strings::Printf("%.2fb", n / 1000000000.0);
|
return absl::StrFormat("%.2fb", n / 1000000000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string FormatTime(int64 micros) {
|
string FormatTime(int64 micros) {
|
||||||
if (micros < 1000) {
|
if (micros < 1000) {
|
||||||
return strings::Printf("%lldus", micros);
|
return absl::StrFormat("%dus", micros);
|
||||||
} else if (micros < 1000000) {
|
} else if (micros < 1000000) {
|
||||||
return strings::Printf("%.2fms", micros / 1000.0);
|
return absl::StrFormat("%.2fms", micros / 1000.0);
|
||||||
} else {
|
} else {
|
||||||
return strings::Printf("%.2fsec", micros / 1000000.0);
|
return absl::StrFormat("%.2fsec", micros / 1000000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string FormatMemory(int64 bytes) {
|
string FormatMemory(int64 bytes) {
|
||||||
if (bytes < 1000) {
|
if (bytes < 1000) {
|
||||||
return strings::Printf("%lldB", bytes);
|
return absl::StrFormat("%dB", bytes);
|
||||||
} else if (bytes < 1000000) {
|
} else if (bytes < 1000000) {
|
||||||
return strings::Printf("%.2fKB", bytes / 1000.0);
|
return absl::StrFormat("%.2fKB", bytes / 1000.0);
|
||||||
} else {
|
} else {
|
||||||
return strings::Printf("%.2fMB", bytes / 1000000.0);
|
return absl::StrFormat("%.2fMB", bytes / 1000000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ tensorflow::Status ReturnError(const std::vector<string>& pieces, int idx) {
|
|||||||
}
|
}
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
strings::StrCat("Invalid option '", pieces[idx], "' value: '", val, "'"));
|
absl::StrCat("Invalid option '", pieces[idx], "' value: '", val, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CaseEqual(StringPiece s1, StringPiece s2) {
|
bool CaseEqual(StringPiece s1, StringPiece s2) {
|
||||||
@ -114,8 +116,7 @@ bool StringToBool(StringPiece str, bool* value) {
|
|||||||
|
|
||||||
tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
||||||
tensorflow::tfprof::Options* opts) {
|
tensorflow::tfprof::Options* opts) {
|
||||||
std::vector<string> pieces =
|
std::vector<string> pieces = absl::StrSplit(line, ' ', absl::SkipEmpty());
|
||||||
str_util::Split(line, ' ', str_util::SkipEmpty());
|
|
||||||
|
|
||||||
std::vector<string> cmds_str(kCmds, kCmds + sizeof(kCmds) / sizeof(*kCmds));
|
std::vector<string> cmds_str(kCmds, kCmds + sizeof(kCmds) / sizeof(*kCmds));
|
||||||
if (std::find(cmds_str.begin(), cmds_str.end(), pieces[0]) ==
|
if (std::find(cmds_str.begin(), cmds_str.end(), pieces[0]) ==
|
||||||
@ -128,74 +129,73 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
|||||||
for (int i = 1; i < pieces.size(); ++i) {
|
for (int i = 1; i < pieces.size(); ++i) {
|
||||||
if (pieces[i] == string(tensorflow::tfprof::kOptions[0])) {
|
if (pieces[i] == string(tensorflow::tfprof::kOptions[0])) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto32(pieces[i + 1], &opts->max_depth)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->max_depth)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[1]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[1]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_bytes)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_bytes)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[2]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[2]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_peak_bytes)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_peak_bytes)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[3]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[3]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_residual_bytes)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_residual_bytes)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[4]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[4]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_output_bytes)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_output_bytes)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[5]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[5]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_micros)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_micros)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[6]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[6]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1],
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_accelerator_micros)) {
|
||||||
&opts->min_accelerator_micros)) {
|
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[7]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[7]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_cpu_micros)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_cpu_micros)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[8]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[8]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_params)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_params)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[9]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[9]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_float_ops)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_float_ops)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[10]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[10]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->min_occurrence)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->min_occurrence)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[11]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[11]) {
|
||||||
if (pieces.size() <= i + 1 ||
|
if (pieces.size() <= i + 1 ||
|
||||||
!strings::safe_strto64(pieces[i + 1], &opts->step)) {
|
!absl::SimpleAtoi(pieces[i + 1], &opts->step)) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
@ -215,39 +215,39 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
|||||||
if (pieces.size() <= i + 1) {
|
if (pieces.size() <= i + 1) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
opts->account_type_regexes = str_util::Split(StripQuote(pieces[i + 1]),
|
opts->account_type_regexes =
|
||||||
',', str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[14]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[14]) {
|
||||||
if (pieces.size() <= i + 1) {
|
if (pieces.size() <= i + 1) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
opts->start_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
|
opts->start_name_regexes =
|
||||||
str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[15]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[15]) {
|
||||||
if (pieces.size() <= i + 1) {
|
if (pieces.size() <= i + 1) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
opts->trim_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
|
opts->trim_name_regexes =
|
||||||
str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[16]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[16]) {
|
||||||
if (pieces.size() <= i + 1) {
|
if (pieces.size() <= i + 1) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
opts->show_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
|
opts->show_name_regexes =
|
||||||
str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[17]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[17]) {
|
||||||
if (pieces.size() <= i + 1) {
|
if (pieces.size() <= i + 1) {
|
||||||
return ReturnError(pieces, i);
|
return ReturnError(pieces, i);
|
||||||
}
|
}
|
||||||
opts->hide_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
|
opts->hide_name_regexes =
|
||||||
str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
++i;
|
++i;
|
||||||
} else if (pieces[i] == tensorflow::tfprof::kOptions[18]) {
|
} else if (pieces[i] == tensorflow::tfprof::kOptions[18]) {
|
||||||
if ((pieces.size() > i + 1 && pieces[i + 1].find("-") == 0) ||
|
if ((pieces.size() > i + 1 && absl::StartsWith(pieces[i + 1], "-")) ||
|
||||||
pieces.size() == i + 1) {
|
pieces.size() == i + 1) {
|
||||||
opts->account_displayed_op_only = true;
|
opts->account_displayed_op_only = true;
|
||||||
} else if (!StringToBool(pieces[i + 1],
|
} else if (!StringToBool(pieces[i + 1],
|
||||||
@ -262,8 +262,8 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
|||||||
}
|
}
|
||||||
std::set<string> shown_set(kShown,
|
std::set<string> shown_set(kShown,
|
||||||
kShown + sizeof(kShown) / sizeof(*kShown));
|
kShown + sizeof(kShown) / sizeof(*kShown));
|
||||||
std::vector<string> requested_vector = str_util::Split(
|
std::vector<string> requested_vector =
|
||||||
StripQuote(pieces[i + 1]), ',', str_util::SkipEmpty());
|
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
|
||||||
std::set<string> requested_set(requested_vector.begin(),
|
std::set<string> requested_set(requested_vector.begin(),
|
||||||
requested_vector.end());
|
requested_vector.end());
|
||||||
for (const string& requested : requested_set) {
|
for (const string& requested : requested_set) {
|
||||||
@ -290,13 +290,13 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintHelp() {
|
void PrintHelp() {
|
||||||
printf(
|
absl::PrintF(
|
||||||
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
|
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
|
||||||
"README.md for profiler tutorial.\n");
|
"README.md for profiler tutorial.\n");
|
||||||
printf(
|
absl::PrintF(
|
||||||
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
|
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
|
||||||
"g3doc/command_line.md for command line tool tutorial.\n");
|
"g3doc/command_line.md for command line tool tutorial.\n");
|
||||||
printf(
|
absl::PrintF(
|
||||||
"profiler --profile_path=<ProfileProto binary file> # required\n"
|
"profiler --profile_path=<ProfileProto binary file> # required\n"
|
||||||
"\nOr:\n\n"
|
"\nOr:\n\n"
|
||||||
"profiler --graph_path=<GraphDef proto file> "
|
"profiler --graph_path=<GraphDef proto file> "
|
||||||
@ -305,7 +305,7 @@ void PrintHelp() {
|
|||||||
"# Contains runtime info. Optional.\n"
|
"# Contains runtime info. Optional.\n"
|
||||||
" --run_log_path=<OpLogProto proto file> "
|
" --run_log_path=<OpLogProto proto file> "
|
||||||
"# Contains extra source code, flops, custom type info. Optional\n\n");
|
"# Contains extra source code, flops, custom type info. Optional\n\n");
|
||||||
printf(
|
absl::PrintF(
|
||||||
"\nTo skip interactive mode, append one of the following commands:\n"
|
"\nTo skip interactive mode, append one of the following commands:\n"
|
||||||
" scope: Organize profiles based on name scopes.\n"
|
" scope: Organize profiles based on name scopes.\n"
|
||||||
" graph: Organize profiles based on graph node input/output.\n"
|
" graph: Organize profiles based on graph node input/output.\n"
|
||||||
@ -392,8 +392,8 @@ string QueryDoc(const string& cmd, const Options& opts) {
|
|||||||
if (s == kShown[0]) {
|
if (s == kShown[0]) {
|
||||||
helps.push_back(kBytes);
|
helps.push_back(kBytes);
|
||||||
} else if (s == kShown[1]) {
|
} else if (s == kShown[1]) {
|
||||||
helps.push_back(strings::StrCat(kTotalMicrosHelp, "\n", kCPUHelp, "\n",
|
helps.push_back(
|
||||||
kAccMicrosHelp));
|
absl::StrCat(kTotalMicrosHelp, "\n", kCPUHelp, "\n", kAccMicrosHelp));
|
||||||
} else if (s == kShown[2]) {
|
} else if (s == kShown[2]) {
|
||||||
helps.push_back(kParams);
|
helps.push_back(kParams);
|
||||||
} else if (s == kShown[3]) {
|
} else if (s == kShown[3]) {
|
||||||
@ -422,8 +422,8 @@ string QueryDoc(const string& cmd, const Options& opts) {
|
|||||||
helps.push_back("Unknown select: " + s);
|
helps.push_back("Unknown select: " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings::StrCat("\nDoc:\n", cmd_help, "\n", absl::StrJoin(helps, "\n"),
|
return absl::StrCat("\nDoc:\n", cmd_help, "\n", absl::StrJoin(helps, "\n"),
|
||||||
"\n\n");
|
"\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tfprof
|
} // namespace tfprof
|
||||||
|
|||||||
@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/lib/core/threadpool.h"
|
#include "tensorflow/core/lib/core/threadpool.h"
|
||||||
#include "tensorflow/core/platform/env_time.h"
|
#include "tensorflow/core/platform/env_time.h"
|
||||||
#include "tensorflow/core/platform/notification.h"
|
#include "tensorflow/core/platform/notification.h"
|
||||||
@ -81,7 +82,7 @@ TEST(RecorderTest, Multithreaded) {
|
|||||||
uint64 start_time = Env::Default()->NowNanos();
|
uint64 start_time = Env::Default()->NowNanos();
|
||||||
uint64 end_time = start_time + kNanosInSec;
|
uint64 end_time = start_time + kNanosInSec;
|
||||||
TraceMeRecorder::Record({/*activity_id=*/j++,
|
TraceMeRecorder::Record({/*activity_id=*/j++,
|
||||||
/*name=*/strings::StrCat(i), start_time,
|
/*name=*/absl::StrCat(i), start_time,
|
||||||
end_time});
|
end_time});
|
||||||
};
|
};
|
||||||
thread_count.fetch_add(1, std::memory_order_relaxed);
|
thread_count.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
|||||||
@ -15,19 +15,21 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_split.h"
|
||||||
#include "linenoise.h"
|
#include "linenoise.h"
|
||||||
#include "tensorflow/c/c_api.h"
|
#include "tensorflow/c/c_api.h"
|
||||||
#include "tensorflow/c/checkpoint_reader.h"
|
#include "tensorflow/c/checkpoint_reader.h"
|
||||||
#include "tensorflow/core/framework/graph.pb.h"
|
#include "tensorflow/core/framework/graph.pb.h"
|
||||||
#include "tensorflow/core/framework/types.h"
|
#include "tensorflow/core/framework/types.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/platform/init_main.h"
|
#include "tensorflow/core/platform/init_main.h"
|
||||||
#include "tensorflow/core/platform/protobuf.h"
|
#include "tensorflow/core/platform/protobuf.h"
|
||||||
@ -93,7 +95,7 @@ int Run(int argc, char** argv) {
|
|||||||
string FLAGS_select = "micros";
|
string FLAGS_select = "micros";
|
||||||
string FLAGS_output = "";
|
string FLAGS_output = "";
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
fprintf(stderr, "%s\n", argv[i]);
|
absl::FPrintF(stderr, "%s\n", argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Flag> flag_list = {
|
std::vector<Flag> flag_list = {
|
||||||
@ -135,31 +137,31 @@ int Run(int argc, char** argv) {
|
|||||||
string usage = Flags::Usage(argv[0], flag_list);
|
string usage = Flags::Usage(argv[0], flag_list);
|
||||||
bool parse_ok = Flags::Parse(&argc, argv, flag_list);
|
bool parse_ok = Flags::Parse(&argc, argv, flag_list);
|
||||||
if (!parse_ok) {
|
if (!parse_ok) {
|
||||||
printf("%s", usage.c_str());
|
absl::PrintF("%s", usage);
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
port::InitMain(argv[0], &argc, &argv);
|
port::InitMain(argv[0], &argc, &argv);
|
||||||
|
|
||||||
if (!FLAGS_profile_path.empty() &&
|
if (!FLAGS_profile_path.empty() &&
|
||||||
(!FLAGS_graph_path.empty() || !FLAGS_run_meta_path.empty())) {
|
(!FLAGS_graph_path.empty() || !FLAGS_run_meta_path.empty())) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"--profile_path is set, do not set --graph_path or "
|
"--profile_path is set, do not set --graph_path or "
|
||||||
"--run_meta_path\n");
|
"--run_meta_path\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<string> account_type_regexes =
|
std::vector<string> account_type_regexes =
|
||||||
str_util::Split(FLAGS_account_type_regexes, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_account_type_regexes, ',', absl::SkipEmpty());
|
||||||
std::vector<string> start_name_regexes =
|
std::vector<string> start_name_regexes =
|
||||||
str_util::Split(FLAGS_start_name_regexes, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_start_name_regexes, ',', absl::SkipEmpty());
|
||||||
std::vector<string> trim_name_regexes =
|
std::vector<string> trim_name_regexes =
|
||||||
str_util::Split(FLAGS_trim_name_regexes, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_trim_name_regexes, ',', absl::SkipEmpty());
|
||||||
std::vector<string> show_name_regexes =
|
std::vector<string> show_name_regexes =
|
||||||
str_util::Split(FLAGS_show_name_regexes, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_show_name_regexes, ',', absl::SkipEmpty());
|
||||||
std::vector<string> hide_name_regexes =
|
std::vector<string> hide_name_regexes =
|
||||||
str_util::Split(FLAGS_hide_name_regexes, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_hide_name_regexes, ',', absl::SkipEmpty());
|
||||||
std::vector<string> select =
|
std::vector<string> select =
|
||||||
str_util::Split(FLAGS_select, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_select, ',', absl::SkipEmpty());
|
||||||
|
|
||||||
string output_type;
|
string output_type;
|
||||||
std::map<string, string> output_options;
|
std::map<string, string> output_options;
|
||||||
@ -183,14 +185,14 @@ int Run(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Reading Files...\n");
|
absl::PrintF("Reading Files...\n");
|
||||||
std::unique_ptr<checkpoint::CheckpointReader> ckpt_reader;
|
std::unique_ptr<checkpoint::CheckpointReader> ckpt_reader;
|
||||||
TF_Status* status = TF_NewStatus();
|
TF_Status* status = TF_NewStatus();
|
||||||
if (!FLAGS_checkpoint_path.empty()) {
|
if (!FLAGS_checkpoint_path.empty()) {
|
||||||
ckpt_reader.reset(
|
ckpt_reader.reset(
|
||||||
new checkpoint::CheckpointReader(FLAGS_checkpoint_path, status));
|
new checkpoint::CheckpointReader(FLAGS_checkpoint_path, status));
|
||||||
if (TF_GetCode(status) != TF_OK) {
|
if (TF_GetCode(status) != TF_OK) {
|
||||||
fprintf(stderr, "%s\n", TF_Message(status));
|
absl::FPrintF(stderr, "%s\n", TF_Message(status));
|
||||||
TF_DeleteStatus(status);
|
TF_DeleteStatus(status);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -201,15 +203,14 @@ int Run(int argc, char** argv) {
|
|||||||
if (!FLAGS_profile_path.empty()) {
|
if (!FLAGS_profile_path.empty()) {
|
||||||
tf_stat.reset(new TFStats(FLAGS_profile_path, std::move(ckpt_reader)));
|
tf_stat.reset(new TFStats(FLAGS_profile_path, std::move(ckpt_reader)));
|
||||||
} else {
|
} else {
|
||||||
printf(
|
absl::PrintF(
|
||||||
"Try to use a single --profile_path instead of "
|
"Try to use a single --profile_path instead of "
|
||||||
"graph_path,op_log_path,run_meta_path\n");
|
"graph_path,op_log_path,run_meta_path\n");
|
||||||
std::unique_ptr<GraphDef> graph(new GraphDef());
|
std::unique_ptr<GraphDef> graph(new GraphDef());
|
||||||
if (!FLAGS_graph_path.empty()) {
|
if (!FLAGS_graph_path.empty()) {
|
||||||
s = ReadProtoFile(Env::Default(), FLAGS_graph_path, graph.get(), false);
|
s = ReadProtoFile(Env::Default(), FLAGS_graph_path, graph.get(), false);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "Failed to read graph_path: %s\n",
|
absl::FPrintF(stderr, "Failed to read graph_path: %s\n", s.ToString());
|
||||||
s.ToString().c_str());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,12 +220,11 @@ int Run(int argc, char** argv) {
|
|||||||
string op_log_str;
|
string op_log_str;
|
||||||
s = ReadFileToString(Env::Default(), FLAGS_op_log_path, &op_log_str);
|
s = ReadFileToString(Env::Default(), FLAGS_op_log_path, &op_log_str);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "Failed to read op_log_path: %s\n",
|
absl::FPrintF(stderr, "Failed to read op_log_path: %s\n", s.ToString());
|
||||||
s.ToString().c_str());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!ParseProtoUnlimited(op_log.get(), op_log_str)) {
|
if (!ParseProtoUnlimited(op_log.get(), op_log_str)) {
|
||||||
fprintf(stderr, "Failed to parse op_log_path\n");
|
absl::FPrintF(stderr, "Failed to parse op_log_path\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,18 +232,19 @@ int Run(int argc, char** argv) {
|
|||||||
std::move(ckpt_reader)));
|
std::move(ckpt_reader)));
|
||||||
|
|
||||||
std::vector<string> run_meta_files =
|
std::vector<string> run_meta_files =
|
||||||
str_util::Split(FLAGS_run_meta_path, ',', str_util::SkipEmpty());
|
absl::StrSplit(FLAGS_run_meta_path, ',', absl::SkipEmpty());
|
||||||
for (int i = 0; i < run_meta_files.size(); ++i) {
|
for (int i = 0; i < run_meta_files.size(); ++i) {
|
||||||
std::unique_ptr<RunMetadata> run_meta(new RunMetadata());
|
std::unique_ptr<RunMetadata> run_meta(new RunMetadata());
|
||||||
s = ReadProtoFile(Env::Default(), run_meta_files[i], run_meta.get(),
|
s = ReadProtoFile(Env::Default(), run_meta_files[i], run_meta.get(),
|
||||||
true);
|
true);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "Failed to read run_meta_path %s. Status: %s\n",
|
absl::FPrintF(stderr, "Failed to read run_meta_path %s. Status: %s\n",
|
||||||
run_meta_files[i].c_str(), s.ToString().c_str());
|
run_meta_files[i], s.ToString());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
tf_stat->AddRunMeta(i, std::move(run_meta));
|
tf_stat->AddRunMeta(i, std::move(run_meta));
|
||||||
fprintf(stdout, "run graph coverage: %.2f\n", tf_stat->run_coverage());
|
absl::FPrintF(stdout, "run graph coverage: %.2f\n",
|
||||||
|
tf_stat->run_coverage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,9 +281,9 @@ int Run(int argc, char** argv) {
|
|||||||
char* line = linenoise("tfprof> ");
|
char* line = linenoise("tfprof> ");
|
||||||
if (line == nullptr) {
|
if (line == nullptr) {
|
||||||
if (!looped) {
|
if (!looped) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"Cannot start interative shell, "
|
"Cannot start interative shell, "
|
||||||
"use 'bazel-bin' instead of 'bazel run'.\n");
|
"use 'bazel-bin' instead of 'bazel run'.\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -291,7 +292,7 @@ int Run(int argc, char** argv) {
|
|||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
if (line_s.empty()) {
|
if (line_s.empty()) {
|
||||||
printf("%s", opts.ToString().c_str());
|
absl::PrintF("%s", opts.ToString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
linenoiseHistoryAdd(line_s.c_str());
|
linenoiseHistoryAdd(line_s.c_str());
|
||||||
@ -300,7 +301,7 @@ int Run(int argc, char** argv) {
|
|||||||
Options new_opts = opts;
|
Options new_opts = opts;
|
||||||
Status s = ParseCmdLine(line_s, &cmd, &new_opts);
|
Status s = ParseCmdLine(line_s, &cmd, &new_opts);
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
fprintf(stderr, "E: %s\n", s.ToString().c_str());
|
absl::FPrintF(stderr, "E: %s\n", s.ToString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cmd == kCmds[5]) {
|
if (cmd == kCmds[5]) {
|
||||||
|
|||||||
@ -31,5 +31,6 @@ cc_library(
|
|||||||
"//tensorflow/core/profiler:profiler_service_proto_cc",
|
"//tensorflow/core/profiler:profiler_service_proto_cc",
|
||||||
"//tensorflow/core/profiler/lib:profiler_lib",
|
"//tensorflow/core/profiler/lib:profiler_lib",
|
||||||
"//tensorflow/core/profiler/lib:profiler_session",
|
"//tensorflow/core/profiler/lib:profiler_session",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -33,6 +33,7 @@ cc_library(
|
|||||||
"//tensorflow/core:protos_all_cc",
|
"//tensorflow/core:protos_all_cc",
|
||||||
"//tensorflow/core/profiler:op_profile_proto_cc",
|
"//tensorflow/core/profiler:op_profile_proto_cc",
|
||||||
"//tensorflow/core/profiler:profiler_service_proto_cc",
|
"//tensorflow/core/profiler:profiler_service_proto_cc",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,6 +44,8 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//tensorflow/core:lib",
|
"//tensorflow/core:lib",
|
||||||
"//tensorflow/core:protos_all_cc",
|
"//tensorflow/core:protos_all_cc",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
"@jsoncpp_git//:jsoncpp",
|
"@jsoncpp_git//:jsoncpp",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -21,12 +21,12 @@ limitations under the License.
|
|||||||
#include "grpcpp/grpcpp.h"
|
#include "grpcpp/grpcpp.h"
|
||||||
#include "absl/strings/escaping.h"
|
#include "absl/strings/escaping.h"
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/numbers.h"
|
||||||
|
#include "absl/strings/str_split.h"
|
||||||
#include "tensorflow/core/distributed_runtime/rpc/grpc_util.h"
|
#include "tensorflow/core/distributed_runtime/rpc/grpc_util.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/core/status.h"
|
#include "tensorflow/core/lib/core/status.h"
|
||||||
#include "tensorflow/core/lib/io/path.h"
|
#include "tensorflow/core/lib/io/path.h"
|
||||||
#include "tensorflow/core/lib/strings/numbers.h"
|
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/profiler/profiler_analysis.grpc.pb.h"
|
#include "tensorflow/core/profiler/profiler_analysis.grpc.pb.h"
|
||||||
#include "tensorflow/core/profiler/profiler_service.grpc.pb.h"
|
#include "tensorflow/core/profiler/profiler_service.grpc.pb.h"
|
||||||
#include "tensorflow/core/profiler/rpc/client/dump_tpu_profile.h"
|
#include "tensorflow/core/profiler/rpc/client/dump_tpu_profile.h"
|
||||||
@ -48,10 +48,10 @@ string GetCurrentTimeStampAsString() {
|
|||||||
|
|
||||||
Status ValidateHostPortPair(const string& host_port) {
|
Status ValidateHostPortPair(const string& host_port) {
|
||||||
uint32 port;
|
uint32 port;
|
||||||
std::vector<string> parts = str_util::Split(host_port, ':');
|
std::vector<string> parts = absl::StrSplit(host_port, ':');
|
||||||
// Must be host:port, port must be a number, host must not contain a '/',
|
// Must be host:port, port must be a number, host must not contain a '/',
|
||||||
// host also must not be empty.
|
// host also must not be empty.
|
||||||
if (parts.size() != 2 || !strings::safe_strtou32(parts[1], &port) ||
|
if (parts.size() != 2 || !absl::SimpleAtoi(parts[1], &port) ||
|
||||||
parts[0].find("/") != string::npos || parts[0].empty()) {
|
parts[0].find("/") != string::npos || parts[0].empty()) {
|
||||||
return errors::InvalidArgument("Could not interpret \"", host_port,
|
return errors::InvalidArgument("Could not interpret \"", host_port,
|
||||||
"\" as a host-port pair.");
|
"\" as a host-port pair.");
|
||||||
@ -180,7 +180,7 @@ Status MaybeCreateEmptyEventFile(const tensorflow::string& logdir) {
|
|||||||
std::vector<string> children;
|
std::vector<string> children;
|
||||||
TF_RETURN_IF_ERROR(Env::Default()->GetChildren(logdir, &children));
|
TF_RETURN_IF_ERROR(Env::Default()->GetChildren(logdir, &children));
|
||||||
for (const string& child : children) {
|
for (const string& child : children) {
|
||||||
if (str_util::EndsWith(child, kProfileEmptySuffix)) {
|
if (absl::EndsWith(child, kProfileEmptySuffix)) {
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,8 +201,7 @@ Status StartTracing(const tensorflow::string& service_addr,
|
|||||||
constexpr char kProfilePluginDirectory[] = "plugins/profile/";
|
constexpr char kProfilePluginDirectory[] = "plugins/profile/";
|
||||||
tensorflow::string repository_root =
|
tensorflow::string repository_root =
|
||||||
io::JoinPath(logdir, kProfilePluginDirectory);
|
io::JoinPath(logdir, kProfilePluginDirectory);
|
||||||
std::vector<tensorflow::string> hostnames =
|
std::vector<tensorflow::string> hostnames = absl::StrSplit(workers_list, ',');
|
||||||
tensorflow::str_util::Split(workers_list, ",");
|
|
||||||
|
|
||||||
TF_RETURN_IF_ERROR(MaybeCreateEmptyEventFile(logdir));
|
TF_RETURN_IF_ERROR(MaybeCreateEmptyEventFile(logdir));
|
||||||
|
|
||||||
|
|||||||
@ -19,11 +19,11 @@ limitations under the License.
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/io/compression.h"
|
#include "tensorflow/core/lib/io/compression.h"
|
||||||
#include "tensorflow/core/lib/io/path.h"
|
#include "tensorflow/core/lib/io/path.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/platform/protobuf.h"
|
#include "tensorflow/core/platform/protobuf.h"
|
||||||
// Windows.h #defines ERROR, but it is also used in
|
// Windows.h #defines ERROR, but it is also used in
|
||||||
@ -43,8 +43,6 @@ namespace {
|
|||||||
using ::tensorflow::io::JoinPath;
|
using ::tensorflow::io::JoinPath;
|
||||||
using ::tensorflow::protobuf::util::JsonOptions;
|
using ::tensorflow::protobuf::util::JsonOptions;
|
||||||
using ::tensorflow::protobuf::util::MessageToJsonString;
|
using ::tensorflow::protobuf::util::MessageToJsonString;
|
||||||
using ::tensorflow::str_util::EndsWith;
|
|
||||||
using ::tensorflow::strings::StrCat;
|
|
||||||
|
|
||||||
constexpr char kJsonOpProfileFileName[] = "op_profile.json";
|
constexpr char kJsonOpProfileFileName[] = "op_profile.json";
|
||||||
constexpr char kJsonTraceFileName[] = "trace.json.gz";
|
constexpr char kJsonTraceFileName[] = "trace.json.gz";
|
||||||
@ -70,12 +68,13 @@ Status WriteGzippedDataToFile(const string& filename, const string& data) {
|
|||||||
Status DumpTraceToLogDirectory(StringPiece run_dir, const string& host_prefix,
|
Status DumpTraceToLogDirectory(StringPiece run_dir, const string& host_prefix,
|
||||||
const string& encoded_trace, std::ostream* os) {
|
const string& encoded_trace, std::ostream* os) {
|
||||||
string proto_path =
|
string proto_path =
|
||||||
JoinPath(run_dir, StrCat(host_prefix, kProtoTraceFileName));
|
JoinPath(run_dir, absl::StrCat(host_prefix, kProtoTraceFileName));
|
||||||
TF_RETURN_IF_ERROR(
|
TF_RETURN_IF_ERROR(
|
||||||
WriteStringToFile(Env::Default(), proto_path, encoded_trace));
|
WriteStringToFile(Env::Default(), proto_path, encoded_trace));
|
||||||
LOG(INFO) << "Dumped raw-proto trace data to " << proto_path;
|
LOG(INFO) << "Dumped raw-proto trace data to " << proto_path;
|
||||||
|
|
||||||
string json_path = JoinPath(run_dir, StrCat(host_prefix, kJsonTraceFileName));
|
string json_path =
|
||||||
|
JoinPath(run_dir, absl::StrCat(host_prefix, kJsonTraceFileName));
|
||||||
Trace trace;
|
Trace trace;
|
||||||
trace.ParseFromString(encoded_trace);
|
trace.ParseFromString(encoded_trace);
|
||||||
if (os) {
|
if (os) {
|
||||||
@ -94,7 +93,8 @@ Status DumpOpProfileToLogDirectory(StringPiece run_dir,
|
|||||||
const string& host_prefix,
|
const string& host_prefix,
|
||||||
const op_profile::Profile& profile,
|
const op_profile::Profile& profile,
|
||||||
std::ostream* os) {
|
std::ostream* os) {
|
||||||
string path = JoinPath(run_dir, StrCat(host_prefix, kJsonOpProfileFileName));
|
string path =
|
||||||
|
JoinPath(run_dir, absl::StrCat(host_prefix, kJsonOpProfileFileName));
|
||||||
string json;
|
string json;
|
||||||
JsonOptions options;
|
JsonOptions options;
|
||||||
options.always_print_primitive_fields = true;
|
options.always_print_primitive_fields = true;
|
||||||
@ -116,10 +116,10 @@ Status DumpToolDataToLogDirectory(StringPiece run_dir,
|
|||||||
const ProfileToolData& tool,
|
const ProfileToolData& tool,
|
||||||
std::ostream* os) {
|
std::ostream* os) {
|
||||||
// Don't save the intermediate results for combining the per host tool data.
|
// Don't save the intermediate results for combining the per host tool data.
|
||||||
if (EndsWith(tool.name(), kFlatProfilerFileName) ||
|
if (absl::EndsWith(tool.name(), kFlatProfilerFileName) ||
|
||||||
EndsWith(tool.name(), kTfStatsHelperSuffix))
|
absl::EndsWith(tool.name(), kTfStatsHelperSuffix))
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
string path = JoinPath(run_dir, StrCat(host_prefix, tool.name()));
|
string path = JoinPath(run_dir, absl::StrCat(host_prefix, tool.name()));
|
||||||
TF_RETURN_IF_ERROR(WriteStringToFile(Env::Default(), path, tool.data()));
|
TF_RETURN_IF_ERROR(WriteStringToFile(Env::Default(), path, tool.data()));
|
||||||
if (os) {
|
if (os) {
|
||||||
*os << "Dumped tool data for " << tool.name() << " to " << path
|
*os << "Dumped tool data for " << tool.name() << " to " << path
|
||||||
@ -135,7 +135,7 @@ Status WriteTensorboardTPUProfile(const string& logdir, const string& run,
|
|||||||
const ProfileResponse& response,
|
const ProfileResponse& response,
|
||||||
std::ostream* os) {
|
std::ostream* os) {
|
||||||
// Dumps profile data to <logdir>/plugins/profile/<run>/.
|
// Dumps profile data to <logdir>/plugins/profile/<run>/.
|
||||||
string host_prefix = host.empty() ? "" : StrCat(host, ".");
|
string host_prefix = host.empty() ? "" : absl::StrCat(host, ".");
|
||||||
string profile_run_dir = JoinPath(logdir, kProfilePluginDirectory, run);
|
string profile_run_dir = JoinPath(logdir, kProfilePluginDirectory, run);
|
||||||
*os << "Creating directory: " << profile_run_dir;
|
*os << "Creating directory: " << profile_run_dir;
|
||||||
TF_RETURN_IF_ERROR(Env::Default()->RecursivelyCreateDir(profile_run_dir));
|
TF_RETURN_IF_ERROR(Env::Default()->RecursivelyCreateDir(profile_run_dir));
|
||||||
|
|||||||
@ -15,9 +15,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/core/profiler/rpc/client/trace_events_to_json.h"
|
#include "tensorflow/core/profiler/rpc/client/trace_events_to_json.h"
|
||||||
|
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
#include "include/json/json.h"
|
#include "include/json/json.h"
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/protobuf/trace_events.pb.h"
|
#include "tensorflow/core/protobuf/trace_events.pb.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -26,13 +26,10 @@ namespace profiler {
|
|||||||
namespace client {
|
namespace client {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::tensorflow::strings::Appendf;
|
|
||||||
using ::tensorflow::strings::StrAppend;
|
|
||||||
|
|
||||||
constexpr double kPicosPerMicro = 1000000.0;
|
constexpr double kPicosPerMicro = 1000000.0;
|
||||||
|
|
||||||
inline void AppendEscapedName(string *json, const string &name) {
|
inline void AppendEscapedName(string *json, const string &name) {
|
||||||
StrAppend(json, "\"name\":", Json::valueToQuotedString(name.c_str()).c_str());
|
absl::StrAppend(json, "\"name\":", Json::valueToQuotedString(name.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds resource events for a single device.
|
// Adds resource events for a single device.
|
||||||
@ -43,17 +40,18 @@ void AddResourceMetadata(uint32 device_id,
|
|||||||
uint32 resource_id = pair.first;
|
uint32 resource_id = pair.first;
|
||||||
const Resource &resource = *pair.second;
|
const Resource &resource = *pair.second;
|
||||||
if (!resource.name().empty()) {
|
if (!resource.name().empty()) {
|
||||||
Appendf(json,
|
absl::StrAppendFormat(json,
|
||||||
R"({"ph":"M","pid":%u,"tid":%u,)"
|
R"({"ph":"M","pid":%u,"tid":%u,)"
|
||||||
R"("name":"thread_name","args":{)",
|
R"("name":"thread_name","args":{)",
|
||||||
device_id, resource_id);
|
device_id, resource_id);
|
||||||
AppendEscapedName(json, resource.name());
|
AppendEscapedName(json, resource.name());
|
||||||
Appendf(json, "}},");
|
absl::StrAppend(json, "}},");
|
||||||
}
|
}
|
||||||
Appendf(json,
|
absl::StrAppendFormat(
|
||||||
R"({"ph":"M","pid":%u,"tid":%u,)"
|
json,
|
||||||
R"("name":"thread_sort_index","args":{"sort_index":%u}},)",
|
R"({"ph":"M","pid":%u,"tid":%u,)"
|
||||||
device_id, resource_id, resource_id);
|
R"("name":"thread_sort_index","args":{"sort_index":%u}},)",
|
||||||
|
device_id, resource_id, resource_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,17 +61,17 @@ void AddDeviceMetadata(const std::map<uint32, const Device *> &devices,
|
|||||||
uint32 device_id = pair.first;
|
uint32 device_id = pair.first;
|
||||||
const Device &device = *pair.second;
|
const Device &device = *pair.second;
|
||||||
if (!device.name().empty()) {
|
if (!device.name().empty()) {
|
||||||
Appendf(json,
|
absl::StrAppendFormat(json,
|
||||||
R"({"ph":"M","pid":%u,"name":"process_name",)"
|
R"({"ph":"M","pid":%u,"name":"process_name",)"
|
||||||
R"("args":{)",
|
R"("args":{)",
|
||||||
device_id);
|
device_id);
|
||||||
AppendEscapedName(json, device.name());
|
AppendEscapedName(json, device.name());
|
||||||
StrAppend(json, "}},");
|
absl::StrAppend(json, "}},");
|
||||||
}
|
}
|
||||||
Appendf(json,
|
absl::StrAppendFormat(json,
|
||||||
R"({"ph":"M","pid":%u,"name":"process_sort_index",)"
|
R"({"ph":"M","pid":%u,"name":"process_sort_index",)"
|
||||||
R"("args":{"sort_index":%u}},)",
|
R"("args":{"sort_index":%u}},)",
|
||||||
device_id, device_id);
|
device_id, device_id);
|
||||||
// Convert to a std::map so that devices are sorted by the device id.
|
// Convert to a std::map so that devices are sorted by the device id.
|
||||||
std::map<uint32, const Resource *> sorted_resources;
|
std::map<uint32, const Resource *> sorted_resources;
|
||||||
for (const auto &pair : device.resources()) {
|
for (const auto &pair : device.resources()) {
|
||||||
@ -84,25 +82,24 @@ void AddDeviceMetadata(const std::map<uint32, const Device *> &devices,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void AddTraceEvent(const TraceEvent &event, string *json) {
|
inline void AddTraceEvent(const TraceEvent &event, string *json) {
|
||||||
Appendf(json, R"({"pid":%u,"tid":%u,"ts":%.5f,)", event.device_id(),
|
absl::StrAppendFormat(json, R"({"pid":%u,"tid":%u,"ts":%.5f,)",
|
||||||
event.resource_id(), event.timestamp_ps() / kPicosPerMicro);
|
event.device_id(), event.resource_id(),
|
||||||
|
event.timestamp_ps() / kPicosPerMicro);
|
||||||
AppendEscapedName(json, event.name());
|
AppendEscapedName(json, event.name());
|
||||||
StrAppend(json, ",");
|
absl::StrAppend(json, ",");
|
||||||
if (event.duration_ps() > 0) {
|
if (event.duration_ps() > 0) {
|
||||||
Appendf(json, R"("ph":"X","dur":%.5f},)",
|
absl::StrAppendFormat(json, R"("ph":"X","dur":%.5f},)",
|
||||||
event.duration_ps() / kPicosPerMicro);
|
event.duration_ps() / kPicosPerMicro);
|
||||||
} else {
|
} else {
|
||||||
StrAppend(json, R"("ph":"i","s":"t"},)");
|
absl::StrAppend(json, R"("ph":"i","s":"t"},)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
string TraceEventsToJson(const Trace &trace) {
|
string TraceEventsToJson(const Trace &trace) {
|
||||||
string json;
|
string json = R"({"displayTimeUnit":"ns","metadata":{"highres-ticks":true},)"
|
||||||
Appendf(
|
R"("traceEvents":[)";
|
||||||
&json, R"({"displayTimeUnit":"ns","metadata":{"highres-ticks":true},)");
|
|
||||||
Appendf(&json, R"("traceEvents":[)");
|
|
||||||
// Convert to a std::map so that devices are sorted by the device id.
|
// Convert to a std::map so that devices are sorted by the device id.
|
||||||
std::map<uint32, const Device *> sorted_devices;
|
std::map<uint32, const Device *> sorted_devices;
|
||||||
for (const auto &pair : trace.devices()) {
|
for (const auto &pair : trace.devices()) {
|
||||||
@ -113,7 +110,7 @@ string TraceEventsToJson(const Trace &trace) {
|
|||||||
AddTraceEvent(event, &json);
|
AddTraceEvent(event, &json);
|
||||||
}
|
}
|
||||||
// Add one fake event to avoid dealing with no-trailing-comma rule.
|
// Add one fake event to avoid dealing with no-trailing-comma rule.
|
||||||
Appendf(&json, R"({}]})");
|
absl::StrAppend(&json, "{}]}");
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ limitations under the License.
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "grpcpp/grpcpp.h"
|
#include "grpcpp/grpcpp.h"
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
#include "absl/strings/str_cat.h"
|
||||||
#include "tensorflow/core/platform/env.h"
|
#include "tensorflow/core/platform/env.h"
|
||||||
#include "tensorflow/core/profiler/lib/profiler_session.h"
|
#include "tensorflow/core/profiler/lib/profiler_session.h"
|
||||||
#include "tensorflow/core/profiler/profiler_service.grpc.pb.h"
|
#include "tensorflow/core/profiler/profiler_service.grpc.pb.h"
|
||||||
@ -31,7 +31,7 @@ namespace tensorflow {
|
|||||||
std::unique_ptr<Thread> StartProfilerServer(int32 port) {
|
std::unique_ptr<Thread> StartProfilerServer(int32 port) {
|
||||||
Env* env = Env::Default();
|
Env* env = Env::Default();
|
||||||
return WrapUnique(env->StartThread({}, "profiler server", [port]() {
|
return WrapUnique(env->StartThread({}, "profiler server", [port]() {
|
||||||
string server_address = strings::StrCat("0.0.0.0:", port);
|
string server_address = absl::StrCat("0.0.0.0:", port);
|
||||||
std::unique_ptr<grpc::ProfilerService::Service> service =
|
std::unique_ptr<grpc::ProfilerService::Service> service =
|
||||||
CreateProfilerService();
|
CreateProfilerService();
|
||||||
::grpc::ServerBuilder builder;
|
::grpc::ServerBuilder builder;
|
||||||
|
|||||||
@ -15,10 +15,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/core/profiler/tfprof_options.h"
|
#include "tensorflow/core/profiler/tfprof_options.h"
|
||||||
|
|
||||||
|
#include "absl/strings/str_format.h"
|
||||||
|
#include "absl/strings/str_split.h"
|
||||||
#include "tensorflow/core/lib/core/errors.h"
|
#include "tensorflow/core/lib/core/errors.h"
|
||||||
#include "tensorflow/core/lib/strings/str_util.h"
|
|
||||||
#include "tensorflow/core/lib/strings/strcat.h"
|
|
||||||
#include "tensorflow/core/lib/strings/stringprintf.h"
|
|
||||||
#include "tensorflow/core/profiler/tfprof_options.pb.h"
|
#include "tensorflow/core/profiler/tfprof_options.pb.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
@ -28,7 +27,7 @@ string KeyValueToStr(const std::map<string, string>& kv_map) {
|
|||||||
std::vector<string> kv_vec;
|
std::vector<string> kv_vec;
|
||||||
kv_vec.reserve(kv_map.size());
|
kv_vec.reserve(kv_map.size());
|
||||||
for (const auto& pair : kv_map) {
|
for (const auto& pair : kv_map) {
|
||||||
kv_vec.push_back(strings::StrCat(pair.first, "=", pair.second));
|
kv_vec.push_back(absl::StrCat(pair.first, "=", pair.second));
|
||||||
}
|
}
|
||||||
return absl::StrJoin(kv_vec, ",");
|
return absl::StrJoin(kv_vec, ",");
|
||||||
}
|
}
|
||||||
@ -50,9 +49,8 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
|
|||||||
if (output_types.find(output_opt) == output_types.end()) {
|
if (output_types.find(output_opt) == output_types.end()) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n",
|
absl::StrFormat("E.g. Unknown output type: %s, Valid types: %s\n",
|
||||||
output_opt.c_str(),
|
output_opt, absl::StrJoin(output_types, ",")));
|
||||||
absl::StrJoin(output_types, ",").c_str()));
|
|
||||||
}
|
}
|
||||||
*output_type = output_opt;
|
*output_type = output_opt;
|
||||||
} else {
|
} else {
|
||||||
@ -60,12 +58,11 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
|
|||||||
if (output_types.find(*output_type) == output_types.end()) {
|
if (output_types.find(*output_type) == output_types.end()) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n",
|
absl::StrFormat("E.g. Unknown output type: %s, Valid types: %s\n",
|
||||||
output_type->c_str(),
|
*output_type, absl::StrJoin(output_types, ",")));
|
||||||
absl::StrJoin(output_types, ",").c_str()));
|
|
||||||
}
|
}
|
||||||
kv_split = str_util::Split(output_opt.substr(opt_split + 1), ",",
|
kv_split = absl::StrSplit(output_opt.substr(opt_split + 1), ",",
|
||||||
str_util::SkipEmpty());
|
absl::SkipEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<string> valid_options;
|
std::set<string> valid_options;
|
||||||
@ -95,7 +92,7 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
|
|||||||
|
|
||||||
for (const string& kv_str : kv_split) {
|
for (const string& kv_str : kv_split) {
|
||||||
const std::vector<string> kv =
|
const std::vector<string> kv =
|
||||||
str_util::Split(kv_str, "=", str_util::SkipEmpty());
|
absl::StrSplit(kv_str, "=", absl::SkipEmpty());
|
||||||
if (kv.size() < 2) {
|
if (kv.size() < 2) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
@ -104,8 +101,8 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
|
|||||||
if (valid_options.find(kv[0]) == valid_options.end()) {
|
if (valid_options.find(kv[0]) == valid_options.end()) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
strings::Printf("Unrecognized options %s for output_type: %s\n",
|
absl::StrFormat("Unrecognized options %s for output_type: %s\n",
|
||||||
kv[0].c_str(), output_type->c_str()));
|
kv[0], *output_type));
|
||||||
}
|
}
|
||||||
const std::vector<string> kv_without_key(kv.begin() + 1, kv.end());
|
const std::vector<string> kv_without_key(kv.begin() + 1, kv.end());
|
||||||
(*output_options)[kv[0]] = absl::StrJoin(kv_without_key, "=");
|
(*output_options)[kv[0]] = absl::StrJoin(kv_without_key, "=");
|
||||||
@ -115,10 +112,9 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
|
|||||||
if (output_options->find(opt) == output_options->end()) {
|
if (output_options->find(opt) == output_options->end()) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INVALID_ARGUMENT,
|
tensorflow::error::INVALID_ARGUMENT,
|
||||||
strings::Printf("Missing required output_options for %s\n"
|
absl::StrFormat("Missing required output_options for %s\n"
|
||||||
"E.g. -output %s:%s=...\n",
|
"E.g. -output %s:%s=...\n",
|
||||||
output_type->c_str(), output_type->c_str(),
|
*output_type, *output_type, opt));
|
||||||
opt.c_str()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tensorflow::Status::OK();
|
return tensorflow::Status::OK();
|
||||||
@ -130,8 +126,8 @@ tensorflow::Status Options::FromProtoStr(const string& opts_proto_str,
|
|||||||
if (!opts_pb.ParseFromString(opts_proto_str)) {
|
if (!opts_pb.ParseFromString(opts_proto_str)) {
|
||||||
return tensorflow::Status(
|
return tensorflow::Status(
|
||||||
tensorflow::error::INTERNAL,
|
tensorflow::error::INTERNAL,
|
||||||
strings::StrCat("Failed to parse option string from Python API: ",
|
absl::StrCat("Failed to parse option string from Python API: ",
|
||||||
opts_proto_str));
|
opts_proto_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
string output_type;
|
string output_type;
|
||||||
@ -141,11 +137,12 @@ tensorflow::Status Options::FromProtoStr(const string& opts_proto_str,
|
|||||||
if (!s.ok()) return s;
|
if (!s.ok()) return s;
|
||||||
|
|
||||||
if (!opts_pb.dump_to_file().empty()) {
|
if (!opts_pb.dump_to_file().empty()) {
|
||||||
fprintf(stderr,
|
absl::FPrintF(stderr,
|
||||||
"-dump_to_file option is deprecated. "
|
"-dump_to_file option is deprecated. "
|
||||||
"Please use -output file:outfile=<filename>\n");
|
"Please use -output file:outfile=<filename>\n");
|
||||||
fprintf(stderr, "-output %s is overwritten with -output file:outfile=%s\n",
|
absl::FPrintF(stderr,
|
||||||
opts_pb.output().c_str(), opts_pb.dump_to_file().c_str());
|
"-output %s is overwritten with -output file:outfile=%s\n",
|
||||||
|
opts_pb.output(), opts_pb.dump_to_file());
|
||||||
output_type = kOutput[2];
|
output_type = kOutput[2];
|
||||||
output_options.clear();
|
output_options.clear();
|
||||||
output_options[kFileOpts[0]] = opts_pb.dump_to_file();
|
output_options[kFileOpts[0]] = opts_pb.dump_to_file();
|
||||||
@ -173,20 +170,21 @@ tensorflow::Status Options::FromProtoStr(const string& opts_proto_str,
|
|||||||
return tensorflow::Status::OK();
|
return tensorflow::Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
string Options::ToString() const {
|
std::string Options::ToString() const {
|
||||||
const string s = strings::Printf(
|
// clang-format off
|
||||||
|
const std::string s = absl::StrFormat(
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
|
"%-28s%d\n"
|
||||||
"%-28s%d\n"
|
"%-28s%d\n"
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%lld\n"
|
|
||||||
"%-28s%s\n"
|
"%-28s%s\n"
|
||||||
"%-28s%s\n"
|
"%-28s%s\n"
|
||||||
"%-28s%s\n"
|
"%-28s%s\n"
|
||||||
@ -196,20 +194,28 @@ string Options::ToString() const {
|
|||||||
"%-28s%s\n"
|
"%-28s%s\n"
|
||||||
"%-28s%s\n"
|
"%-28s%s\n"
|
||||||
"%-28s%s:%s\n",
|
"%-28s%s:%s\n",
|
||||||
kOptions[0], max_depth, kOptions[1], min_bytes, kOptions[2],
|
kOptions[0], max_depth,
|
||||||
min_peak_bytes, kOptions[3], min_residual_bytes, kOptions[4],
|
kOptions[1], min_bytes,
|
||||||
min_output_bytes, kOptions[5], min_micros, kOptions[6],
|
kOptions[2], min_peak_bytes,
|
||||||
min_accelerator_micros, kOptions[7], min_cpu_micros, kOptions[8],
|
kOptions[3], min_residual_bytes,
|
||||||
min_params, kOptions[9], min_float_ops, kOptions[10], min_occurrence,
|
kOptions[4], min_output_bytes,
|
||||||
kOptions[11], step, kOptions[12], order_by.c_str(), kOptions[13],
|
kOptions[5], min_micros,
|
||||||
absl::StrJoin(account_type_regexes, ",").c_str(), kOptions[14],
|
kOptions[6], min_accelerator_micros,
|
||||||
absl::StrJoin(start_name_regexes, ",").c_str(), kOptions[15],
|
kOptions[7], min_cpu_micros,
|
||||||
absl::StrJoin(trim_name_regexes, ",").c_str(), kOptions[16],
|
kOptions[8], min_params,
|
||||||
absl::StrJoin(show_name_regexes, ",").c_str(), kOptions[17],
|
kOptions[9], min_float_ops,
|
||||||
absl::StrJoin(hide_name_regexes, ",").c_str(), kOptions[18],
|
kOptions[10], min_occurrence,
|
||||||
(account_displayed_op_only ? "true" : "false"), kOptions[19],
|
kOptions[11], step,
|
||||||
absl::StrJoin(select, ",").c_str(), kOptions[20], output_type.c_str(),
|
kOptions[12], order_by,
|
||||||
KeyValueToStr(output_options).c_str());
|
kOptions[13], absl::StrJoin(account_type_regexes, ","),
|
||||||
|
kOptions[14], absl::StrJoin(start_name_regexes, ","),
|
||||||
|
kOptions[15], absl::StrJoin(trim_name_regexes, ","),
|
||||||
|
kOptions[16], absl::StrJoin(show_name_regexes, ","),
|
||||||
|
kOptions[17], absl::StrJoin(hide_name_regexes, ","),
|
||||||
|
kOptions[18], (account_displayed_op_only ? "true" : "false"),
|
||||||
|
kOptions[19], absl::StrJoin(select, ","),
|
||||||
|
kOptions[20], output_type, KeyValueToStr(output_options));
|
||||||
|
// clang-format on
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user