Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: ui/base/resource/data_pack.cc

Issue 2699513002: Add an option to print the resource ids that Chrome loads. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/resource/data_pack.cc
diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
index 6de25681749a0bb68e2177e5405eeb6466b4c7bf..9eb0082c2fb0f7f549521dd41b72e21e57af796e 100644
--- a/ui/base/resource/data_pack.cc
+++ b/ui/base/resource/data_pack.cc
@@ -7,12 +7,14 @@
#include <errno.h>
#include <utility>
+#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
+#include "base/stl_util.h"
#include "base/strings/string_piece.h"
// For details of the file layout, see
@@ -65,6 +67,32 @@ void LogDataPackError(LoadErrors error) {
UMA_HISTOGRAM_ENUMERATION("DataPack.Load", error, LOAD_ERRORS_COUNT);
}
+// Prints the given resource id the first time it's loaded if Chrome has been
+// started with --print-resource-ids. This output is then used to generate a
+// more optimal resource renumbering to improve startup speed. See
+// tools/gritsettings/README.md for more info.
Alexei Svitkine (slow) 2017/02/16 16:19:20 Note: tools/gritsettings/README.md will be added i
+void MaybePrintResourceId(uint16_t resource_id) {
+ // This code is run in other binaries than Chrome which do not initialize the
+ // CommandLine object. Early return in those cases.
+ if (!base::CommandLine::InitializedForCurrentProcess())
+ return;
+
+ // Note: This switch isn't in ui/base/ui_base_switches.h because ui/base
+ // depends on ui/base/resource and thus it would cause a circular dependency.
+ static bool print_resource_ids =
+ base::CommandLine::ForCurrentProcess()->HasSwitch("print-resource-ids");
+ if (!print_resource_ids)
+ return;
+
+ // Note: This is leaked intentionally. However, it's only allocated if the
+ // above command line is specified, so it shouldn't affect regular users.
+ static std::set<uint16_t>* resource_ids_logged = new std::set<uint16_t>();
+ if (!base::ContainsKey(*resource_ids_logged, resource_id)) {
+ printf("Resource=%d\n", resource_id);
+ resource_ids_logged->insert(resource_id);
+ }
+}
+
} // namespace
namespace ui {
@@ -258,6 +286,7 @@ bool DataPack::GetStringPiece(uint16_t resource_id,
return false;
}
+ MaybePrintResourceId(resource_id);
size_t length = next_entry->file_offset - target->file_offset;
data->set(reinterpret_cast<const char*>(data_source_->GetData() +
target->file_offset),
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698