1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2015 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 "chrome/browser/net/request_source_bandwidth_histograms.h"
#include "base/metrics/histogram_macros.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/process_type.h"
#include "net/url_request/url_request.h"
namespace {
enum Bucket {
BUCKET_UNKNOWN,
BUCKET_RENDERER,
BUCKET_BROWSER,
BUCKET_MAX,
};
bool ShouldHistogramRequest(const net::URLRequest* request, bool started) {
return started &&
!request->was_cached() &&
request->url().SchemeIsHTTPOrHTTPS();
}
Bucket GetBucketForRequest(const net::URLRequest* request) {
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (!info)
return BUCKET_BROWSER;
else if (info->GetProcessType() == content::PROCESS_TYPE_RENDERER)
return BUCKET_RENDERER;
else
return BUCKET_UNKNOWN;
}
// Histogram response sizes in kilobytes, from 1 KB to 4 GB.
#define UMA_HISTOGRAM_RESPONSE_KB(bucket, sample) \
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResponseSizeByProcess." bucket, sample, \
1, 4 * 1024 * 1024, 100)
void LogRequest(Bucket bucket, int64 bytes) {
int64 kilobytes = bytes / 1024;
switch (bucket) {
case BUCKET_UNKNOWN:
UMA_HISTOGRAM_RESPONSE_KB("Unknown", kilobytes);
break;
case BUCKET_RENDERER:
UMA_HISTOGRAM_RESPONSE_KB("Renderer", kilobytes);
break;
case BUCKET_BROWSER:
UMA_HISTOGRAM_RESPONSE_KB("Browser", kilobytes);
break;
default:
NOTREACHED();
}
}
} // namespace
void RecordRequestSourceBandwidth(const net::URLRequest* request,
bool started) {
if (ShouldHistogramRequest(request, started))
LogRequest(GetBucketForRequest(request), request->GetTotalReceivedBytes());
}
|