Commit e752516a authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Add DVLOG(2) for uploaded histograms

To check that the expected histograms are uploaded, I wanted a way
to see the uploaded histograms. With this CL, uploaded histogram
data is logged to the console. Can be enabled with
-vmodule=net_metrics_log_uploader=2. This is debug-build only.


Change-Id: I9c889e5e959c684b4a94b17cb53b687a48d6eebf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218312Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774817}
parent c4988088
......@@ -4,12 +4,17 @@
#include "components/metrics/net/net_metrics_log_uploader.h"
#include <sstream>
#include "base/base64.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/statistics_recorder.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "components/encrypted_messages/encrypted_message.pb.h"
......@@ -21,7 +26,9 @@
#include "net/url_request/url_fetcher.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/metrics_proto/reporting_info.pb.h"
#include "third_party/zlib/google/compression_utils.h"
#include "url/gurl.h"
namespace {
......@@ -182,6 +189,52 @@ bool EncryptAndBase64EncodeString(const std::string& plaintext,
return true;
}
#ifndef NDEBUG
void LogUploadingHistograms(const std::string& compressed_log_data) {
if (!VLOG_IS_ON(2))
return;
std::string uncompressed;
if (!compression::GzipUncompress(compressed_log_data, &uncompressed)) {
DVLOG(2) << "failed to uncompress log";
return;
}
metrics::ChromeUserMetricsExtension proto;
if (!proto.ParseFromString(uncompressed)) {
DVLOG(2) << "failed to parse uncompressed log";
return;
};
DVLOG(2) << "Uploading histograms...";
const base::StatisticsRecorder::Histograms histograms =
base::StatisticsRecorder::GetHistograms();
auto get_histogram_name = [&](uint64_t name_hash) -> std::string {
for (base::HistogramBase* histogram : histograms) {
if (histogram->name_hash() == name_hash)
return histogram->histogram_name();
}
return base::StrCat({"unnamed ", base::NumberToString(name_hash)});
};
for (int i = 0; i < proto.histogram_event_size(); i++) {
const metrics::HistogramEventProto& event = proto.histogram_event(i);
std::stringstream summary;
summary << " sum=" << event.sum();
for (int j = 0; j < event.bucket_size(); j++) {
const metrics::HistogramEventProto::Bucket& b = event.bucket(j);
// Empty fields have a specific meaning, see
// third_party/metrics_proto/histogram_event.proto.
summary << " bucket["
<< (b.has_min() ? base::NumberToString(b.min()) : "..") << '-'
<< (b.has_max() ? base::NumberToString(b.max()) : "..") << ")="
<< (b.has_count() ? base::NumberToString(b.count()) : "(1)");
}
DVLOG(2) << get_histogram_name(event.name_hash()) << summary.str();
}
}
#endif
} // namespace
namespace metrics {
......@@ -243,6 +296,13 @@ void NetMetricsLogUploader::UploadLogToURL(
const GURL& url) {
DCHECK(!log_hash.empty());
#ifndef NDEBUG
// For debug builds, you can use -vmodule=net_metrics_log_uploader=2
// to enable logging of uploaded histograms. You probably also want to use
// --force-enable-metrics-reporting, or metrics reporting may not be enabled.
LogUploadingHistograms(compressed_log_data);
#endif
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = url;
// Drop cookies and auth data.
......
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