diff options
-rw-r--r-- | ppapi/c/private/ppb_uma_private.h | 45 | ||||
-rw-r--r-- | ppapi/ppapi_tests.gypi | 2 | ||||
-rw-r--r-- | ppapi/tests/all_c_includes.h | 1 | ||||
-rw-r--r-- | ppapi/tests/test_uma.cc | 56 | ||||
-rw-r--r-- | ppapi/tests/test_uma.h | 31 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 4 | ||||
-rwxr-xr-x | webkit/plugins/ppapi/ppb_uma_private_impl.cc | 98 | ||||
-rwxr-xr-x | webkit/plugins/ppapi/ppb_uma_private_impl.h | 21 |
9 files changed, 260 insertions, 0 deletions
diff --git a/ppapi/c/private/ppb_uma_private.h b/ppapi/c/private/ppb_uma_private.h new file mode 100644 index 0000000..0b1c5bf --- /dev/null +++ b/ppapi/c/private/ppb_uma_private.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2011 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. + */ +#ifndef PPAPI_C_PRIVATE_PPB_UMA_PRIVATE_H_ +#define PPAPI_C_PRIVATE_PPB_UMA_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" + +#define PPB_UMA_PRIVATE_INTERFACE "PPB_UMA(Private);0.1" + +struct PPB_UMA_Private { + /** + * HistogramCustomTimes is a pointer to a function which records a time + * sample given in milliseconds in the histogram given by |name|, possibly + * creating the histogram if it does not exist. + */ + void (*HistogramCustomTimes)(struct PP_Var name, + int64_t sample, + int64_t min, int64_t max, + uint32_t bucket_count); + + /** + * HistogramCustomCounts is a pointer to a function which records a sample + * in the histogram given by |name|, possibly creating the histogram if it + * does not exist. + */ + void (*HistogramCustomCounts)(struct PP_Var name, + int32_t sample, + int32_t min, int32_t max, + uint32_t bucket_count); + + /** + * HistogramEnumeration is a pointer to a function which records a sample + * in the histogram given by |name|, possibly creating the histogram if it + * does not exist. The sample represents a value in an enumeration bounded + * by |boundary_value|, that is, sample < boundary_value always. + */ + void (*HistogramEnumeration)(struct PP_Var name, + int32_t sample, + int32_t boundary_value); +}; + +#endif /* PPAPI_C_PRIVATE_PPB_UMA_PRIVATE_H_ */ diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index eaf9ece..6d81e19 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -224,6 +224,8 @@ 'tests/test_scrollbar.cc', 'tests/test_scrollbar.h', 'tests/test_struct_sizes.c', + 'tests/test_uma.cc', + 'tests/test_uma.h', 'tests/test_url_loader.cc', 'tests/test_url_loader.h', 'tests/test_url_util.cc', diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index cf393c7..a77296b 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -87,6 +87,7 @@ #include "ppapi/c/private/ppb_nacl_private.h" #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppp_instance_private.h" +#include "ppapi/c/private/ppb_uma_private.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/c/trusted/ppb_image_data_trusted.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" diff --git a/ppapi/tests/test_uma.cc b/ppapi/tests/test_uma.cc new file mode 100644 index 0000000..a310e8f --- /dev/null +++ b/ppapi/tests/test_uma.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2011 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 "ppapi/tests/test_uma.h" + +#include "ppapi/c/private/ppb_uma_private.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(UMA); + +bool TestUMA::Init() { + uma_interface_ = reinterpret_cast<PPB_UMA_Private const*>( + pp::Module::Get()->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE)); + return !!uma_interface_; +} + +void TestUMA::RunTest() { + instance_->LogTest("Count", TestCount()); + instance_->LogTest("Time", TestTime()); + instance_->LogTest("Enum", TestEnum()); +} + +std::string TestUMA::TestCount() { + pp::Var name_var = pp::Var("Test.CountHistogram"); + PP_Var name = name_var.pp_var(); + uma_interface_->HistogramCustomCounts(name, 10, 1, 100, 50); + uma_interface_->HistogramCustomCounts(name, 30, 1, 100, 50); + uma_interface_->HistogramCustomCounts(name, 20, 1, 100, 50); + uma_interface_->HistogramCustomCounts(name, 40, 1, 100, 50); + PASS(); +} + +std::string TestUMA::TestTime() { + pp::Var name_var = pp::Var("Test.TimeHistogram"); + PP_Var name = name_var.pp_var(); + uma_interface_->HistogramCustomTimes(name, 100, 1, 10000, 50); + uma_interface_->HistogramCustomTimes(name, 1000, 1, 10000, 50); + uma_interface_->HistogramCustomTimes(name, 5000, 1, 10000, 50); + uma_interface_->HistogramCustomTimes(name, 10, 1, 10000, 50); + PASS(); +} + +std::string TestUMA::TestEnum() { + pp::Var name_var = pp::Var("Test.EnumHistogram"); + PP_Var name = name_var.pp_var(); + uma_interface_->HistogramEnumeration(name, 0, 5); + uma_interface_->HistogramEnumeration(name, 3, 5); + uma_interface_->HistogramEnumeration(name, 3, 5); + uma_interface_->HistogramEnumeration(name, 1, 5); + uma_interface_->HistogramEnumeration(name, 2, 5); + PASS(); +} + diff --git a/ppapi/tests/test_uma.h b/ppapi/tests/test_uma.h new file mode 100644 index 0000000..0a60fde --- /dev/null +++ b/ppapi/tests/test_uma.h @@ -0,0 +1,31 @@ +// Copyright (c) 2011 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. + +#ifndef PAPPI_TESTS_TEST_UMA_H_ +#define PAPPI_TESTS_TEST_UMA_H_ + +#include <string> + +#include "ppapi/tests/test_case.h" + +struct PPB_UMA_Private; + +class TestUMA : public TestCase { + public: + explicit TestUMA(TestingInstance* instance) : TestCase(instance) {} + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestCount(); + std::string TestTime(); + std::string TestEnum(); + + // Used by the tests that access the C API directly. + const PPB_UMA_Private* uma_interface_; +}; + +#endif // PAPPI_TESTS_TEST_BUFFER_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index a19efdb..1e1bfec 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -287,6 +287,8 @@ '../plugins/ppapi/ppb_scrollbar_impl.h', '../plugins/ppapi/ppb_surface_3d_impl.cc', '../plugins/ppapi/ppb_surface_3d_impl.h', + '../plugins/ppapi/ppb_uma_private_impl.cc', + '../plugins/ppapi/ppb_uma_private_impl.h', '../plugins/ppapi/ppb_url_loader_impl.cc', '../plugins/ppapi/ppb_url_loader_impl.h', '../plugins/ppapi/ppb_url_request_info_impl.cc', diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 9073ed0..f22ca92 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -62,6 +62,7 @@ #include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_proxy_private.h" #include "ppapi/c/private/ppb_nacl_private.h" +#include "ppapi/c/private/ppb_uma_private.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/c/trusted/ppb_image_data_trusted.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" @@ -94,6 +95,7 @@ #include "webkit/plugins/ppapi/ppb_proxy_impl.h" #include "webkit/plugins/ppapi/ppb_scrollbar_impl.h" #include "webkit/plugins/ppapi/ppb_transport_impl.h" +#include "webkit/plugins/ppapi/ppb_uma_private_impl.h" #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" @@ -299,6 +301,8 @@ const void* GetInterface(const char* name) { return PPB_Proxy_Impl::GetInterface(); if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE) == 0) return PPB_Scrollbar_Impl::GetInterface(); + if (strcmp(name, PPB_UMA_PRIVATE_INTERFACE) == 0) + return PPB_UMA_Private_Impl::GetInterface(); if (strcmp(name, PPB_URLLOADER_INTERFACE) == 0) return PPB_URLLoader_Impl::GetInterface(); if (strcmp(name, PPB_URLLOADERTRUSTED_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppb_uma_private_impl.cc b/webkit/plugins/ppapi/ppb_uma_private_impl.cc new file mode 100755 index 0000000..f08e1df --- /dev/null +++ b/webkit/plugins/ppapi/ppb_uma_private_impl.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_uma_private_impl.h" + +#include "base/metrics/histogram.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/c/private/ppb_uma_private.h" +#include "webkit/glue/webkit_glue.h" +#include "webkit/plugins/ppapi/var.h" + +namespace webkit { +namespace ppapi { + +namespace { + +#define RETURN_IF_BAD_ARGS(_name, _sample, _min, _max, _bucket_count) \ + do { \ + if (_name.type != PP_VARTYPE_STRING || _name.value.as_id == 0) \ + return; \ + if (_min >= _max) \ + return; \ + if (_bucket_count <= 1) \ + return; \ + } while (0) + +void HistogramCustomTimes(PP_Var name, + int64_t sample, + int64_t min, int64_t max, + uint32_t bucket_count) { + RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); + + scoped_refptr<StringVar> name_string(StringVar::FromPPVar(name)); + if (name_string == NULL) + return; + base::Histogram* counter = + base::Histogram::FactoryTimeGet( + name_string->value(), + base::TimeDelta::FromMilliseconds(min), + base::TimeDelta::FromMilliseconds(max), + bucket_count, + base::Histogram::kUmaTargetedHistogramFlag); + counter->AddTime(base::TimeDelta::FromMilliseconds(sample)); +} + +void HistogramCustomCounts(PP_Var name, + int32_t sample, + int32_t min, int32_t max, + uint32_t bucket_count) { + RETURN_IF_BAD_ARGS(name, sample, min, max, bucket_count); + + scoped_refptr<StringVar> name_string(StringVar::FromPPVar(name)); + if (name_string == NULL) + return; + base::Histogram* counter = + base::Histogram::FactoryGet( + name_string->value(), + min, + max, + bucket_count, + base::Histogram::kUmaTargetedHistogramFlag); + counter->Add(sample); +} + +void HistogramEnumeration(PP_Var name, + int32_t sample, + int32_t boundary_value) { + RETURN_IF_BAD_ARGS(name, sample, 1, boundary_value, boundary_value + 1); + + scoped_refptr<StringVar> name_string(StringVar::FromPPVar(name)); + if (name_string == NULL) + return; + base::Histogram* counter = + base::LinearHistogram::FactoryGet( + name_string->value(), + 1, + boundary_value, + boundary_value + 1, + base::Histogram::kUmaTargetedHistogramFlag); + counter->Add(sample); +} + +} // namespace + +const PPB_UMA_Private ppb_uma = { + &HistogramCustomTimes, + &HistogramCustomCounts, + &HistogramEnumeration, +}; + +// static +const PPB_UMA_Private* PPB_UMA_Private_Impl::GetInterface() { + return &ppb_uma; +} + +} // namespace ppapi +} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_uma_private_impl.h b/webkit/plugins/ppapi/ppb_uma_private_impl.h new file mode 100755 index 0000000..0088713 --- /dev/null +++ b/webkit/plugins/ppapi/ppb_uma_private_impl.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011 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. + +#ifndef WEBKIT_PLUGINS_PPAPI_PPB_UMA_PRIVATE_IMPL_H_ +#define WEBKIT_PLUGINS_PPAPI_PPB_UMA_PRIVATE_IMPL_H_ + +struct PPB_UMA_Private; + +namespace webkit { +namespace ppapi { + +class PPB_UMA_Private_Impl { + public: + static const PPB_UMA_Private* GetInterface(); +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_PPB_UMA_PRIVATE_IMPL_H_ |