diff options
author | Benety Goh <benety@mongodb.com> | 2015-07-07 14:30:55 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-07-08 10:29:21 -0400 |
commit | 5eca5fe8106408b198c759443a2bb1ca320dad6c (patch) | |
tree | 588b151fc7ac817eb441b2ca32a5aef8e33bd282 /src/mongo/db/stats | |
parent | 659b6566c4251714ae95b7f249bf7ff3851f1aaf (diff) | |
download | mongo-5eca5fe8106408b198c759443a2bb1ca320dad6c.tar.gz |
SERVER-19307 moved TimerStats into its own library
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/SConscript | 22 | ||||
-rw-r--r-- | src/mongo/db/stats/timer_stats.h | 4 | ||||
-rw-r--r-- | src/mongo/db/stats/timer_stats_test.cpp | 51 |
3 files changed, 75 insertions, 2 deletions
diff --git a/src/mongo/db/stats/SConscript b/src/mongo/db/stats/SConscript index 3141d5e5272..af46ba98832 100644 --- a/src/mongo/db/stats/SConscript +++ b/src/mongo/db/stats/SConscript @@ -3,6 +3,28 @@ Import("env") env.Library( + target='timer_stats', + source=[ + 'timer_stats.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/bson/bson', + '$BUILD_DIR/mongo/util/foundation', + '$BUILD_DIR/mongo/util/concurrency/spin_lock', + ], +) + +env.CppUnitTest( + target='timer_stats_test', + source=[ + 'timer_stats_test.cpp', + ], + LIBDEPS=[ + 'timer_stats', + ], +) + +env.Library( target='top', source=[ 'top.cpp', diff --git a/src/mongo/db/stats/timer_stats.h b/src/mongo/db/stats/timer_stats.h index a1b3ef69dfd..cd444bee9aa 100644 --- a/src/mongo/db/stats/timer_stats.h +++ b/src/mongo/db/stats/timer_stats.h @@ -57,8 +57,8 @@ public: private: mutable SpinLock _lock; - long long _num; - long long _totalMillis; + long long _num = 0; + long long _totalMillis = 0; }; /** diff --git a/src/mongo/db/stats/timer_stats_test.cpp b/src/mongo/db/stats/timer_stats_test.cpp new file mode 100644 index 00000000000..cd755386329 --- /dev/null +++ b/src/mongo/db/stats/timer_stats_test.cpp @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2015 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/jsobj.h" +#include "mongo/db/stats/timer_stats.h" +#include "mongo/util/time_support.h" +#include "mongo/unittest/unittest.h" + +namespace { + +using namespace mongo; + +TEST(TimerStatsTest, GetReportNoRecording) { + ASSERT_EQUALS(BSON("num" << 0 << "totalMillis" << 0), TimerStats().getReport()); +} + +TEST(TimerStatsTest, GetReportOneRecording) { + TimerStats timerStats; + Timer timer; + int millis = timerStats.record(timer); + ASSERT_EQUALS(BSON("num" << 1 << "totalMillis" << millis), timerStats.getReport()); +} + +} // namespace |