Commit 13cb0545 authored by Jasper Chapman-Black's avatar Jasper Chapman-Black Committed by Commit Bot

SuperSize: Add group by generated file type

Bug: 978298
Change-Id: I2e1a00223a2313511667f93063192b4e98475346
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931078
Commit-Queue: Jasper Chapman-Black <jaspercb@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718288}
parent 0d855887
...@@ -21,6 +21,8 @@ source_set("caspian-lib") { ...@@ -21,6 +21,8 @@ source_set("caspian-lib") {
"function_signature.h", "function_signature.h",
"grouped_path.cc", "grouped_path.cc",
"grouped_path.h", "grouped_path.h",
"lens.cc",
"lens.h",
"model.cc", "model.cc",
"model.h", "model.h",
"tree_builder.cc", "tree_builder.cc",
...@@ -43,6 +45,7 @@ test("caspian_unittests") { ...@@ -43,6 +45,7 @@ test("caspian_unittests") {
"diff_test.cc", "diff_test.cc",
"function_signature_test.cc", "function_signature_test.cc",
"grouped_path_test.cc", "grouped_path_test.cc",
"lens_test.cc",
"tree_builder_test.cc", "tree_builder_test.cc",
] ]
deps = [ deps = [
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "third_party/re2/src/re2/re2.h" #include "third_party/re2/src/re2/re2.h"
#include "tools/binary_size/libsupersize/caspian/diff.h" #include "tools/binary_size/libsupersize/caspian/diff.h"
#include "tools/binary_size/libsupersize/caspian/file_format.h" #include "tools/binary_size/libsupersize/caspian/file_format.h"
#include "tools/binary_size/libsupersize/caspian/lens.h"
#include "tools/binary_size/libsupersize/caspian/model.h" #include "tools/binary_size/libsupersize/caspian/model.h"
#include "tools/binary_size/libsupersize/caspian/tree_builder.h" #include "tools/binary_size/libsupersize/caspian/tree_builder.h"
...@@ -143,6 +144,8 @@ void BuildTree(bool method_count_mode, ...@@ -143,6 +144,8 @@ void BuildTree(bool method_count_mode,
filters.push_back([](const BaseSymbol& sym) -> bool { filters.push_back([](const BaseSymbol& sym) -> bool {
return sym.IsTemplate() && sym.IsNative(); return sym.IsTemplate() && sym.IsNative();
}); });
} else if (!strcmp(group_by, "generated_type")) {
lens = std::make_unique<GeneratedLens>();
} else { } else {
// TODO(jaspercb): Support group by generated path type. // TODO(jaspercb): Support group by generated path type.
std::cerr << "Unsupported group_by=" << group_by << std::endl; std::cerr << "Unsupported group_by=" << group_by << std::endl;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tools/binary_size/libsupersize/caspian/lens.h"
#include <string>
#include "third_party/re2/src/re2/re2.h"
#include "tools/binary_size/libsupersize/caspian/model.h"
namespace {
constexpr const char* kNoComponent = "(No component)";
bool PartialMatch(std::string_view view, const RE2& regex) {
re2::StringPiece piece(view.data(), view.size());
return RE2::PartialMatch(piece, regex);
}
bool PartialMatch(const char* string, const RE2& regex) {
if (string) {
return PartialMatch(std::string_view(string), regex);
}
return false;
}
} // namespace
namespace caspian {
std::string_view IdPathLens::ParentName(const BaseSymbol& symbol) {
return "";
}
std::string_view ComponentLens::ParentName(const BaseSymbol& symbol) {
std::string component;
if (symbol.Component() && *symbol.Component()) {
return symbol.Component();
}
return kNoComponent;
}
std::string_view TemplateLens::ParentName(const BaseSymbol& symbol) {
return symbol.Name();
}
std::string_view GeneratedLens::ParentName(const BaseSymbol& symbol) {
static LazyRE2 register_jni_regex = {
R"(Register.*JNIEnv\*\)|RegisteredMethods$)"};
if (PartialMatch(symbol.FullName(), *register_jni_regex)) {
return "RegisterJNI";
}
static LazyRE2 gl_bindings_autogen_regex = {"gl_bindings_autogen"};
if (PartialMatch(symbol.SourcePath(), *gl_bindings_autogen_regex) ||
PartialMatch(symbol.ObjectPath(), *gl_bindings_autogen_regex)) {
return "gl_bindings_autogen";
}
if (!symbol.IsGeneratedSource()) {
return "Not generated";
}
static LazyRE2 java_protobuf_regex = {R"(Proto\.java$)"};
if (PartialMatch(symbol.SourcePath(), *java_protobuf_regex)) {
return "Java Protocol Buffers";
}
static LazyRE2 cc_protobuf_regex = {R"(/protobuf/|\.pbzero\.o$|\.pb\.o$)"};
if (PartialMatch(symbol.ObjectPath(), *cc_protobuf_regex)) {
return "C++ Protocol Buffers";
}
static LazyRE2 mojo_regex = {".mojom|^mojo/|^mojo::"};
if (PartialMatch(symbol.ObjectPath(), *mojo_regex)) {
return "Mojo";
}
static LazyRE2 dev_tools_regex = {R"(\b(?:protocol|devtools)\b)"};
if (PartialMatch(symbol.SourcePath(), *dev_tools_regex)) {
return "DevTools";
}
static LazyRE2 blink_bindings_regex = {R"((?:blink|WebKit)/.*bindings)"};
if (PartialMatch(symbol.ObjectPath(), *blink_bindings_regex)) {
return "Blink (bindings)";
}
static LazyRE2 blink_regex = {"WebKit|blink/"};
if (PartialMatch(symbol.ObjectPath(), *blink_regex)) {
return "Blink (other)";
}
static LazyRE2 v8_builtins = {"embedded.S$"};
if (PartialMatch(symbol.ObjectPath(), *v8_builtins)) {
return "V8 Builtins";
}
static LazyRE2 prepopulated_engines_regex = {"prepopulated_engines"};
if (PartialMatch(symbol.ObjectPath(), *prepopulated_engines_regex)) {
return "Metrics-related code";
}
static LazyRE2 gpu_driver_regex = {"gpu_driver_bug_list"};
if (PartialMatch(symbol.ObjectPath(), *gpu_driver_regex)) {
return "gpu_driver_bug_list_autogen.cc";
}
static LazyRE2 components_policy_regex = {"components/policy"};
if (PartialMatch(symbol.ObjectPath(), *components_policy_regex)) {
return "components/policy";
}
return "Generated (other)";
}
} // namespace caspian
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TOOLS_BINARY_SIZE_LIBSUPERSIZE_CASPIAN_LENS_H_
#define TOOLS_BINARY_SIZE_LIBSUPERSIZE_CASPIAN_LENS_H_
#include <string_view>
namespace caspian {
class BaseSymbol;
class BaseLens {
public:
virtual ~BaseLens() = default;
virtual std::string_view ParentName(const BaseSymbol& symbol) = 0;
};
class IdPathLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class ComponentLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class TemplateLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class GeneratedLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
} // namespace caspian
#endif // TOOLS_BINARY_SIZE_LIBSUPERSIZE_CASPIAN_LENS_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "tools/binary_size/libsupersize/caspian/lens.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/binary_size/libsupersize/caspian/model.h"
namespace caspian {
TEST(LensTest, TestGeneratedLensRegisterJNI) {
Symbol sym;
sym.full_name_ =
"base::android::JNI_TraceEvent_RegisterEnabledObserver(_JNIEnv*)";
sym.section_id_ = SectionId::kText;
sym.source_path_ = "a/b/c.java";
EXPECT_EQ("RegisterJNI", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensGlBindings) {
Symbol sym;
sym.full_name_ = "gl::TraceGLApi::glCopyTexImage2DFn(unsigned int, int, int)";
sym.section_id_ = SectionId::kText;
sym.source_path_ = "a/b/gl_bindings_autogen_gl.cc";
EXPECT_EQ("gl_bindings_autogen", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensNotGenerated) {
Symbol sym;
sym.full_name_ = "NotAGeneratedSymbol";
sym.section_id_ = SectionId::kText;
sym.source_path_ = "a/b/c.cc";
EXPECT_EQ("Not generated", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensJavaProto) {
Symbol sym;
sym.section_id_ = SectionId::kDex;
sym.source_path_ = "a/b/FooProto.java";
sym.flags_ |= SymbolFlag::kGeneratedSource;
EXPECT_EQ("Java Protocol Buffers", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensCppProto) {
Symbol sym;
sym.section_id_ = SectionId::kDex;
sym.object_path_ = "a/b/sync.pb.o";
sym.flags_ |= SymbolFlag::kGeneratedSource;
EXPECT_EQ("C++ Protocol Buffers", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensMojo) {
Symbol sym;
sym.section_id_ = SectionId::kText;
sym.object_path_ = "a.mojom";
sym.flags_ |= SymbolFlag::kGeneratedSource;
EXPECT_EQ("Mojo", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensDevTools) {
Symbol sym;
sym.section_id_ = SectionId::kText;
sym.flags_ |= SymbolFlag::kGeneratedSource;
sym.source_path_ = "a/b/protocol/Foo.cpp";
EXPECT_EQ("DevTools", GeneratedLens().ParentName(sym));
sym.source_path_ = "a/b/devtools/Foo.cpp";
EXPECT_EQ("DevTools", GeneratedLens().ParentName(sym));
}
TEST(LensTest, TestGeneratedLensBlinkBindings) {
Symbol sym;
sym.section_id_ = SectionId::kText;
sym.flags_ |= SymbolFlag::kGeneratedSource;
sym.object_path_ = "blink/foo/bindings/bar";
EXPECT_EQ("Blink (bindings)", GeneratedLens().ParentName(sym));
}
} // namespace caspian
...@@ -54,6 +54,20 @@ enum class DiffStatus : uint8_t { ...@@ -54,6 +54,20 @@ enum class DiffStatus : uint8_t {
kRemoved = 3, kRemoved = 3,
}; };
class SymbolFlag {
public:
static const int32_t kAnonymous = 1;
static const int32_t kStartup = 2;
static const int32_t kUnlikely = 4;
static const int32_t kRel = 8;
static const int32_t kRelLocal = 16;
static const int32_t kGeneratedSource = 32;
static const int32_t kClone = 64;
static const int32_t kHot = 128;
static const int32_t kCovered = 256;
static const int32_t kUncompressed = 512;
};
class Symbol; class Symbol;
class BaseSymbol { class BaseSymbol {
...@@ -127,6 +141,10 @@ class BaseSymbol { ...@@ -127,6 +141,10 @@ class BaseSymbol {
return !full_name.empty() && full_name[0] == '"'; return !full_name.empty() && full_name[0] == '"';
} }
bool IsGeneratedSource() const {
return Flags() & SymbolFlag::kGeneratedSource;
}
bool IsNameUnique() const { bool IsNameUnique() const {
return !(IsStringLiteral() || IsOverhead() || return !(IsStringLiteral() || IsOverhead() ||
(!FullName().empty() && FullName()[0] == '*') || (!FullName().empty() && FullName()[0] == '*') ||
......
...@@ -16,25 +16,8 @@ namespace { ...@@ -16,25 +16,8 @@ namespace {
constexpr const char kComponentSep = '>'; constexpr const char kComponentSep = '>';
constexpr const char kPathSep = '/'; constexpr const char kPathSep = '/';
constexpr const char* kNoName = "(No path)"; constexpr const char* kNoName = "(No path)";
constexpr const char* kNoComponent = "(No component)";
} // namespace } // namespace
std::string_view IdPathLens::ParentName(const BaseSymbol& symbol) {
return "";
}
std::string_view ComponentLens::ParentName(const BaseSymbol& symbol) {
std::string component;
if (symbol.Component() && *symbol.Component()) {
return symbol.Component();
}
return kNoComponent;
}
std::string_view TemplateLens::ParentName(const BaseSymbol& symbol) {
return symbol.Name();
}
TreeBuilder::TreeBuilder(SizeInfo* size_info) { TreeBuilder::TreeBuilder(SizeInfo* size_info) {
symbols_.reserve(size_info->raw_symbols.size()); symbols_.reserve(size_info->raw_symbols.size());
for (const Symbol& sym : size_info->raw_symbols) { for (const Symbol& sym : size_info->raw_symbols) {
......
...@@ -13,30 +13,10 @@ ...@@ -13,30 +13,10 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "tools/binary_size/libsupersize/caspian/lens.h"
#include "tools/binary_size/libsupersize/caspian/model.h" #include "tools/binary_size/libsupersize/caspian/model.h"
namespace caspian { namespace caspian {
class BaseLens {
public:
virtual ~BaseLens() = default;
virtual std::string_view ParentName(const BaseSymbol& symbol) = 0;
};
class IdPathLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class ComponentLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class TemplateLens : public BaseLens {
public:
std::string_view ParentName(const BaseSymbol& symbol) override;
};
class TreeBuilder { class TreeBuilder {
public: public:
explicit TreeBuilder(SizeInfo* size_info); explicit TreeBuilder(SizeInfo* size_info);
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
#include "tools/binary_size/libsupersize/caspian/model.h" #include "tools/binary_size/libsupersize/caspian/model.h"
namespace caspian { namespace caspian {
namespace { namespace {
using FilterList = std::vector<std::function<bool(const BaseSymbol&)>>;
void MakeSymbol(SizeInfo* info, void MakeSymbol(SizeInfo* info,
SectionId section_id, SectionId section_id,
int32_t size, int32_t size,
...@@ -44,6 +47,7 @@ void MakeSymbol(SizeInfo* info, ...@@ -44,6 +47,7 @@ void MakeSymbol(SizeInfo* info,
sym.size_info_ = info; sym.size_info_ = info;
info->raw_symbols.push_back(sym); info->raw_symbols.push_back(sym);
} }
} // namespace
std::unique_ptr<SizeInfo> CreateSizeInfo() { std::unique_ptr<SizeInfo> CreateSizeInfo() {
std::unique_ptr<SizeInfo> info = std::make_unique<SizeInfo>(); std::unique_ptr<SizeInfo> info = std::make_unique<SizeInfo>();
...@@ -67,7 +71,7 @@ TEST(TreeBuilderTest, TestIdPathLens) { ...@@ -67,7 +71,7 @@ TEST(TreeBuilderTest, TestIdPathLens) {
std::unique_ptr<SizeInfo> size_info = CreateSizeInfo(); std::unique_ptr<SizeInfo> size_info = CreateSizeInfo();
TreeBuilder builder(size_info.get()); TreeBuilder builder(size_info.get());
std::vector<std::function<bool(const BaseSymbol&)>> filters; FilterList filters;
builder.Build(std::make_unique<IdPathLens>(), '/', false, filters); builder.Build(std::make_unique<IdPathLens>(), '/', false, filters);
CheckAllTreeNodesFindable(builder, builder.Open("")); CheckAllTreeNodesFindable(builder, builder.Open(""));
EXPECT_EQ("Dt", builder.Open("")["type"].asString()); EXPECT_EQ("Dt", builder.Open("")["type"].asString());
...@@ -77,7 +81,7 @@ TEST(TreeBuilderTest, TestComponentLens) { ...@@ -77,7 +81,7 @@ TEST(TreeBuilderTest, TestComponentLens) {
std::unique_ptr<SizeInfo> size_info = CreateSizeInfo(); std::unique_ptr<SizeInfo> size_info = CreateSizeInfo();
TreeBuilder builder(size_info.get()); TreeBuilder builder(size_info.get());
std::vector<std::function<bool(const BaseSymbol&)>> filters; FilterList filters;
builder.Build(std::make_unique<ComponentLens>(), '>', false, filters); builder.Build(std::make_unique<ComponentLens>(), '>', false, filters);
CheckAllTreeNodesFindable(builder, builder.Open("")); CheckAllTreeNodesFindable(builder, builder.Open(""));
EXPECT_EQ("Ct", builder.Open("A")["type"].asString()); EXPECT_EQ("Ct", builder.Open("A")["type"].asString());
...@@ -100,7 +104,7 @@ TEST(TreeBuilderTest, TestTemplateLens) { ...@@ -100,7 +104,7 @@ TEST(TreeBuilderTest, TestTemplateLens) {
"void ()>::RunOnce(base::internal::BindStateBase*)"); "void ()>::RunOnce(base::internal::BindStateBase*)");
TreeBuilder builder(size_info.get()); TreeBuilder builder(size_info.get());
std::vector<std::function<bool(const BaseSymbol&)>> filters; FilterList filters;
builder.Build(std::make_unique<TemplateLens>(), '/', false, filters); builder.Build(std::make_unique<TemplateLens>(), '/', false, filters);
CheckAllTreeNodesFindable(builder, builder.Open("")); CheckAllTreeNodesFindable(builder, builder.Open(""));
EXPECT_EQ( EXPECT_EQ(
...@@ -115,7 +119,7 @@ TEST(TreeBuilderTest, TestNoNameUnderGroup) { ...@@ -115,7 +119,7 @@ TEST(TreeBuilderTest, TestNoNameUnderGroup) {
MakeSymbol(size_info.get(), SectionId::kText, 20, "", "A>B>C", "SymbolName"); MakeSymbol(size_info.get(), SectionId::kText, 20, "", "A>B>C", "SymbolName");
TreeBuilder builder(size_info.get()); TreeBuilder builder(size_info.get());
std::vector<std::function<bool(const BaseSymbol&)>> filters; FilterList filters;
builder.Build(std::make_unique<ComponentLens>(), '>', false, filters); builder.Build(std::make_unique<ComponentLens>(), '>', false, filters);
CheckAllTreeNodesFindable(builder, builder.Open("")); CheckAllTreeNodesFindable(builder, builder.Open(""));
EXPECT_EQ("A>B>C/(No path)", EXPECT_EQ("A>B>C/(No path)",
...@@ -138,7 +142,7 @@ TEST(TreeBuilderTest, TestJoinDexMethodClasses) { ...@@ -138,7 +142,7 @@ TEST(TreeBuilderTest, TestJoinDexMethodClasses) {
"OverviewModeObserver <init>(android.graphics.Bitmap)"); "OverviewModeObserver <init>(android.graphics.Bitmap)");
TreeBuilder builder(size_info.get()); TreeBuilder builder(size_info.get());
std::vector<std::function<bool(const BaseSymbol&)>> filters; FilterList filters;
builder.Build(std::make_unique<ComponentLens>(), '>', false, filters); builder.Build(std::make_unique<ComponentLens>(), '>', false, filters);
CheckAllTreeNodesFindable(builder, builder.Open("")); CheckAllTreeNodesFindable(builder, builder.Open(""));
...@@ -160,6 +164,4 @@ TEST(TreeBuilderTest, TestJoinDexMethodClasses) { ...@@ -160,6 +164,4 @@ TEST(TreeBuilderTest, TestJoinDexMethodClasses) {
const int short_name_index = dex_symbol["shortNameIndex"].asInt(); const int short_name_index = dex_symbol["shortNameIndex"].asInt();
EXPECT_EQ("android.graphics.Bitmap a()", id_path.substr(short_name_index)); EXPECT_EQ("android.graphics.Bitmap a()", id_path.substr(short_name_index));
} }
} // namespace
} // namespace caspian } // namespace caspian
...@@ -126,6 +126,10 @@ if ('serviceWorker' in navigator) { ...@@ -126,6 +126,10 @@ if ('serviceWorker' in navigator) {
<input type="radio" id="template" name="group_by" value="template"> <input type="radio" id="template" name="group_by" value="template">
<label class="radio-label" for="template">Template</label> <label class="radio-label" for="template">Template</label>
</div> </div>
<div class="radio-wrapper">
<input type="radio" id="generated_type" name="group_by" value="generated_type">
<label class="radio-label" for="generated_type">Generated type</label>
</div>
</fieldset> </fieldset>
<fieldset> <fieldset>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment