From 7d6198ed425b8decb16e7e620b20f7fff2e427a2 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 16:52:27 -0800 Subject: [PATCH] Print usage count if it's rarely used. PiperOrigin-RevId: 597083184 --- .../compiler/cpp/tools/analyze_profile_proto.cc | 3 ++- .../compiler/cpp/tools/analyze_profile_proto_test.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc index 5621d1922b..ce6211c6ea 100644 --- a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc +++ b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc @@ -440,7 +440,8 @@ static absl::StatusOr AnalyzeProfileProto( stream << " " << analysis.presence << "_PRESENT"; } if (analysis.usage != PDProtoScale::kDefault) { - stream << " " << analysis.usage << "_USED"; + stream << " " << analysis.usage << "_USED(" + << analysis.usage_count << ")"; } } if (optimized != PDProtoOptimization::kNone) { diff --git a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc index 35eab5bb0c..a288702f82 100644 --- a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc +++ b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc @@ -184,12 +184,12 @@ TEST(AnalyzeProfileProtoTest, PrintStatistics) { options.pool = DescriptorPool::generated_pool(); EXPECT_STREQ(AnalyzeToText(info, options).c_str(), R"(Message google::protobuf::compiler::tools::AnalyzeThis - int32 id: RARELY_USED - string optional_string: RARELY_USED - string[] repeated_string: LIKELY_PRESENT RARELY_USED - AnalyzeChild optional_child: LIKELY_PRESENT RARELY_USED LAZY - AnalyzeChild[] repeated_child: LIKELY_PRESENT RARELY_USED - Nested nested: RARELY_USED + int32 id: RARELY_USED(100) + string optional_string: RARELY_USED(100) + string[] repeated_string: LIKELY_PRESENT RARELY_USED(100) + AnalyzeChild optional_child: LIKELY_PRESENT RARELY_USED(1) LAZY + AnalyzeChild[] repeated_child: LIKELY_PRESENT RARELY_USED(100) + Nested nested: RARELY_USED(100) ======== singular_lazy_num=1 singular_lazy_0usage_num=0