Use Abseil string utilities in the TensorFlow Profiler.

PiperOrigin-RevId: 284597520
Change-Id: I5df43eeff1913f95ff726b40f51c51e9ae015de9
This commit is contained in:
A. Unique TensorFlower 2019-12-09 11:26:45 -08:00 committed by TensorFlower Gardener
parent 8ccf72521d
commit 59329ef58f
38 changed files with 485 additions and 457 deletions

View File

@ -103,6 +103,8 @@ cc_library(
":protos_all_cc",
"//tensorflow/core:framework_headers_lib",
"//tensorflow/core:lib",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)

View File

@ -25,6 +25,8 @@ cc_library(
"//tensorflow/core:regexp_internal",
"//tensorflow/core/profiler:protos_all_cc",
"//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",
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@jsoncpp_git//:jsoncpp",
],
)
@ -52,6 +56,7 @@ cc_library(
"//tensorflow/core:regexp_internal",
"//tensorflow/core/profiler:protos_all_cc",
"//tensorflow/core/profiler:tfprof_options",
"@com_google_absl//absl/strings:str_format",
],
)
@ -73,6 +78,7 @@ cc_library(
"//tensorflow/core:regexp_internal",
"//tensorflow/core/profiler:protos_all_cc",
"//tensorflow/core/profiler:tfprof_options",
"@com_google_absl//absl/strings:str_format",
],
)
@ -86,13 +92,14 @@ cc_library(
":tfprof_show_multi",
":tfprof_tensor",
":tfprof_utils",
"//tensorflow/c:c_api",
"//tensorflow/c:checkpoint_reader",
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:regexp_internal",
"//tensorflow/core/profiler:protos_all_cc",
"//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/profiler:protos_all_cc",
"//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/profiler:protos_all_cc",
"//tensorflow/core/profiler:tfprof_options",
"@com_google_absl//absl/strings:str_format",
],
)
@ -169,6 +179,8 @@ cc_library(
"//tensorflow/core:regexp_internal",
"//tensorflow/core/profiler:protos_all_cc",
"//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/profiler:protos_all_cc",
"//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:regexp_internal",
"//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:tfprof_options",
"//tensorflow/core/profiler/internal/advisor:tfprof_advisor",
"@com_google_absl//absl/strings:str_format",
],
alwayslink = 1,
)
@ -314,6 +331,8 @@ cc_library(
"//tensorflow/core:framework",
"//tensorflow/core:lib",
"//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 = [
":traceme_recorder",
"//tensorflow/core:lib",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)

View File

@ -30,6 +30,7 @@ cc_library(
hdrs = ["accelerator_utilization_checker.h"],
deps = [
":checker",
"@com_google_absl//absl/strings:str_format",
],
)
@ -38,6 +39,7 @@ cc_library(
hdrs = ["operation_checker.h"],
deps = [
":checker",
"@com_google_absl//absl/strings:str_format",
],
)
@ -46,6 +48,8 @@ cc_library(
hdrs = ["expensive_operation_checker.h"],
deps = [
":checker",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)
@ -59,6 +63,7 @@ cc_library(
":internal_checker_runner_dummy",
":operation_checker",
"//tensorflow/core/profiler:protos_all_cc",
"@com_google_absl//absl/strings:str_format",
],
)

View File

@ -16,6 +16,7 @@ limitations under the License.
#ifndef 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"
namespace tensorflow {
@ -39,8 +40,8 @@ class AcceleratorUtilizationChecker : public Checker {
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
const TFStats* stats) override {
if (!stats) {
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
name().c_str());
absl::FPrintF(
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
return reports_;
}
for (const auto& n : stats->nodes()) {
@ -56,14 +57,14 @@ class AcceleratorUtilizationChecker : public Checker {
if (total_micros <= 0) continue;
double utilization = 1.0 * stat.exec_micros / total_micros;
if (utilization >= 0.5) {
reports_.add_reports(strings::Printf("device: %s utilization: %.2f",
s.first.c_str(), utilization));
reports_.add_reports(absl::StrFormat("device: %s utilization: %.2f",
s.first, utilization));
} else if (utilization < 0.5 && utilization > 0.2) {
reports_.add_reports(strings::Printf("device: %s low utilization: %.2f",
s.first.c_str(), utilization));
reports_.add_reports(absl::StrFormat("device: %s low utilization: %.2f",
s.first, utilization));
} else if (utilization <= 0.2) {
reports_.add_reports(strings::Printf("device: %s low utilization: %.2f",
s.first.c_str(), utilization));
reports_.add_reports(absl::StrFormat("device: %s low utilization: %.2f",
s.first, utilization));
}
}
return reports_;

View File

@ -16,7 +16,6 @@ limitations under the License.
#ifndef 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/tfprof_options.pb.h"

View File

@ -16,6 +16,8 @@ limitations under the License.
#ifndef 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"
namespace tensorflow {
@ -29,12 +31,12 @@ class ExpensiveOperationChecker : public Checker {
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
const TFStats* stats) override {
if (!stats) {
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
name().c_str());
absl::FPrintF(
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
return reports_;
}
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);
CheckScopeView(stats);
@ -44,7 +46,7 @@ class ExpensiveOperationChecker : public Checker {
void CheckOpView(const TFStats* stats) {
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;
}
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;
for (int i = 0; i < 3 && node->children_size() > 0; ++i) {
node = &node->children(0);
outputs.push_back(strings::Printf(
outputs.push_back(absl::StrFormat(
"top %d operation type: %s, "
"cpu: %s, accelerator: %s, total: %s (%.2f%%)",
i + 1, node->name().c_str(),
FormatTime(node->cpu_exec_micros()).c_str(),
FormatTime(node->accelerator_exec_micros()).c_str(),
FormatTime(node->exec_micros()).c_str(),
i + 1, node->name(), FormatTime(node->cpu_exec_micros()),
FormatTime(node->accelerator_exec_micros()),
FormatTime(node->exec_micros()),
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) {
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;
}
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;
CodeViewHelper(node, 0, &outputs);
reports_.add_reports(str_util::Join(outputs, "\n"));
reports_.add_reports(absl::StrJoin(outputs, "\n"));
}
void CheckScopeView(const TFStats* stats) {
@ -102,13 +103,13 @@ class ExpensiveOperationChecker : public Checker {
std::vector<string> outputs;
for (int i = 0; i < 3 && i < root.children_size(); ++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,
node.name().c_str(), FormatTime(node.cpu_exec_micros()).c_str(),
FormatTime(node.accelerator_exec_micros()).c_str(),
FormatTime(node.exec_micros()).c_str()));
node.name(), FormatTime(node.cpu_exec_micros()),
FormatTime(node.accelerator_exec_micros()),
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,
@ -121,12 +122,12 @@ class ExpensiveOperationChecker : public Checker {
if (c->total_exec_micros() < 1000) {
continue;
}
outputs->push_back(strings::Printf(
"%s%s, cpu: %s, accelerator: %s, total: %s",
string(depth * 2, ' ').c_str(), c->name().c_str(),
FormatTime(c->total_cpu_exec_micros()).c_str(),
FormatTime(c->total_accelerator_exec_micros()).c_str(),
FormatTime(c->total_exec_micros()).c_str()));
outputs->push_back(
absl::StrFormat("%s%s, cpu: %s, accelerator: %s, total: %s",
std::string(depth * 2, ' '), c->name(),
FormatTime(c->total_cpu_exec_micros()),
FormatTime(c->total_accelerator_exec_micros()),
FormatTime(c->total_exec_micros())));
CodeViewHelper(c, depth + 1, outputs);
}
}

View File

@ -17,6 +17,7 @@ limitations under the License.
#ifndef 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"
namespace tensorflow {
@ -30,8 +31,8 @@ class OperationChecker : public Checker {
AdviceProto::Checker Check(const AdvisorOptionsProto::CheckerOption& options,
const TFStats* stats) override {
if (!stats) {
fprintf(stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n",
name().c_str());
absl::FPrintF(
stderr, "Missing profiles (e.g. graph, run_meta). Skip %s\n", name());
return reports_;
}
bool use_batch_norm = false;

View File

@ -16,6 +16,7 @@ limitations under the License.
#ifndef 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/checker.h"
#include "tensorflow/core/profiler/internal/advisor/expensive_operation_checker.h"
@ -62,9 +63,9 @@ class Advisor {
stats_));
}
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()) {
fprintf(stdout, "%s\n", r.c_str());
absl::FPrintF(stdout, "%s\n", r);
}
}
fflush(stdout);

View File

@ -16,7 +16,6 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/advisor/tfprof_advisor.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/test.h"

View File

@ -21,12 +21,11 @@ limitations under the License.
#include "absl/container/fixed_array.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/lib/core/errors.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/abi.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/gpu/cupti_tracer.h"
#include "tensorflow/core/profiler/internal/gpu/cupti_wrapper.h"
@ -165,8 +164,8 @@ class CuptiTraceCollectorImpl : public CuptiTraceCollector {
ns->set_node_name(activity_name);
switch (event.type) {
case CuptiTracerEventType::Kernel: {
const std::string details = strings::Printf(
"regs:%llu shm:%llu grid:%llu,%llu,%llu block:%llu,%llu,%llu",
const std::string details = absl::StrFormat(
"regs:%u shm:%u grid:%u,%u,%u block:%u,%u,%u",
event.kernel_info.registers_per_thread,
event.kernel_info.static_shared_memory_usage,
event.kernel_info.grid_x, event.kernel_info.grid_y,

View File

@ -16,9 +16,11 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/print_model_analysis.h"
#include <stdio.h>
#include <memory>
#include <utility>
#include "absl/strings/str_format.h"
#include "tensorflow/c/checkpoint_reader.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/lib/core/errors.h"
@ -40,7 +42,7 @@ string RunProfile(const string& command, const string& options,
if (command == kCmds[4]) {
AdvisorOptionsProto option_pb;
if (!option_pb.ParseFromString(options)) {
fprintf(stderr, "Cannot parse AdvisorOptionsProto\n");
absl::FPrintF(stderr, "Cannot parse AdvisorOptionsProto\n");
return "";
}
tf_stats->BuildAllViews();
@ -52,23 +54,26 @@ string RunProfile(const string& command, const string& options,
Options opts;
tensorflow::Status s = Options::FromProtoStr(options, &opts);
if (!s.ok()) {
fprintf(stderr, "%s\n", s.ToString().c_str());
absl::FPrintF(stderr, "%s\n", s.ToString());
return "";
}
if (opts.output_type == kOutput[1]) {
printf("\n=========================Options=============================\n");
printf("%s", opts.ToString().c_str());
printf("\n==================Model Analysis Report======================\n");
absl::PrintF(
"\n=========================Options=============================\n");
absl::PrintF("%s", opts.ToString());
absl::PrintF(
"\n==================Model Analysis Report======================\n");
string ret = "";
if (command == kCmds[2] || command == kCmds[3]) {
ret = tf_stats->ShowMultiGraphNode(command, opts).SerializeAsString();
} else if (command == kCmds[0] || command == kCmds[1]) {
ret = tf_stats->ShowGraphNode(command, opts).SerializeAsString();
} 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);
return ret;
}
@ -77,7 +82,7 @@ string RunProfile(const string& command, const string& options,
} else if (command == kCmds[0] || command == kCmds[1]) {
return tf_stats->ShowGraphNode(command, opts).SerializeAsString();
} else {
fprintf(stderr, "Unknown command: %s\n", command.c_str());
absl::FPrintF(stderr, "Unknown command: %s\n", command);
return "";
}
}
@ -88,7 +93,7 @@ bool NewProfiler(const string* graph, const string* op_log) {
if (graph && !graph->empty()) {
if (!graph_ptr->ParseFromString(*graph)) {
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;
}
}
@ -98,7 +103,7 @@ bool NewProfiler(const string* graph, const string* op_log) {
if (op_log && !op_log->empty()) {
op_log_ptr.reset(new OpLogProto());
if (!op_log_ptr->ParseFromString(*op_log)) {
fprintf(stderr, "Failed to parse OpLogProto.\n");
absl::FPrintF(stderr, "Failed to parse OpLogProto.\n");
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());
if (!graph_ptr->ParseFromString(*graph)) {
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));

View File

@ -16,16 +16,16 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_code.h"
#include <stdio.h>
#include <utility>
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "tensorflow/c/c_api.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/io/zlib_compression_options.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/profiler/internal/tfprof_constants.h"
@ -36,13 +36,13 @@ namespace {
const char* const kGradientSuffix = " (gradient)";
// Convert to Trace proto into a short readable string.
string GetTraceString(const CallStack::Trace& trace) {
string ntrace(io::Basename(trace.file()));
ntrace += strings::StrCat(":", trace.lineno());
std::string GetTraceString(const CallStack::Trace& trace) {
std::string ntrace =
absl::StrCat(io::Basename(trace.file()), ":", trace.lineno());
if (trace.function().length() < 20) {
ntrace += ":" + trace.function();
absl::StrAppend(&ntrace, ":", trace.function());
} else {
ntrace += ":" + trace.function().substr(0, 17) + "...";
absl::StrAppend(&ntrace, ":", trace.function().substr(0, 17), "...");
}
return ntrace;
}
@ -116,7 +116,7 @@ class FunctionTable {
string file_base(io::Basename(file_path));
file_base = file_base.substr(0, file_base.find_last_of("."));
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_start_line(func_start_line);
return func_pb->id();
@ -229,7 +229,7 @@ class Samples {
} else if (type == kShown[3]) {
sample_pb->mutable_value()->Add(gn->float_ops(node->node->step()));
} 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;
return s;
}
fprintf(stdout, "\nRun pprof -png --nodecount=100 --sample_index=1 <%s>\n",
filename.c_str());
absl::FPrintF(stdout,
"\nRun pprof -png --nodecount=100 --sample_index=1 <%s>\n",
filename);
delete zlib_output_buffer;
return s;
}
@ -364,7 +365,7 @@ class PprofProfileImpl : public PprofProfile {
profile_pb->mutable_comment()->Add(string_table_.GetIndex(
"Model float operations (Only available if defined)."));
} 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()) {
@ -459,7 +460,8 @@ void TFCode::Build() {
}
}
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();
if (opts.output_type == kOutput[3]) {
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();
}
string select = *opts.select.begin();
if (select != kShown[0] && select != kShown[1] && select != kShown[2] &&
select != kShown[3] && select != kShown[9] && select != kShown[10] &&
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();
}
}
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);
@ -508,7 +511,7 @@ const ShowMultiNode* TFCode::ShowInternal(const Options& opts,
Status s = pprof_profile_->WritePprofProfile(
opts.output_options.at(kPprofOpts[0]));
if (!s.ok()) {
fprintf(stderr, "%s\n", s.ToString().c_str());
absl::FPrintF(stderr, "%s\n", s.ToString());
}
} else {
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);
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);
} else {
@ -690,15 +693,14 @@ string TFCode::FormatNode(CodeNode* node, const Options& opts,
}
if (opts.select.find(kShown[7]) != opts.select.end()) {
// 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()) {
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(),
node->name().c_str(),
absl::StrJoin(attrs, ", ").c_str());
return absl::StrFormat("%s%s (%s)\n", std::string(indent, ' '), node->name(),
absl::StrJoin(attrs, ", "));
}
} // namespace tfprof
} // namespace tensorflow

View File

@ -16,10 +16,10 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_graph.h"
#include <stdio.h>
#include <utility>
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "absl/strings/str_format.h"
#include "tensorflow/core/platform/regexp.h"
#include "tensorflow/core/profiler/internal/tfprof_constants.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();
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_;
}
if (timeline && timeline->step() < 0) {
// TODO(xpan): Maybe pick a default step for users.
fprintf(stderr,
"Must specify -step option to generate timeline in graph view.\n");
absl::FPrintF(
stderr,
"Must specify -step option to generate timeline in graph view.\n");
return root_;
}
// 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->formatted_str =
strings::Printf("%s%s\n", string(last_ident, ' ').c_str(),
FormatNode(node, opts).c_str());
node->formatted_str = absl::StrFormat(
"%s%s\n", std::string(last_ident, ' '), FormatNode(node, opts));
if (opts.select.find(kShown[4]) != opts.select.end()) {
std::unique_ptr<TFProfTensor> tfprof_tensor;

View File

@ -85,8 +85,8 @@ void ExecStep::AddMemoryStats(const string& dev,
exec_mem.set_memory_micros(step_stat.all_start_micros() +
step_stat.op_end_rel_micros());
} else {
fprintf(stderr, "%s has no start time, skipping\n",
step_stat.node_name().c_str());
absl::FPrintF(stderr, "%s has no start time, skipping\n",
step_stat.node_name());
return;
}
@ -106,8 +106,8 @@ void ExecStep::AddMemoryStats(const string& dev,
}
}
if (accelerator_allocator_cnt > 1) {
fprintf(stderr, "found %d gpu allocator for 1 node\n",
accelerator_allocator_cnt);
absl::FPrintF(stderr, "found %d gpu allocator for 1 node\n",
accelerator_allocator_cnt);
}
int64 total_output_bytes = 0;

View File

@ -21,6 +21,7 @@ limitations under the License.
#include <string>
#include <vector>
#include "absl/strings/str_format.h"
#include "tensorflow/core/framework/allocation_description.pb.h"
#include "tensorflow/core/framework/attr_value.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_shape.pb.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/profiler/tfprof_log.pb.h"
#include "tensorflow/core/profiler/tfprof_options.h"
@ -326,13 +325,13 @@ class TFGraphNode {
(*node_.mutable_attrs())[attr.first].MergeFrom(attr.second);
if (attr.first == "shape" && attr.second.has_shape()) {
if (!shape_.empty()) {
fprintf(stderr, "Found duplicated shapes!\n");
absl::FPrintF(stderr, "Found duplicated shapes!\n");
continue;
}
shape_ = ShapeProtoToVec(attr.second.shape());
} else if (attr.first == "_output_shapes" && attr.second.has_list()) {
if (!output_shapes_.empty()) {
fprintf(stderr, "Found duplicated output shapes!\n");
absl::FPrintF(stderr, "Found duplicated output shapes!\n");
continue;
}
for (int i = 0; i < attr.second.list().shape_size(); ++i) {
@ -669,7 +668,7 @@ class TFGraphNode {
if (complete_shape) {
return params;
} else {
fprintf(stderr, "Incomplete shape.\n");
absl::FPrintF(stderr, "Incomplete shape.\n");
}
}
return 0;

View File

@ -14,9 +14,6 @@ limitations under the License.
==============================================================================*/
#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 tfprof {
namespace {}

View File

@ -16,10 +16,11 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_op.h"
#include <stdio.h>
#include <utility>
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "tensorflow/core/platform/regexp.h"
#include "tensorflow/core/profiler/internal/tfprof_constants.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();
}
return strings::Printf(
"%30s", strings::Printf("%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().exec_micros()).c_str(),
accu_pct, pct)
.c_str());
return absl::StrFormat(
"%30s",
absl::StrFormat("%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().exec_micros()), accu_pct, pct));
}
string FormatCPUExecTime(const ShowMultiNode* node, const ShowMultiNode* root) {
double accu_pct = 0.0;
@ -54,12 +54,10 @@ string FormatCPUExecTime(const ShowMultiNode* node, const ShowMultiNode* root) {
root->proto().total_cpu_exec_micros();
}
return strings::Printf(
"%30s",
strings::Printf("%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().cpu_exec_micros()).c_str(),
accu_pct, pct)
.c_str());
return absl::StrFormat(
"%30s", absl::StrFormat("%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().cpu_exec_micros()),
accu_pct, pct));
}
string FormatAcceleratorExecTime(const ShowMultiNode* node,
const ShowMultiNode* root) {
@ -72,12 +70,11 @@ string FormatAcceleratorExecTime(const ShowMultiNode* node,
root->proto().total_accelerator_exec_micros();
}
return strings::Printf(
"%30s", strings::Printf(
"%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().accelerator_exec_micros()).c_str(),
accu_pct, pct)
.c_str());
return absl::StrFormat(
"%30s",
absl::StrFormat("%s (%.2f%%, %.2f%%)",
FormatTime(node->proto().accelerator_exec_micros()),
accu_pct, pct));
}
} // namespace
@ -106,16 +103,16 @@ const ShowMultiNode* TFOp::ShowInternal(const Options& opts,
Timeline* timeline) {
root_->ResetTotalStats();
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();
}
if (opts.output_type == kOutput[1] || opts.output_type == kOutput[2]) {
root_->formatted_str = FormatNode(root_.get(), root_.get(), opts);
}
if (timeline) {
fprintf(stderr,
"op view doesn't support timeline yet. "
"Consider graph/scope/code view.\n");
absl::FPrintF(stderr,
"op view doesn't support timeline yet. "
"Consider graph/scope/code view.\n");
return root_.get();
}
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;
pct = 100.0 * node_bytes / root_total_bytes;
}
return strings::Printf(
"%30s", strings::Printf("%s (%.2f%%, %.2f%%)",
FormatMemory(node_bytes).c_str(), accu_pct, pct)
.c_str());
return absl::StrFormat(
"%30s", absl::StrFormat("%s (%.2f%%, %.2f%%)", FormatMemory(node_bytes),
accu_pct, pct));
}
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 =
100.0 * node->proto().parameters() / root->proto().total_parameters();
}
attrs.push_back(strings::Printf(
"%30s",
strings::Printf("%s params (%.2f%%, %.2f%%)",
FormatNumber(node->proto().parameters()).c_str(),
accu_pct, pct)
.c_str()));
attrs.push_back(absl::StrFormat(
"%30s", absl::StrFormat("%s params (%.2f%%, %.2f%%)",
FormatNumber(node->proto().parameters()),
accu_pct, pct)));
}
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();
}
attrs.push_back(strings::Printf(
"%30s", strings::Printf("%s float_ops (%.2f%%, %.2f%%)",
FormatNumber(node->proto().float_ops()).c_str(),
accu_pct, pct)
.c_str()));
attrs.push_back(absl::StrFormat(
"%30s", absl::StrFormat("%s float_ops (%.2f%%, %.2f%%)",
FormatNumber(node->proto().float_ops()),
accu_pct, pct)));
}
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()) {
total_runs += gnode.run_count();
}
attrs.push_back(strings::Printf(
"%10s",
strings::Printf("%lld|%d", total_runs, node->proto().graph_nodes_size())
.c_str()));
attrs.push_back(absl::StrFormat(
"%10s", absl::StrFormat("%d|%d", total_runs,
node->proto().graph_nodes_size())));
}
string node_str = strings::Printf("%-25s%s\n", node->name().c_str(),
absl::StrJoin(attrs, ", ").c_str());
string node_str =
absl::StrFormat("%-25s%s\n", node->name(), absl::StrJoin(attrs, ", "));
if (opts.select.find(kShown[8]) != opts.select.end()) {
string input_shape_str = FormatInputShapes(node->proto());
if (!input_shape_str.empty()) {
node_str = strings::Printf("%s\n%s\n\n", node_str.c_str(),
input_shape_str.c_str());
node_str = absl::StrFormat("%s\n%s\n\n", node_str, input_shape_str);
}
}
return node_str;

View File

@ -16,11 +16,12 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
#include <stdio.h>
#include <utility>
#include "absl/strings/str_format.h"
#include "tensorflow/c/c_api.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/regexp.h"
#include "tensorflow/core/profiler/internal/tfprof_constants.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) {
root_->ResetTotalStats();
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_;
}
@ -171,9 +172,8 @@ std::vector<ScopeNode*> TFScope::PrintScope(const std::vector<ScopeNode*> roots,
}
}
node->formatted_str =
strings::Printf("%s%s\n", string(last_ident, ' ').c_str(),
FormatNode(node, opts).c_str());
node->formatted_str = absl::StrFormat(
"%s%s\n", std::string(last_ident, ' '), FormatNode(node, opts));
if (opts.select.find(kShown[4]) != opts.select.end()) {
std::unique_ptr<TFProfTensor> tfprof_tensor;

View File

@ -18,7 +18,8 @@ limitations under the License.
#include <memory>
#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/regexp.h"
@ -32,19 +33,19 @@ const GraphNodeProto& TFShow::Show(const string& prefix, const Options& opts) {
} else {
const ShowNode* ret = ShowInternal(opts, nullptr);
if (opts.output_type == kOutput[1]) {
printf("%s", (prefix + ret->formatted_str).c_str());
absl::PrintF("%s", (prefix + ret->formatted_str));
fflush(stdout);
} else if (opts.output_type == kOutput[2]) {
Status s = WriteStringToFile(Env::Default(),
opts.output_options.at(kFileOpts[0]),
prefix + ret->formatted_str);
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] ||
opts.output_type == kOutput[4]) {
} 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();
}
@ -59,7 +60,7 @@ bool TFShow::LookUpCheckPoint(const string& name,
TF_Status* status = TF_NewStatus();
ckpt_reader_->GetTensor(name, &out_tensor, status);
if (TF_GetCode(status) != TF_OK) {
fprintf(stderr, "%s\n", TF_Message(status));
absl::FPrintF(stderr, "%s\n", TF_Message(status));
TF_DeleteStatus(status);
return false;
}
@ -227,17 +228,16 @@ string TFShow::FormatNode(ShowNode* node, const Options& opts) const {
std::vector<string> shape_vec;
for (const auto& s : node->node->input_shapes()) {
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 {
shape_vec.push_back(strings::Printf(
"%d:%s", s.first, absl::StrJoin(s.second, "x").c_str()));
shape_vec.push_back(
absl::StrFormat("%d:%s", s.first, absl::StrJoin(s.second, "x")));
}
}
info.push_back(absl::StrJoin(shape_vec, "|"));
}
return strings::Printf("%s (%s)", node->name().c_str(),
absl::StrJoin(info, ", ").c_str());
return absl::StrFormat("%s (%s)", node->name(), absl::StrJoin(info, ", "));
}
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()) {
legends.push_back("input shapes");
}
return strings::Printf("node name | %s\n",
absl::StrJoin(legends, " | ").c_str());
return absl::StrFormat("node name | %s\n", absl::StrJoin(legends, " | "));
}
} // namespace tfprof

View File

@ -25,7 +25,6 @@ limitations under the License.
#include "tensorflow/c/checkpoint_reader.h"
#include "tensorflow/core/framework/graph.pb.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_node.h"
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"

View File

@ -18,8 +18,8 @@ limitations under the License.
#include <memory>
#include <set>
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/regexp.h"
#include "tensorflow/core/profiler/internal/tfprof_scope.h"
@ -35,19 +35,19 @@ const MultiGraphNodeProto& TFMultiShow::Show(const string& prefix,
} else {
const ShowMultiNode* ret = ShowInternal(opts, nullptr);
if (opts.output_type == kOutput[1]) {
printf("%s", (prefix + ret->formatted_str).c_str());
absl::PrintF("%s%s", prefix, ret->formatted_str);
fflush(stdout);
} else if (opts.output_type == kOutput[2]) {
Status s = WriteStringToFile(Env::Default(),
opts.output_options.at(kFileOpts[0]),
prefix + ret->formatted_str);
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] ||
opts.output_type == kOutput[4]) {
} 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();
}
@ -158,8 +158,7 @@ string TFMultiShow::FormatLegend(const Options& opts) const {
if (opts.select.find(kShown[8]) != opts.select.end()) {
legends.push_back("input shapes");
}
return strings::Printf("node name | %s\n",
absl::StrJoin(legends, " | ").c_str());
return absl::StrFormat("node name | %s\n", absl::StrJoin(legends, " | "));
}
string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
@ -176,14 +175,14 @@ string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
std::vector<string> input_vec;
for (const auto& s : input_shapes) {
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 {
input_vec.push_back(strings::Printf(
"%d:%s", s.first, absl::StrJoin(s.second, "x").c_str()));
input_vec.push_back(
absl::StrFormat("%d:%s", s.first, absl::StrJoin(s.second, "x")));
}
}
string shape_type_str = strings::Printf(
"input_type: %s", absl::StrJoin(input_vec, ",\t").c_str());
string shape_type_str =
absl::StrFormat("input_type: %s", absl::StrJoin(input_vec, ",\t"));
auto t = input_shapes_attr.find(shape_type_str);
if (t == input_shapes_attr.end()) {
input_shapes_attr.insert(
@ -211,9 +210,9 @@ string TFMultiShow::FormatInputShapes(const MultiGraphNodeProto& proto) const {
input_types.reserve(shape_count_vec.size());
for (const auto& s : shape_count_vec) {
std::tuple<int64, int64, int64> t = s.second;
input_types.push_back(strings::Printf(
"%s\t(run*%lld|defined*%lld)\texec_time: %s", s.first.c_str(),
std::get<1>(t), std::get<0>(t), FormatTime(std::get<2>(t)).c_str()));
input_types.push_back(absl::StrFormat(
"%s\t(run*%d|defined*%d)\texec_time: %s", s.first, std::get<1>(t),
std::get<0>(t), FormatTime(std::get<2>(t))));
}
return absl::StrJoin(input_types, "\n");
}

View File

@ -25,7 +25,6 @@ limitations under the License.
#include "tensorflow/c/checkpoint_reader.h"
#include "tensorflow/core/framework/graph.pb.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_node.h"
#include "tensorflow/core/profiler/internal/tfprof_node_show.h"
@ -45,8 +44,7 @@ class TFMultiShow {
virtual ~TFMultiShow() {}
virtual void AddNode(TFGraphNode* node) = 0;
virtual void Build() = 0;
virtual const MultiGraphNodeProto& Show(const string& prefix,
const Options& opts) final;
const MultiGraphNodeProto& Show(const string& prefix, const Options& opts);
protected:
virtual const ShowMultiNode* ShowInternal(const Options& opts,

View File

@ -16,10 +16,13 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_stats.h"
#include <stdio.h>
#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/lib/strings/str_util.h"
#include "tensorflow/core/platform/regexp.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)) {
CHECK(graph) << "Must at least have GraphDef";
printf("Parsing Inputs...\n");
absl::PrintF("Parsing Inputs...\n");
AddGraph(std::move(graph));
if (run_meta && run_meta->has_step_stats()) {
AddRunMeta(0, std::move(run_meta));
@ -80,13 +83,13 @@ TFStats::TFStats(const string& filename,
string str;
Status s = ReadFileToString(Env::Default(), filename, &str);
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;
}
ProfileProto profile;
if (!profile.ParseFromString(str)) {
fprintf(stderr, "Failed to parse profile\n");
absl::FPrintF(stderr, "Failed to parse profile\n");
return;
}
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);
} else {
fprintf(stderr, "Unknown command: %s\n", cmd.c_str());
absl::FPrintF(stderr, "Unknown command: %s\n", cmd);
return empty_graph_node_;
}
}
@ -178,14 +181,14 @@ const MultiGraphNodeProto& TFStats::ShowMultiGraphNode(
if (cmd == kCmds[2]) {
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 code_view_->Show(prefix, opts);
} else if (cmd == kCmds[3]) {
return op_view_->Show(prefix, opts);
} else {
fprintf(stderr, "Unknown command: %s\n", cmd.c_str());
absl::FPrintF(stderr, "Unknown command: %s\n", cmd);
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?)
auto prefix_pos = node_input.find(":");
if (prefix_pos != node_input.npos) {
std::vector<string> input_parts = str_util::Split(node_input, ":");
CHECK(input_parts.size() == 2)
std::vector<string> input_parts = absl::StrSplit(node_input, ':');
DCHECK(input_parts.size() == 2)
<< "Unknown NodeDef.input format: " << node_input;
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;
}
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) {
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;
}
if (steps_.find(step) == steps_.end()) {
@ -349,18 +352,18 @@ void TFStats::WriteProfile(const string& filename) {
SerializeToString(&content);
Status s = WriteStringToFile(Env::Default(), filename, content);
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 {
if (opts.step >= 0 && steps_.find(opts.step) == steps_.end()) {
fprintf(stderr,
"Options -step=%lld not found.\nAvailable steps: ", opts.step);
absl::FPrintF(stderr,
"Options -step=%d not found.\nAvailable steps: ", opts.step);
for (int64 s : steps_) {
fprintf(stderr, "%lld ", s);
absl::FPrintF(stderr, "%d ", s);
}
fprintf(stderr, "\n");
absl::FPrintF(stderr, "\n");
return false;
}
return true;

View File

@ -33,7 +33,6 @@ limitations under the License.
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/step_stats.pb.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_graph.h"
#include "tensorflow/core/profiler/internal/tfprof_node.h"

View File

@ -15,6 +15,9 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_tensor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
namespace tensorflow {
namespace tfprof {
void TFProfTensor::Display(string* formatted_str,
@ -22,7 +25,7 @@ void TFProfTensor::Display(string* formatted_str,
if (formatted_str) {
if (formatted_str_.length() >= kTFProfTenosrMaxDisplayLen) {
*formatted_str =
strings::StrCat(formatted_str_, "...omitted from display\n\n");
absl::StrCat(formatted_str_, "...omitted from display\n\n");
} else {
*formatted_str = formatted_str_;
}
@ -68,7 +71,7 @@ void TFProfTensor::Build() {
break;
}
default: {
fprintf(stderr, "Not Supported type %d\n", tensor_->dtype());
absl::FPrintF(stderr, "Not Supported type %d\n", tensor_->dtype());
break;
}
}

View File

@ -24,10 +24,10 @@ limitations under the License.
#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/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"
namespace tensorflow {
@ -56,23 +56,21 @@ class TFProfTensor {
std::ostringstream sstream;
sstream << value;
if (typeid(value) == typeid(double)) {
double double_val;
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
double double_val = 0.0;
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
dim->add_value_double(double_val);
formatted_str_ += strings::Printf(
"%.2f ", dim->value_double(dim->value_double_size() - 1));
absl::StrAppendFormat(&formatted_str_, "%.2f ",
dim->value_double(dim->value_double_size() - 1));
} else if (typeid(value) == typeid(int64)) {
int64 int64_val;
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
int64 int64_val = 0;
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
dim->add_value_int64(int64_val);
formatted_str_ += strings::Printf(
"%lld ",
static_cast<int64>(dim->value_int64(dim->value_int64_size() - 1)));
absl::StrAppendFormat(&formatted_str_, "%d ",
dim->value_int64(dim->value_int64_size() - 1));
} else if (typeid(value) == typeid(string)) {
dim->add_value_str(sstream.str());
formatted_str_ =
strings::StrCat(formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1) + "' ");
absl::StrAppend(&formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1), "' ");
} else {
CHECK(false) << "Unsupported type: " << typeid(value).name();
}
@ -91,23 +89,21 @@ class TFProfTensor {
sstream << values[nstart];
if (typeid(values[nstart]) == typeid(double)) {
double double_val;
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
double double_val = 0.0;
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
dim->add_value_double(double_val);
formatted_str_ += strings::Printf(
"%.2f ", dim->value_double(dim->value_double_size() - 1));
absl::StrAppendFormat(&formatted_str_, "%.2f ",
dim->value_double(dim->value_double_size() - 1));
} else if (typeid(values[nstart]) == typeid(int64)) {
int64 int64_val;
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
int64 int64_val = 0;
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
dim->add_value_int64(int64_val);
formatted_str_ += strings::Printf(
"%lld ",
static_cast<int64>(dim->value_int64(dim->value_int64_size() - 1)));
absl::StrAppendFormat(&formatted_str_, "%d ",
dim->value_int64(dim->value_int64_size() - 1));
} else if (typeid(values[nstart]) == typeid(string)) {
dim->add_value_str(sstream.str());
formatted_str_ =
strings::StrCat(formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1) + "' ");
absl::StrAppend(&formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1), "' ");
} else {
CHECK(false) << "Unsupported type: " << typeid(values[nstart]).name();
}
@ -119,23 +115,23 @@ class TFProfTensor {
sstream << values[nstart];
if (typeid(values[nstart]) == typeid(double)) {
double double_val;
CHECK(strings::safe_strtod(sstream.str().c_str(), &double_val));
double double_val = 0.0;
CHECK(absl::SimpleAtod(sstream.str(), &double_val)); // Crash OK
dim->add_value_double(double_val);
formatted_str_ += strings::Printf(
"%.2f ", dim->value_double(dim->value_double_size() - 1));
absl::StrAppendFormat(
&formatted_str_, "%.2f ",
dim->value_double(dim->value_double_size() - 1));
} else if (typeid(values[nstart]) == typeid(int64)) {
int64 int64_val;
CHECK(strings::safe_strto64(sstream.str().c_str(), &int64_val));
int64 int64_val = 0;
CHECK(absl::SimpleAtoi(sstream.str(), &int64_val)); // Crash OK
dim->add_value_int64(int64_val);
formatted_str_ += strings::Printf(
"%lld ", static_cast<int64>(
dim->value_int64(dim->value_int64_size() - 1)));
absl::StrAppendFormat(
&formatted_str_, "%d ",
dim->value_int64(dim->value_int64_size() - 1));
} else if (typeid(values[nstart]) == typeid(string)) {
dim->add_value_str(sstream.str());
formatted_str_ = strings::StrCat(
formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1) + "' ");
absl::StrAppend(&formatted_str_, "'",
dim->value_str(dim->value_str_size() - 1), "' ");
} else {
CHECK(false) << "Unsupported type: "
<< typeid(values[nstart]).name();
@ -158,7 +154,7 @@ class TFProfTensor {
void GetValueVec(std::vector<U>* value_vec) {
// TODO(xpan): Address the huge tensor problem.
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>();
for (int64 i = 0; i < tensor_->NumElements(); i++) {

View File

@ -17,9 +17,9 @@ limitations under the License.
#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/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
namespace tensorflow {
@ -27,15 +27,15 @@ namespace tfprof {
namespace {
int kMaxDisplayedMemNode = 10;
string GetTimeDevName(const string& dev) {
std::string GetTimeDevName(const std::string& dev) {
if (dev.find("stream") != dev.npos) {
return strings::StrCat("Op execution threads: ", dev);
return absl::StrCat("Op execution threads: ", dev);
} else {
return strings::StrCat("Op scheduling threads: ", dev);
return absl::StrCat("Op scheduling threads: ", dev);
}
}
string GetMemoryLaneName(const string& dev) {
return strings::StrCat("mem usage on:", dev);
std::string GetMemoryLaneName(const std::string& dev) {
return absl::StrCat("mem usage on:", dev);
}
} // namespace
@ -104,7 +104,7 @@ void ChromeTraceFormatter::EmitCounter(
Json::Value args2(Json::objectValue);
// Need to reserve the same args for all locations.
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;
for (auto it = tensor_mem.rbegin(); it != tensor_mem.rend(); ++it) {
@ -112,14 +112,14 @@ void ChromeTraceFormatter::EmitCounter(
if (bytes < it->first || count >= kMaxDisplayedMemNode) {
break;
}
args2[strings::Printf("Top Allocation %02d", count)] =
Json::Value(strings::StrCat(it->first / 1000000.0, " MB from ", t));
args2[absl::StrFormat("Top Allocation %02d", count)] =
Json::Value(absl::StrCat(it->first / 1000000.0, " MB from ", t));
++count;
bytes -= it->first;
}
}
args2[strings::StrCat("Not Displayed")] =
Json::Value(strings::Printf("%.2f MB", bytes / 1000000.0));
args2[std::string("Not Displayed")] =
Json::Value(absl::StrFormat("%.2f MB", bytes / 1000000.0));
event2["args"] = args2;
events_.push_back(event2);
}
@ -136,10 +136,10 @@ string ChromeTraceFormatter::Format() {
Json::FastWriter writer;
string trace_str = writer.write(trace);
if (trace_str.length() > 200 * 1024 * 1024) {
fprintf(stderr,
"Trace file is over 200MB. Chrome might not be able to "
"display it. Consider to use filters (e.g. -min_micros "
"> 1000 or -op_type .*gpu:0.* to reduce the size.\n");
absl::FPrintF(stderr,
"Trace file is over 200MB. Chrome might not be able to "
"display it. Consider to use filters (e.g. -min_micros "
"> 1000 or -op_type .*gpu:0.* to reduce the size.\n");
}
return trace_str;
}
@ -235,7 +235,7 @@ void Timeline::GenerateGraphTimeline(const std::vector<GraphNode*>& gnodes) {
}
AllocateLanes();
fprintf(stdout, "generating trace file.\n");
absl::FPrintF(stdout, "generating trace file.\n");
int64 flow_id = 1;
for (const auto& process : alloc_nodes_) {
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);
}
if (IsPlacedOnAccelerator(dev.first)) {
fprintf(stdout, "%s peak memory: %.2f MB\n", dev.first.c_str(),
max_bytes_in_use / 1000000.0);
absl::FPrintF(stdout, "%s peak memory: %.2f MB\n", dev.first,
max_bytes_in_use / 1000000.0);
}
}
OutputTimeline();
@ -321,21 +321,23 @@ void Timeline::GenerateCodeTimeline(const CodeNode* node) {
}
void Timeline::OutputTimeline() {
string outfile = strings::Printf("%s_%lld", outfile_.c_str(), step());
std::string outfile = absl::StrFormat("%s_%d", outfile_, step());
Status s =
WriteStringToFile(Env::Default(), outfile, chrome_formatter_.Format());
if (!s.ok()) {
fprintf(stderr, "Failed to write timeline file: %s\nError: %s\n",
outfile.c_str(), s.ToString().c_str());
absl::FPrintF(stderr, "Failed to write timeline file: %s\nError: %s\n",
outfile, s.ToString());
return;
}
fprintf(stdout, "\n******************************************************\n");
fprintf(stdout,
"Timeline file is written to %s.\n"
"Open a Chrome browser, enter URL chrome://tracing and "
"load the timeline file.",
outfile.c_str());
fprintf(stdout, "\n******************************************************\n");
absl::FPrintF(stdout,
"\n******************************************************\n");
absl::FPrintF(stdout,
"Timeline file is written to %s.\n"
"Open a Chrome browser, enter URL chrome://tracing and "
"load the timeline file.",
outfile);
absl::FPrintF(stdout,
"\n******************************************************\n");
fflush(stdout);
}

View File

@ -16,10 +16,10 @@ limitations under the License.
#ifndef 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 "tensorflow/core/framework/graph.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/protobuf/config.pb.h"
@ -143,7 +143,7 @@ class Timeline {
void EmitTreeNode(const Node* node, int64 start_time, int64 duration,
int64 depth, std::set<int64>* visited_depth) {
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);
}

View File

@ -16,14 +16,16 @@ limitations under the License.
#include "tensorflow/core/profiler/internal/tfprof_utils.h"
#include <stdio.h>
#include <algorithm>
#include <memory>
#include <set>
#include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/regexp.h"
@ -31,33 +33,33 @@ namespace tensorflow {
namespace tfprof {
string FormatNumber(int64 n) {
if (n < 1000) {
return strings::Printf("%lld", n);
return absl::StrFormat("%d", n);
} else if (n < 1000000) {
return strings::Printf("%.2fk", n / 1000.0);
return absl::StrFormat("%.2fk", n / 1000.0);
} else if (n < 1000000000) {
return strings::Printf("%.2fm", n / 1000000.0);
return absl::StrFormat("%.2fm", n / 1000000.0);
} else {
return strings::Printf("%.2fb", n / 1000000000.0);
return absl::StrFormat("%.2fb", n / 1000000000.0);
}
}
string FormatTime(int64 micros) {
if (micros < 1000) {
return strings::Printf("%lldus", micros);
return absl::StrFormat("%dus", micros);
} else if (micros < 1000000) {
return strings::Printf("%.2fms", micros / 1000.0);
return absl::StrFormat("%.2fms", micros / 1000.0);
} else {
return strings::Printf("%.2fsec", micros / 1000000.0);
return absl::StrFormat("%.2fsec", micros / 1000000.0);
}
}
string FormatMemory(int64 bytes) {
if (bytes < 1000) {
return strings::Printf("%lldB", bytes);
return absl::StrFormat("%dB", bytes);
} else if (bytes < 1000000) {
return strings::Printf("%.2fKB", bytes / 1000.0);
return absl::StrFormat("%.2fKB", bytes / 1000.0);
} 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(
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) {
@ -114,8 +116,7 @@ bool StringToBool(StringPiece str, bool* value) {
tensorflow::Status ParseCmdLine(const string& line, string* cmd,
tensorflow::tfprof::Options* opts) {
std::vector<string> pieces =
str_util::Split(line, ' ', str_util::SkipEmpty());
std::vector<string> pieces = absl::StrSplit(line, ' ', absl::SkipEmpty());
std::vector<string> cmds_str(kCmds, kCmds + sizeof(kCmds) / sizeof(*kCmds));
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) {
if (pieces[i] == string(tensorflow::tfprof::kOptions[0])) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[2]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[3]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[4]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[5]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[6]) {
if (pieces.size() <= i + 1 ||
!strings::safe_strto64(pieces[i + 1],
&opts->min_accelerator_micros)) {
!absl::SimpleAtoi(pieces[i + 1], &opts->min_accelerator_micros)) {
return ReturnError(pieces, i);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[7]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[8]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[9]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[10]) {
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);
}
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[11]) {
if (pieces.size() <= i + 1 ||
!strings::safe_strto64(pieces[i + 1], &opts->step)) {
!absl::SimpleAtoi(pieces[i + 1], &opts->step)) {
return ReturnError(pieces, i);
}
++i;
@ -215,39 +215,39 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
if (pieces.size() <= i + 1) {
return ReturnError(pieces, i);
}
opts->account_type_regexes = str_util::Split(StripQuote(pieces[i + 1]),
',', str_util::SkipEmpty());
opts->account_type_regexes =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[14]) {
if (pieces.size() <= i + 1) {
return ReturnError(pieces, i);
}
opts->start_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
str_util::SkipEmpty());
opts->start_name_regexes =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[15]) {
if (pieces.size() <= i + 1) {
return ReturnError(pieces, i);
}
opts->trim_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
str_util::SkipEmpty());
opts->trim_name_regexes =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[16]) {
if (pieces.size() <= i + 1) {
return ReturnError(pieces, i);
}
opts->show_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
str_util::SkipEmpty());
opts->show_name_regexes =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
++i;
} else if (pieces[i] == tensorflow::tfprof::kOptions[17]) {
if (pieces.size() <= i + 1) {
return ReturnError(pieces, i);
}
opts->hide_name_regexes = str_util::Split(StripQuote(pieces[i + 1]), ',',
str_util::SkipEmpty());
opts->hide_name_regexes =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
++i;
} 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) {
opts->account_displayed_op_only = true;
} else if (!StringToBool(pieces[i + 1],
@ -262,8 +262,8 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
}
std::set<string> shown_set(kShown,
kShown + sizeof(kShown) / sizeof(*kShown));
std::vector<string> requested_vector = str_util::Split(
StripQuote(pieces[i + 1]), ',', str_util::SkipEmpty());
std::vector<string> requested_vector =
absl::StrSplit(StripQuote(pieces[i + 1]), ',', absl::SkipEmpty());
std::set<string> requested_set(requested_vector.begin(),
requested_vector.end());
for (const string& requested : requested_set) {
@ -290,13 +290,13 @@ tensorflow::Status ParseCmdLine(const string& line, string* cmd,
}
void PrintHelp() {
printf(
absl::PrintF(
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
"README.md for profiler tutorial.\n");
printf(
absl::PrintF(
"See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/"
"g3doc/command_line.md for command line tool tutorial.\n");
printf(
absl::PrintF(
"profiler --profile_path=<ProfileProto binary file> # required\n"
"\nOr:\n\n"
"profiler --graph_path=<GraphDef proto file> "
@ -305,7 +305,7 @@ void PrintHelp() {
"# Contains runtime info. Optional.\n"
" --run_log_path=<OpLogProto proto file> "
"# 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"
" scope: Organize profiles based on name scopes.\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]) {
helps.push_back(kBytes);
} else if (s == kShown[1]) {
helps.push_back(strings::StrCat(kTotalMicrosHelp, "\n", kCPUHelp, "\n",
kAccMicrosHelp));
helps.push_back(
absl::StrCat(kTotalMicrosHelp, "\n", kCPUHelp, "\n", kAccMicrosHelp));
} else if (s == kShown[2]) {
helps.push_back(kParams);
} else if (s == kShown[3]) {
@ -422,8 +422,8 @@ string QueryDoc(const string& cmd, const Options& opts) {
helps.push_back("Unknown select: " + s);
}
}
return strings::StrCat("\nDoc:\n", cmd_help, "\n", absl::StrJoin(helps, "\n"),
"\n\n");
return absl::StrCat("\nDoc:\n", cmd_help, "\n", absl::StrJoin(helps, "\n"),
"\n\n");
}
} // namespace tfprof

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/strings/str_cat.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/env_time.h"
#include "tensorflow/core/platform/notification.h"
@ -81,7 +82,7 @@ TEST(RecorderTest, Multithreaded) {
uint64 start_time = Env::Default()->NowNanos();
uint64 end_time = start_time + kNanosInSec;
TraceMeRecorder::Record({/*activity_id=*/j++,
/*name=*/strings::StrCat(i), start_time,
/*name=*/absl::StrCat(i), start_time,
end_time});
};
thread_count.fetch_add(1, std::memory_order_relaxed);

View File

@ -15,19 +15,21 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "linenoise.h"
#include "tensorflow/c/c_api.h"
#include "tensorflow/c/checkpoint_reader.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/types.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/init_main.h"
#include "tensorflow/core/platform/protobuf.h"
@ -93,7 +95,7 @@ int Run(int argc, char** argv) {
string FLAGS_select = "micros";
string FLAGS_output = "";
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 = {
@ -135,31 +137,31 @@ int Run(int argc, char** argv) {
string usage = Flags::Usage(argv[0], flag_list);
bool parse_ok = Flags::Parse(&argc, argv, flag_list);
if (!parse_ok) {
printf("%s", usage.c_str());
absl::PrintF("%s", usage);
return (2);
}
port::InitMain(argv[0], &argc, &argv);
if (!FLAGS_profile_path.empty() &&
(!FLAGS_graph_path.empty() || !FLAGS_run_meta_path.empty())) {
fprintf(stderr,
"--profile_path is set, do not set --graph_path or "
"--run_meta_path\n");
absl::FPrintF(stderr,
"--profile_path is set, do not set --graph_path or "
"--run_meta_path\n");
return 1;
}
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 =
str_util::Split(FLAGS_start_name_regexes, ',', str_util::SkipEmpty());
absl::StrSplit(FLAGS_start_name_regexes, ',', absl::SkipEmpty());
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 =
str_util::Split(FLAGS_show_name_regexes, ',', str_util::SkipEmpty());
absl::StrSplit(FLAGS_show_name_regexes, ',', absl::SkipEmpty());
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 =
str_util::Split(FLAGS_select, ',', str_util::SkipEmpty());
absl::StrSplit(FLAGS_select, ',', absl::SkipEmpty());
string output_type;
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;
TF_Status* status = TF_NewStatus();
if (!FLAGS_checkpoint_path.empty()) {
ckpt_reader.reset(
new checkpoint::CheckpointReader(FLAGS_checkpoint_path, status));
if (TF_GetCode(status) != TF_OK) {
fprintf(stderr, "%s\n", TF_Message(status));
absl::FPrintF(stderr, "%s\n", TF_Message(status));
TF_DeleteStatus(status);
return 1;
}
@ -201,15 +203,14 @@ int Run(int argc, char** argv) {
if (!FLAGS_profile_path.empty()) {
tf_stat.reset(new TFStats(FLAGS_profile_path, std::move(ckpt_reader)));
} else {
printf(
absl::PrintF(
"Try to use a single --profile_path instead of "
"graph_path,op_log_path,run_meta_path\n");
std::unique_ptr<GraphDef> graph(new GraphDef());
if (!FLAGS_graph_path.empty()) {
s = ReadProtoFile(Env::Default(), FLAGS_graph_path, graph.get(), false);
if (!s.ok()) {
fprintf(stderr, "Failed to read graph_path: %s\n",
s.ToString().c_str());
absl::FPrintF(stderr, "Failed to read graph_path: %s\n", s.ToString());
return 1;
}
}
@ -219,12 +220,11 @@ int Run(int argc, char** argv) {
string op_log_str;
s = ReadFileToString(Env::Default(), FLAGS_op_log_path, &op_log_str);
if (!s.ok()) {
fprintf(stderr, "Failed to read op_log_path: %s\n",
s.ToString().c_str());
absl::FPrintF(stderr, "Failed to read op_log_path: %s\n", s.ToString());
return 1;
}
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;
}
}
@ -232,18 +232,19 @@ int Run(int argc, char** argv) {
std::move(ckpt_reader)));
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) {
std::unique_ptr<RunMetadata> run_meta(new RunMetadata());
s = ReadProtoFile(Env::Default(), run_meta_files[i], run_meta.get(),
true);
if (!s.ok()) {
fprintf(stderr, "Failed to read run_meta_path %s. Status: %s\n",
run_meta_files[i].c_str(), s.ToString().c_str());
absl::FPrintF(stderr, "Failed to read run_meta_path %s. Status: %s\n",
run_meta_files[i], s.ToString());
return 1;
}
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> ");
if (line == nullptr) {
if (!looped) {
fprintf(stderr,
"Cannot start interative shell, "
"use 'bazel-bin' instead of 'bazel run'.\n");
absl::FPrintF(stderr,
"Cannot start interative shell, "
"use 'bazel-bin' instead of 'bazel run'.\n");
}
break;
}
@ -291,7 +292,7 @@ int Run(int argc, char** argv) {
free(line);
if (line_s.empty()) {
printf("%s", opts.ToString().c_str());
absl::PrintF("%s", opts.ToString());
continue;
}
linenoiseHistoryAdd(line_s.c_str());
@ -300,7 +301,7 @@ int Run(int argc, char** argv) {
Options new_opts = opts;
Status s = ParseCmdLine(line_s, &cmd, &new_opts);
if (!s.ok()) {
fprintf(stderr, "E: %s\n", s.ToString().c_str());
absl::FPrintF(stderr, "E: %s\n", s.ToString());
continue;
}
if (cmd == kCmds[5]) {

View File

@ -31,5 +31,6 @@ cc_library(
"//tensorflow/core/profiler:profiler_service_proto_cc",
"//tensorflow/core/profiler/lib:profiler_lib",
"//tensorflow/core/profiler/lib:profiler_session",
"@com_google_absl//absl/strings",
],
)

View File

@ -33,6 +33,7 @@ cc_library(
"//tensorflow/core:protos_all_cc",
"//tensorflow/core/profiler:op_profile_proto_cc",
"//tensorflow/core/profiler:profiler_service_proto_cc",
"@com_google_absl//absl/strings",
],
)
@ -43,6 +44,8 @@ cc_library(
deps = [
"//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@jsoncpp_git//:jsoncpp",
],
)

View File

@ -21,12 +21,12 @@ limitations under the License.
#include "grpcpp/grpcpp.h"
#include "absl/strings/escaping.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/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.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_service.grpc.pb.h"
#include "tensorflow/core/profiler/rpc/client/dump_tpu_profile.h"
@ -48,10 +48,10 @@ string GetCurrentTimeStampAsString() {
Status ValidateHostPortPair(const string& host_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 '/',
// 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()) {
return errors::InvalidArgument("Could not interpret \"", host_port,
"\" as a host-port pair.");
@ -180,7 +180,7 @@ Status MaybeCreateEmptyEventFile(const tensorflow::string& logdir) {
std::vector<string> children;
TF_RETURN_IF_ERROR(Env::Default()->GetChildren(logdir, &children));
for (const string& child : children) {
if (str_util::EndsWith(child, kProfileEmptySuffix)) {
if (absl::EndsWith(child, kProfileEmptySuffix)) {
return Status::OK();
}
}
@ -201,8 +201,7 @@ Status StartTracing(const tensorflow::string& service_addr,
constexpr char kProfilePluginDirectory[] = "plugins/profile/";
tensorflow::string repository_root =
io::JoinPath(logdir, kProfilePluginDirectory);
std::vector<tensorflow::string> hostnames =
tensorflow::str_util::Split(workers_list, ",");
std::vector<tensorflow::string> hostnames = absl::StrSplit(workers_list, ',');
TF_RETURN_IF_ERROR(MaybeCreateEmptyEventFile(logdir));

View File

@ -19,11 +19,11 @@ limitations under the License.
#include <ctime>
#include <vector>
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/io/compression.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/protobuf.h"
// Windows.h #defines ERROR, but it is also used in
@ -43,8 +43,6 @@ namespace {
using ::tensorflow::io::JoinPath;
using ::tensorflow::protobuf::util::JsonOptions;
using ::tensorflow::protobuf::util::MessageToJsonString;
using ::tensorflow::str_util::EndsWith;
using ::tensorflow::strings::StrCat;
constexpr char kJsonOpProfileFileName[] = "op_profile.json";
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,
const string& encoded_trace, std::ostream* os) {
string proto_path =
JoinPath(run_dir, StrCat(host_prefix, kProtoTraceFileName));
JoinPath(run_dir, absl::StrCat(host_prefix, kProtoTraceFileName));
TF_RETURN_IF_ERROR(
WriteStringToFile(Env::Default(), proto_path, encoded_trace));
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.ParseFromString(encoded_trace);
if (os) {
@ -94,7 +93,8 @@ Status DumpOpProfileToLogDirectory(StringPiece run_dir,
const string& host_prefix,
const op_profile::Profile& profile,
std::ostream* os) {
string path = JoinPath(run_dir, StrCat(host_prefix, kJsonOpProfileFileName));
string path =
JoinPath(run_dir, absl::StrCat(host_prefix, kJsonOpProfileFileName));
string json;
JsonOptions options;
options.always_print_primitive_fields = true;
@ -116,10 +116,10 @@ Status DumpToolDataToLogDirectory(StringPiece run_dir,
const ProfileToolData& tool,
std::ostream* os) {
// Don't save the intermediate results for combining the per host tool data.
if (EndsWith(tool.name(), kFlatProfilerFileName) ||
EndsWith(tool.name(), kTfStatsHelperSuffix))
if (absl::EndsWith(tool.name(), kFlatProfilerFileName) ||
absl::EndsWith(tool.name(), kTfStatsHelperSuffix))
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()));
if (os) {
*os << "Dumped tool data for " << tool.name() << " to " << path
@ -135,7 +135,7 @@ Status WriteTensorboardTPUProfile(const string& logdir, const string& run,
const ProfileResponse& response,
std::ostream* os) {
// 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);
*os << "Creating directory: " << profile_run_dir;
TF_RETURN_IF_ERROR(Env::Default()->RecursivelyCreateDir(profile_run_dir));

View File

@ -15,9 +15,9 @@ limitations under the License.
#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 "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/protobuf/trace_events.pb.h"
namespace tensorflow {
@ -26,13 +26,10 @@ namespace profiler {
namespace client {
namespace {
using ::tensorflow::strings::Appendf;
using ::tensorflow::strings::StrAppend;
constexpr double kPicosPerMicro = 1000000.0;
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.
@ -43,17 +40,18 @@ void AddResourceMetadata(uint32 device_id,
uint32 resource_id = pair.first;
const Resource &resource = *pair.second;
if (!resource.name().empty()) {
Appendf(json,
R"({"ph":"M","pid":%u,"tid":%u,)"
R"("name":"thread_name","args":{)",
device_id, resource_id);
absl::StrAppendFormat(json,
R"({"ph":"M","pid":%u,"tid":%u,)"
R"("name":"thread_name","args":{)",
device_id, resource_id);
AppendEscapedName(json, resource.name());
Appendf(json, "}},");
absl::StrAppend(json, "}},");
}
Appendf(json,
R"({"ph":"M","pid":%u,"tid":%u,)"
R"("name":"thread_sort_index","args":{"sort_index":%u}},)",
device_id, resource_id, resource_id);
absl::StrAppendFormat(
json,
R"({"ph":"M","pid":%u,"tid":%u,)"
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;
const Device &device = *pair.second;
if (!device.name().empty()) {
Appendf(json,
R"({"ph":"M","pid":%u,"name":"process_name",)"
R"("args":{)",
device_id);
absl::StrAppendFormat(json,
R"({"ph":"M","pid":%u,"name":"process_name",)"
R"("args":{)",
device_id);
AppendEscapedName(json, device.name());
StrAppend(json, "}},");
absl::StrAppend(json, "}},");
}
Appendf(json,
R"({"ph":"M","pid":%u,"name":"process_sort_index",)"
R"("args":{"sort_index":%u}},)",
device_id, device_id);
absl::StrAppendFormat(json,
R"({"ph":"M","pid":%u,"name":"process_sort_index",)"
R"("args":{"sort_index":%u}},)",
device_id, device_id);
// Convert to a std::map so that devices are sorted by the device id.
std::map<uint32, const Resource *> sorted_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) {
Appendf(json, R"({"pid":%u,"tid":%u,"ts":%.5f,)", event.device_id(),
event.resource_id(), event.timestamp_ps() / kPicosPerMicro);
absl::StrAppendFormat(json, R"({"pid":%u,"tid":%u,"ts":%.5f,)",
event.device_id(), event.resource_id(),
event.timestamp_ps() / kPicosPerMicro);
AppendEscapedName(json, event.name());
StrAppend(json, ",");
absl::StrAppend(json, ",");
if (event.duration_ps() > 0) {
Appendf(json, R"("ph":"X","dur":%.5f},)",
event.duration_ps() / kPicosPerMicro);
absl::StrAppendFormat(json, R"("ph":"X","dur":%.5f},)",
event.duration_ps() / kPicosPerMicro);
} else {
StrAppend(json, R"("ph":"i","s":"t"},)");
absl::StrAppend(json, R"("ph":"i","s":"t"},)");
}
}
} // namespace
string TraceEventsToJson(const Trace &trace) {
string json;
Appendf(
&json, R"({"displayTimeUnit":"ns","metadata":{"highres-ticks":true},)");
Appendf(&json, R"("traceEvents":[)");
string json = R"({"displayTimeUnit":"ns","metadata":{"highres-ticks":true},)"
R"("traceEvents":[)";
// Convert to a std::map so that devices are sorted by the device id.
std::map<uint32, const Device *> sorted_devices;
for (const auto &pair : trace.devices()) {
@ -113,7 +110,7 @@ string TraceEventsToJson(const Trace &trace) {
AddTraceEvent(event, &json);
}
// Add one fake event to avoid dealing with no-trailing-comma rule.
Appendf(&json, R"({}]})");
absl::StrAppend(&json, "{}]}");
return json;
}

View File

@ -19,7 +19,7 @@ limitations under the License.
#include <utility>
#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/profiler/lib/profiler_session.h"
#include "tensorflow/core/profiler/profiler_service.grpc.pb.h"
@ -31,7 +31,7 @@ namespace tensorflow {
std::unique_ptr<Thread> StartProfilerServer(int32 port) {
Env* env = Env::Default();
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 =
CreateProfilerService();
::grpc::ServerBuilder builder;

View File

@ -15,10 +15,9 @@ limitations under the License.
#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/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"
namespace tensorflow {
@ -28,7 +27,7 @@ string KeyValueToStr(const std::map<string, string>& kv_map) {
std::vector<string> kv_vec;
kv_vec.reserve(kv_map.size());
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, ",");
}
@ -50,9 +49,8 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
if (output_types.find(output_opt) == output_types.end()) {
return tensorflow::Status(
tensorflow::error::INVALID_ARGUMENT,
strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n",
output_opt.c_str(),
absl::StrJoin(output_types, ",").c_str()));
absl::StrFormat("E.g. Unknown output type: %s, Valid types: %s\n",
output_opt, absl::StrJoin(output_types, ",")));
}
*output_type = output_opt;
} else {
@ -60,12 +58,11 @@ tensorflow::Status ParseOutput(const string& output_opt, string* output_type,
if (output_types.find(*output_type) == output_types.end()) {
return tensorflow::Status(
tensorflow::error::INVALID_ARGUMENT,
strings::Printf("E.g. Unknown output type: %s, Valid types: %s\n",
output_type->c_str(),
absl::StrJoin(output_types, ",").c_str()));
absl::StrFormat("E.g. Unknown output type: %s, Valid types: %s\n",
*output_type, absl::StrJoin(output_types, ",")));
}
kv_split = str_util::Split(output_opt.substr(opt_split + 1), ",",
str_util::SkipEmpty());
kv_split = absl::StrSplit(output_opt.substr(opt_split + 1), ",",
absl::SkipEmpty());
}
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) {
const std::vector<string> kv =
str_util::Split(kv_str, "=", str_util::SkipEmpty());
absl::StrSplit(kv_str, "=", absl::SkipEmpty());
if (kv.size() < 2) {
return tensorflow::Status(
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()) {
return tensorflow::Status(
tensorflow::error::INVALID_ARGUMENT,
strings::Printf("Unrecognized options %s for output_type: %s\n",
kv[0].c_str(), output_type->c_str()));
absl::StrFormat("Unrecognized options %s for output_type: %s\n",
kv[0], *output_type));
}
const std::vector<string> kv_without_key(kv.begin() + 1, kv.end());
(*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()) {
return tensorflow::Status(
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",
output_type->c_str(), output_type->c_str(),
opt.c_str()));
*output_type, *output_type, opt));
}
}
return tensorflow::Status::OK();
@ -130,8 +126,8 @@ tensorflow::Status Options::FromProtoStr(const string& opts_proto_str,
if (!opts_pb.ParseFromString(opts_proto_str)) {
return tensorflow::Status(
tensorflow::error::INTERNAL,
strings::StrCat("Failed to parse option string from Python API: ",
opts_proto_str));
absl::StrCat("Failed to parse option string from Python API: ",
opts_proto_str));
}
string output_type;
@ -141,11 +137,12 @@ tensorflow::Status Options::FromProtoStr(const string& opts_proto_str,
if (!s.ok()) return s;
if (!opts_pb.dump_to_file().empty()) {
fprintf(stderr,
"-dump_to_file option is deprecated. "
"Please use -output file:outfile=<filename>\n");
fprintf(stderr, "-output %s is overwritten with -output file:outfile=%s\n",
opts_pb.output().c_str(), opts_pb.dump_to_file().c_str());
absl::FPrintF(stderr,
"-dump_to_file option is deprecated. "
"Please use -output file:outfile=<filename>\n");
absl::FPrintF(stderr,
"-output %s is overwritten with -output file:outfile=%s\n",
opts_pb.output(), opts_pb.dump_to_file());
output_type = kOutput[2];
output_options.clear();
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();
}
string Options::ToString() const {
const string s = strings::Printf(
std::string Options::ToString() const {
// 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%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"
@ -196,20 +194,28 @@ string Options::ToString() const {
"%-28s%s\n"
"%-28s%s\n"
"%-28s%s:%s\n",
kOptions[0], max_depth, kOptions[1], min_bytes, kOptions[2],
min_peak_bytes, kOptions[3], min_residual_bytes, kOptions[4],
min_output_bytes, kOptions[5], min_micros, kOptions[6],
min_accelerator_micros, kOptions[7], min_cpu_micros, kOptions[8],
min_params, kOptions[9], min_float_ops, kOptions[10], min_occurrence,
kOptions[11], step, kOptions[12], order_by.c_str(), kOptions[13],
absl::StrJoin(account_type_regexes, ",").c_str(), kOptions[14],
absl::StrJoin(start_name_regexes, ",").c_str(), kOptions[15],
absl::StrJoin(trim_name_regexes, ",").c_str(), kOptions[16],
absl::StrJoin(show_name_regexes, ",").c_str(), kOptions[17],
absl::StrJoin(hide_name_regexes, ",").c_str(), kOptions[18],
(account_displayed_op_only ? "true" : "false"), kOptions[19],
absl::StrJoin(select, ",").c_str(), kOptions[20], output_type.c_str(),
KeyValueToStr(output_options).c_str());
kOptions[0], max_depth,
kOptions[1], min_bytes,
kOptions[2], min_peak_bytes,
kOptions[3], min_residual_bytes,
kOptions[4], min_output_bytes,
kOptions[5], min_micros,
kOptions[6], min_accelerator_micros,
kOptions[7], min_cpu_micros,
kOptions[8], min_params,
kOptions[9], min_float_ops,
kOptions[10], min_occurrence,
kOptions[11], step,
kOptions[12], order_by,
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;
}