diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 21:03:29 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 21:03:29 +0000 |
commit | 3ebd384a5bbbac045e7ae7e07f8c8d9934dd7c69 (patch) | |
tree | 176514ecc364a5aa376aca2fc60e2440d5817384 /dbus/dbus_statistics_unittest.cc | |
parent | 42774e4a2cffae20a5ab38ed43ed79ef9376e2fd (diff) | |
download | chromium_src-3ebd384a5bbbac045e7ae7e07f8c8d9934dd7c69.zip chromium_src-3ebd384a5bbbac045e7ae7e07f8c8d9934dd7c69.tar.gz chromium_src-3ebd384a5bbbac045e7ae7e07f8c8d9934dd7c69.tar.bz2 |
Add DBusStatistics and DBusLogSource to log and show dbus stats
The intention of this is to provide low overhead detailed logging to ensure that dbus call counts remain reasonable as we migrate NetworkLibrary and other systtems from src/chrome to src/chromeos.
We already have UMA stats which provide high level numbers that we can watch, but this will make detailed debugging available for advanced users and in feedback reports.
BUG=159635
For chrome/chrome_browser_chromeos.gypi:
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11363173
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/dbus_statistics_unittest.cc')
-rw-r--r-- | dbus/dbus_statistics_unittest.cc | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/dbus/dbus_statistics_unittest.cc b/dbus/dbus_statistics_unittest.cc new file mode 100644 index 0000000..9a2e2a1 --- /dev/null +++ b/dbus/dbus_statistics_unittest.cc @@ -0,0 +1,183 @@ +// Copyright (c) 2012 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 "dbus/dbus_statistics.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace dbus { + +class DBusStatisticsTest : public testing::Test { + public: + DBusStatisticsTest() { + } + + virtual void SetUp() OVERRIDE { + statistics::Initialize(); + } + + virtual void TearDown() OVERRIDE { + statistics::Shutdown(); + } + + protected: + void AddTestMethodCalls() { + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method1"); + statistics::AddReceivedSignal( + "service1", "service1.interface1", "method1"); + statistics::AddBlockingSentMethodCall( + "service1", "service1.interface1", "method1"); + + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method2"); + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method2"); + statistics::AddReceivedSignal( + "service1", "service1.interface1", "method2"); + + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method3"); + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method3"); + statistics::AddSentMethodCall( + "service1", "service1.interface1", "method3"); + + statistics::AddSentMethodCall( + "service1", "service1.interface2", "method1"); + + statistics::AddSentMethodCall( + "service1", "service1.interface2", "method2"); + + statistics::AddSentMethodCall( + "service2", "service2.interface1", "method1"); + } + + private: + DISALLOW_COPY_AND_ASSIGN(DBusStatisticsTest); +}; + +TEST_F(DBusStatisticsTest, TestDBusStatsBasic) { + int sent = 0, received = 0, block = 0; + + // Add a sent call + statistics::AddSentMethodCall("service1", "service1.interface1", "method1"); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(0, received); + EXPECT_EQ(0, block); + + // Add a received call + statistics::AddReceivedSignal("service1", "service1.interface1", "method1"); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(1, received); + EXPECT_EQ(0, block); + + // Add a block call + statistics::AddBlockingSentMethodCall( + "service1", "service1.interface1", "method1"); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(1, received); + EXPECT_EQ(1, block); +} + +TEST_F(DBusStatisticsTest, TestDBusStatsMulti) { + int sent = 0, received = 0, block = 0; + + // Add some more stats to exercise accessing multiple different stats. + AddTestMethodCalls(); + + // Make sure all entries can be found in the set and their counts were + // incremented correctly. + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(1, received); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method2", &sent, &received, &block)); + EXPECT_EQ(2, sent); + EXPECT_EQ(1, received); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface1", "method3", &sent, &received, &block)); + EXPECT_EQ(3, sent); + EXPECT_EQ(0, received); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface2", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(0, received); + ASSERT_TRUE(statistics::testing::GetCalls( + "service1", "service1.interface2", "method2", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(0, received); + ASSERT_TRUE(statistics::testing::GetCalls( + "service2", "service2.interface1", "method1", &sent, &received, &block)); + EXPECT_EQ(1, sent); + EXPECT_EQ(0, received); + + ASSERT_FALSE(statistics::testing::GetCalls( + "service1", "service1.interface3", "method2", &sent, &received, &block)); +} + +TEST_F(DBusStatisticsTest, TestGetAsString) { + std::string output_none = GetAsString(statistics::SHOW_SERVICE, + statistics::FORMAT_TOTALS); + EXPECT_EQ("No DBus calls.", output_none); + + AddTestMethodCalls(); + + std::string output_service = GetAsString(statistics::SHOW_SERVICE, + statistics::FORMAT_TOTALS); + const std::string expected_output_service( + "service1: Sent (BLOCKING): 1 Sent: 8 Received: 2\n" + "service2: Sent: 1\n"); + EXPECT_EQ(expected_output_service, output_service); + + std::string output_interface = GetAsString(statistics::SHOW_INTERFACE, + statistics::FORMAT_TOTALS); + const std::string expected_output_interface( + "service1.interface1: Sent (BLOCKING): 1 Sent: 6 Received: 2\n" + "service1.interface2: Sent: 2\n" + "service2.interface1: Sent: 1\n"); + EXPECT_EQ(expected_output_interface, output_interface); + + std::string output_per_minute = GetAsString(statistics::SHOW_INTERFACE, + statistics::FORMAT_PER_MINUTE); + const std::string expected_output_per_minute( + "service1.interface1: Sent (BLOCKING): 1/min Sent: 6/min" + " Received: 2/min\n" + "service1.interface2: Sent: 2/min\n" + "service2.interface1: Sent: 1/min\n"); + EXPECT_EQ(expected_output_per_minute, output_per_minute); + + std::string output_all = GetAsString(statistics::SHOW_INTERFACE, + statistics::FORMAT_ALL); + const std::string expected_output_all( + "service1.interface1: Sent (BLOCKING): 1 (1/min) Sent: 6 (6/min)" + " Received: 2 (2/min)\n" + "service1.interface2: Sent: 2 (2/min)\n" + "service2.interface1: Sent: 1 (1/min)\n"); + EXPECT_EQ(expected_output_all, output_all); + + + std::string output_method = GetAsString(statistics::SHOW_METHOD, + statistics::FORMAT_TOTALS); + const std::string expected_output_method( + "service1.interface1.method1: Sent (BLOCKING): 1 Sent: 1 Received: 1\n" + "service1.interface1.method2: Sent: 2 Received: 1\n" + "service1.interface1.method3: Sent: 3\n" + "service1.interface2.method1: Sent: 1\n" + "service1.interface2.method2: Sent: 1\n" + "service2.interface1.method1: Sent: 1\n"); + EXPECT_EQ(expected_output_method, output_method); + +} + +} // namespace dbus |