Commit 9d337bc7 authored by gavinp@chromium.org's avatar gavinp@chromium.org

Clean up dependencies for disk_cache histogram_macros.h.

The current mechanism by which these convenience macros find their
backend is confusing, at best; the macro has the form of our include
guard macros, but describes a CC file. Embedded within the
histogram_macros.h then is an abstraction violation: it just knows
which object has backend information depending on which file it was
included from.

Some downstream reviews have made this even more confusing; rather
than continue this, let's parameterize the backend object to the
convenience macros, so each translation unit is responsible for
knowing its own context.

R=mmenke@chromium.org, rvargas@chromium.org
TBR=mmenke@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/140893013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251116 0039d316-1c4b-4281-b951-d872f2087c98
parent 1477ef4c
......@@ -366,6 +366,8 @@ void HttpPipeliningCompatibilityClient::OnRequestFinished(
int request_id, internal::PipelineTestRequest::Status status) {
// The CACHE_HISTOGRAM_* macros are used, because they allow dynamic metric
// names.
// TODO(gavinp): Clean up this dependency by moving the needed functionality
// into base/.
CACHE_HISTOGRAM_ENUMERATION(GetMetricName(request_id, "Status"),
status,
internal::PipelineTestRequest::STATUS_MAX);
......
......@@ -27,11 +27,11 @@
#include "net/disk_cache/errors.h"
#include "net/disk_cache/experiments.h"
#include "net/disk_cache/file.h"
// This has to be defined before including histogram_macros.h from this file.
#define NET_DISK_CACHE_BACKEND_IMPL_CC_
#include "net/disk_cache/histogram_macros.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ this
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
......
......@@ -35,6 +35,9 @@
#include "base/win/scoped_handle.h"
#endif
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
namespace {
......
......@@ -18,6 +18,9 @@
#include "net/disk_cache/net_log_parameters.h"
#include "net/disk_cache/sparse_control.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
......
......@@ -41,6 +41,9 @@
#include "net/disk_cache/histogram_macros.h"
#include "net/disk_cache/trace.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
using base::TimeTicks;
......
......@@ -84,12 +84,6 @@
#define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \
CACHE_HISTOGRAM_ENUMERATION(name, sample, 50)
#ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_
#define BACKEND_OBJ this
#else
#define BACKEND_OBJ backend_
#endif
// Generates a UMA histogram of the given type, generating the proper name for
// it (asking backend_->HistogramName), and adding the provided sample.
// For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would
......@@ -101,8 +95,9 @@
// UMA_HISTOGRAM_COUNTS("DiskCache.2.MyExperiment_530", 55);
//
#define CACHE_UMA(type, name, experiment, sample) {\
const std::string my_name = BACKEND_OBJ->HistogramName(name, experiment);\
switch (BACKEND_OBJ->cache_type()) {\
const std::string my_name =\
CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name, experiment);\
switch (CACHE_UMA_BACKEND_IMPL_OBJ->cache_type()) {\
case net::DISK_CACHE:\
CACHE_HISTOGRAM_##type(my_name.data(), sample);\
break;\
......
......@@ -13,6 +13,9 @@
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/histogram_macros.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
namespace disk_cache {
BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend,
......
......@@ -12,6 +12,9 @@
#include "net/disk_cache/histogram_macros.h"
#include "net/disk_cache/stress_support.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
using base::TimeTicks;
......
......@@ -28,11 +28,11 @@
#include "net/disk_cache/storage_block-inl.h"
#include "net/disk_cache/v3/disk_format_v3.h"
#include "net/disk_cache/v3/entry_impl_v3.h"
#include "net/disk_cache/v3/histogram_macros.h"
#include "net/disk_cache/v3/index_table.h"
// This has to be defined before including histogram_macros.h from this file.
#define NET_DISK_CACHE_BACKEND_IMPL_CC_
#include "net/disk_cache/v3/histogram_macros.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ this
using base::Time;
using base::TimeDelta;
......
......@@ -26,11 +26,11 @@
#include "net/disk_cache/errors.h"
#include "net/disk_cache/experiments.h"
#include "net/disk_cache/file.h"
// This has to be defined before including histogram_macros.h from this file.
#define NET_DISK_CACHE_BACKEND_IMPL_CC_
#include "net/disk_cache/histogram_macros.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ this
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
......
......@@ -18,6 +18,9 @@
#include "net/disk_cache/v3/histogram_macros.h"
// #include "net/disk_cache/v3/sparse_control_v3.h"
// Provide a BackendImpl object to macros from histogram_macros.h.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
......
......@@ -40,6 +40,9 @@
#include "net/disk_cache/v3/entry_impl_v3.h"
#include "net/disk_cache/v3/histogram_macros.h"
// Define CACHE_UMA_BACKEND_IMPL_OBJ to be a disk_cache::BackendImpl* in order
// to use the CACHE_UMA histogram macro.
#define CACHE_UMA_BACKEND_IMPL_OBJ backend_
using base::Time;
using base::TimeTicks;
......
......@@ -84,12 +84,6 @@
#define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \
CACHE_HISTOGRAM_ENUMERATION(name, sample, 50)
#ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_
#define BACKEND_OBJ this
#else
#define BACKEND_OBJ backend_
#endif
// Generates a UMA histogram of the given type, generating the proper name for
// it (asking backend_->HistogramName), and adding the provided sample.
// For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would
......@@ -99,8 +93,9 @@
// UMA_HISTOGRAM_COUNTS("DiskCache3.MyName_AppCache", 20);
//
#define CACHE_UMA(type, name, sample) {\
const std::string my_name = BACKEND_OBJ->HistogramName(name);\
switch (BACKEND_OBJ->cache_type()) {\
const std::string my_name =\
CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name);\
switch (CACHE_UMA_BACKEND_IMPL_OBJ->cache_type()) {\
case net::DISK_CACHE:\
CACHE_HISTOGRAM_##type(my_name.data(), sample);\
break;\
......
......@@ -457,6 +457,7 @@
'disk_cache/v3/entry_impl_v3.h',
'disk_cache/v3/eviction_v3.cc',
'disk_cache/v3/eviction_v3.h',
'disk_cache/v3/histogram_macros.h',
'disk_cache/v3/index_table.cc',
'disk_cache/v3/index_table.h',
'dns/address_sorter.h',
......
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