| Index: content/renderer/stats_collection_controller.cc
|
| diff --git a/content/renderer/stats_collection_controller.cc b/content/renderer/stats_collection_controller.cc
|
| index f82a8c4fd561450070e0213981551881d19e315c..9c9bf608c5a3b33416f34a27a95b211f6573f997 100644
|
| --- a/content/renderer/stats_collection_controller.cc
|
| +++ b/content/renderer/stats_collection_controller.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/json/json_writer.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/metrics/statistics_recorder.h"
|
| +#include "base/metrics/stats_table.h"
|
| #include "base/strings/string_util.h"
|
| #include "content/common/child_process_messages.h"
|
| #include "content/renderer/render_view_impl.h"
|
| @@ -73,6 +74,34 @@ void ConvertLoadTimeToJSON(
|
| base::JSONWriter::Write(&item, result);
|
| }
|
|
|
| +
|
| +// Encodes StatsTable as json.
|
| +// - |stats_table| - StatsTable to encode.
|
| +// - |pid| - The process id to get stats for (0 for all processes).
|
| +// - |result| - returned JSON.
|
| +// Example return value:
|
| +// {'c:V8:TotalEvalSize': 102664, 'c:V8:TotalLoadSize': 164356}
|
| +void ConvertStatsTableToJSON(
|
| + const base::StatsTable* stats_table,
|
| + const base::ProcessId pid,
|
| + std::string *result) {
|
| + base::DictionaryValue counters;
|
| + // NOTE: Counters start at index 1.
|
| + for (int index = 1; index <= stats_table->GetMaxCounters(); index++) {
|
| + std::string name = stats_table->GetRowName(index);
|
| + if (name.length() == 0)
|
| + break;
|
| +
|
| + // JSON doesn't allow '.' in names.
|
| + size_t pos;
|
| + while ((pos = name.find(".")) != std::string::npos)
|
| + name.replace(pos, 1, ":");
|
| +
|
| + counters.SetInteger(name, stats_table->GetRowValue(index, pid));
|
| + }
|
| + base::JSONWriter::Write(&counters, result);
|
| +}
|
| +
|
| } // namespace
|
|
|
| StatsCollectionController::StatsCollectionController()
|
| @@ -83,6 +112,10 @@ StatsCollectionController::StatsCollectionController()
|
| BindCallback("getBrowserHistogram",
|
| base::Bind(&StatsCollectionController::GetBrowserHistogram,
|
| base::Unretained(this)));
|
| + BindCallback("getStatsTable",
|
| + base::Bind(
|
| + &StatsCollectionController::GetStatsTable,
|
| + base::Unretained(this)));
|
| BindCallback("tabLoadTiming",
|
| base::Bind(
|
| &StatsCollectionController::GetTabLoadTiming,
|
| @@ -90,7 +123,7 @@ StatsCollectionController::StatsCollectionController()
|
| }
|
|
|
| void StatsCollectionController::GetHistogram(const CppArgumentList& args,
|
| - CppVariant* result) {
|
| + CppVariant* result) {
|
| if (args.size() != 1) {
|
| result->SetNull();
|
| return;
|
| @@ -107,7 +140,7 @@ void StatsCollectionController::GetHistogram(const CppArgumentList& args,
|
| }
|
|
|
| void StatsCollectionController::GetBrowserHistogram(const CppArgumentList& args,
|
| - CppVariant* result) {
|
| + CppVariant* result) {
|
| if (args.size() != 1) {
|
| result->SetNull();
|
| return;
|
| @@ -125,6 +158,18 @@ void StatsCollectionController::GetBrowserHistogram(const CppArgumentList& args,
|
| result->Set(histogram_json);
|
| }
|
|
|
| +void StatsCollectionController::GetStatsTable(const CppArgumentList& args,
|
| + CppVariant* result) {
|
| + base::StatsTable* stats_table = base::StatsTable::current();
|
| + std::string output;
|
| + if (!stats_table) {
|
| + output = "{}";
|
| + } else {
|
| + ConvertStatsTableToJSON(stats_table, base::GetCurrentProcId(), &output);
|
| + }
|
| + result->Set(output);
|
| +}
|
| +
|
| void StatsCollectionController::GetTabLoadTiming(
|
| const CppArgumentList& args,
|
| CppVariant* result) {
|
|
|