Commit 16b3d6f5 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

SuperSize: Fix method count mode for size diffs

It was not filtering out changed symbols.

Bug: 1040165
Change-Id: I85c0898788708defda595ccb1f25a5a97d94aa46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032806
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737846}
parent 280bbbe1
...@@ -91,6 +91,16 @@ bool BuildTree(bool method_count_mode, ...@@ -91,6 +91,16 @@ bool BuildTree(bool method_count_mode,
const bool diff_mode = info && before_info; const bool diff_mode = info && before_info;
if (method_count_mode && diff_mode) {
// include_sections is used to filter to just .dex.method symbols.
// For diffs, we also want to filter to just adds & removes.
filters.push_back([](const GroupedPath&, const BaseSymbol& sym) -> bool {
DiffStatus diff_status = sym.GetDiffStatus();
return diff_status == DiffStatus::kAdded ||
diff_status == DiffStatus::kRemoved;
});
}
if (minimum_size_bytes > 0) { if (minimum_size_bytes > 0) {
if (!diff_mode) { if (!diff_mode) {
filters.push_back([minimum_size_bytes](const GroupedPath&, filters.push_back([minimum_size_bytes](const GroupedPath&,
......
...@@ -326,6 +326,7 @@ void TreeNode::WriteIntoJson( ...@@ -326,6 +326,7 @@ void TreeNode::WriteIntoJson(
std::function<bool(const TreeNode* const& l, const TreeNode* const& r)> std::function<bool(const TreeNode* const& l, const TreeNode* const& r)>
compare_func, compare_func,
bool is_sparse, bool is_sparse,
bool method_count_mode,
Json::Value* out) { Json::Value* out) {
if (symbol) { if (symbol) {
(*out)["helpme"] = std::string(symbol->Name()); (*out)["helpme"] = std::string(symbol->Name());
...@@ -362,7 +363,7 @@ void TreeNode::WriteIntoJson( ...@@ -362,7 +363,7 @@ void TreeNode::WriteIntoJson(
(*out)["size"] = size; (*out)["size"] = size;
(*out)["flags"] = flags; (*out)["flags"] = flags;
node_stats.WriteIntoJson(&(*out)["childStats"]); node_stats.WriteIntoJson(method_count_mode, &(*out)["childStats"]);
const size_t kMaxChildNodesToExpand = 1000; const size_t kMaxChildNodesToExpand = 1000;
if (children.size() > kMaxChildNodesToExpand) { if (children.size() > kMaxChildNodesToExpand) {
...@@ -380,7 +381,7 @@ void TreeNode::WriteIntoJson( ...@@ -380,7 +381,7 @@ void TreeNode::WriteIntoJson(
std::sort(children.begin(), children.end(), compare_func); std::sort(children.begin(), children.end(), compare_func);
for (unsigned int i = 0; i < children.size(); i++) { for (unsigned int i = 0; i < children.size(); i++) {
children[i]->WriteIntoJson(depth - 1, compare_func, is_sparse, children[i]->WriteIntoJson(depth - 1, compare_func, is_sparse,
&(*out)["children"][i]); method_count_mode, &(*out)["children"][i]);
} }
} }
} }
...@@ -407,17 +408,24 @@ NodeStats::NodeStats(const BaseSymbol& symbol) { ...@@ -407,17 +408,24 @@ NodeStats::NodeStats(const BaseSymbol& symbol) {
} }
} }
void NodeStats::WriteIntoJson(Json::Value* out) const { void NodeStats::WriteIntoJson(bool method_count_mode, Json::Value* out) const {
(*out) = Json::Value(Json::objectValue); (*out) = Json::Value(Json::objectValue);
for (const auto kv : child_stats) { for (const auto kv : child_stats) {
const std::string sectionId = std::string(1, static_cast<char>(kv.first)); const std::string sectionId = std::string(1, static_cast<char>(kv.first));
const Stat stats = kv.second; const Stat stats = kv.second;
(*out)[sectionId] = Json::Value(Json::objectValue); (*out)[sectionId] = Json::Value(Json::objectValue);
(*out)[sectionId]["size"] = stats.size; (*out)[sectionId]["size"] = stats.size;
(*out)[sectionId]["count"] = stats.count;
(*out)[sectionId]["added"] = stats.added; (*out)[sectionId]["added"] = stats.added;
(*out)[sectionId]["removed"] = stats.removed; (*out)[sectionId]["removed"] = stats.removed;
(*out)[sectionId]["changed"] = stats.changed; (*out)[sectionId]["changed"] = stats.changed;
// Count is used to store value for "method count" mode.
// Why? Because that's how it was implemented in the .ndjson worker.
int count = stats.count;
bool is_diff = stats.added > 0 || stats.removed > 0 || stats.changed > 0;
if (method_count_mode && is_diff) {
count = stats.added - stats.removed;
}
(*out)[sectionId]["count"] = count;
} }
} }
......
...@@ -321,7 +321,7 @@ struct NodeStats { ...@@ -321,7 +321,7 @@ struct NodeStats {
NodeStats(); NodeStats();
~NodeStats(); ~NodeStats();
explicit NodeStats(const BaseSymbol& symbol); explicit NodeStats(const BaseSymbol& symbol);
void WriteIntoJson(Json::Value* out) const; void WriteIntoJson(bool method_count_mode, Json::Value* out) const;
NodeStats& operator+=(const NodeStats& other); NodeStats& operator+=(const NodeStats& other);
SectionId ComputeBiggestSection() const; SectionId ComputeBiggestSection() const;
int32_t SumCount() const; int32_t SumCount() const;
...@@ -341,6 +341,7 @@ struct TreeNode { ...@@ -341,6 +341,7 @@ struct TreeNode {
void WriteIntoJson(int depth, void WriteIntoJson(int depth,
CompareFunc compare_func, CompareFunc compare_func,
bool is_sparse, bool is_sparse,
bool method_count_mode,
Json::Value* out); Json::Value* out);
GroupedPath id_path; GroupedPath id_path;
......
...@@ -130,7 +130,8 @@ Json::Value TreeBuilder::Open(const char* path) { ...@@ -130,7 +130,8 @@ Json::Value TreeBuilder::Open(const char* path) {
exit(1); exit(1);
} }
Json::Value v; Json::Value v;
node->WriteIntoJson(1, node_sort_func, size_info_->IsSparse(), &v); node->WriteIntoJson(1, node_sort_func, size_info_->IsSparse(),
method_count_mode_, &v);
return v; return v;
} }
......
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