summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Kanchev <kanchev@itestra.com>2013-03-18 16:12:09 +0100
committerAleksandar Kanchev <kanchev@itestra.com>2013-03-18 16:12:09 +0100
commit779bd801426922c68d8875d0325c0def88855a92 (patch)
tree394cca8829606cb4659dcb1a82a3d72ff3a453fe
parent809b42e0503cb1e866616ce6e2d497c01896b587 (diff)
downloadgenivi-common-api-runtime-779bd801426922c68d8875d0325c0def88855a92.tar.gz
CommonAPI-Ping: use CLOCK_MONOTONIC
-rw-r--r--CommonAPI-Ping/.gitignore4
-rw-r--r--CommonAPI-Ping/Makefile.am9
-rw-r--r--CommonAPI-Ping/src/Benchmark.cpp1
-rw-r--r--CommonAPI-Ping/src/BenchmarkStats.h51
-rw-r--r--CommonAPI-Ping/src/StopWatch.cpp34
-rw-r--r--CommonAPI-Ping/src/StopWatch.h56
6 files changed, 100 insertions, 55 deletions
diff --git a/CommonAPI-Ping/.gitignore b/CommonAPI-Ping/.gitignore
index db0b55e..d5e715c 100644
--- a/CommonAPI-Ping/.gitignore
+++ b/CommonAPI-Ping/.gitignore
@@ -22,5 +22,5 @@
/m4/libtool.m4
/m4/lt*.m4
/src-gen
-/EchoClient
-/EchoService
+/PingClient
+/PingService
diff --git a/CommonAPI-Ping/Makefile.am b/CommonAPI-Ping/Makefile.am
index 8757ffc..140839c 100644
--- a/CommonAPI-Ping/Makefile.am
+++ b/CommonAPI-Ping/Makefile.am
@@ -55,11 +55,14 @@ bin_PROGRAMS = \
PingService
PingClient_SOURCES = \
- src/BenchmarkStats.h \
- src/BenchmarkStats.cpp \
src/Benchmark.h \
src/Benchmark.cpp \
- src/PingClient.cpp
+ src/BenchmarkStats.h \
+ src/BenchmarkStats.cpp \
+ src/PingClient.cpp \
+ src/StopWatch.h \
+ src/StopWatch.cpp
+
PingClient_LDADD = libcommonapi-tests-PingProxy.la
PingService_SOURCES = \
diff --git a/CommonAPI-Ping/src/Benchmark.cpp b/CommonAPI-Ping/src/Benchmark.cpp
index a6c6563..9c32a37 100644
--- a/CommonAPI-Ping/src/Benchmark.cpp
+++ b/CommonAPI-Ping/src/Benchmark.cpp
@@ -7,6 +7,7 @@
#include "Benchmark.h"
#include <CommonAPI/Factory.h>
+#include <chrono>
#include <functional>
diff --git a/CommonAPI-Ping/src/BenchmarkStats.h b/CommonAPI-Ping/src/BenchmarkStats.h
index 054c8c7..8dde793 100644
--- a/CommonAPI-Ping/src/BenchmarkStats.h
+++ b/CommonAPI-Ping/src/BenchmarkStats.h
@@ -7,57 +7,10 @@
#ifndef BENCHMARKING_STATS_H_
#define BENCHMARKING_STATS_H_
-#include <chrono>
#include <thread>
#include <memory>
-
-class StopWatch {
- public:
- typedef std::chrono::high_resolution_clock clock;
-
- StopWatch():
- started_(false),
- totalElapsedMilliseconds_(0) {
- }
-
- inline void reset() {
- totalElapsedMilliseconds_ = totalElapsedMilliseconds_.zero();
- }
-
- inline void start() {
- reset();
- startTimePoint_ = clock::now();
- started_ = true;
- }
-
- inline void stop() {
- totalElapsedMilliseconds_ += getElapsed();
- started_ = false;
- }
-
- inline int64_t getTotalElapsedMilliseconds() const {
- int64_t elapsedMilliseconds = totalElapsedMilliseconds_.count();
-
- if (started_)
- elapsedMilliseconds += getElapsed().count();
-
- return elapsedMilliseconds;
- }
-
- inline int64_t getTotalElapsedSeconds() const {
- return getTotalElapsedMilliseconds() / 1000;
- }
-
- private:
- inline std::chrono::milliseconds getElapsed() const {
- return std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - startTimePoint_);
- }
-
- bool started_;
- clock::time_point startTimePoint_;
- std::chrono::milliseconds totalElapsedMilliseconds_;
-};
+#include "StopWatch.h"
class BenchmarkStats {
@@ -114,6 +67,4 @@ private:
StopWatch transportStopWatch_;
};
-extern std::shared_ptr<BenchmarkStats> global_stats;
-
#endif // BENCHMARKING_STATS_H_
diff --git a/CommonAPI-Ping/src/StopWatch.cpp b/CommonAPI-Ping/src/StopWatch.cpp
new file mode 100644
index 0000000..9f8a413
--- /dev/null
+++ b/CommonAPI-Ping/src/StopWatch.cpp
@@ -0,0 +1,34 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "StopWatch.h"
+
+#include <cassert>
+#include <ctime>
+
+
+#define USEC_PER_SEC 1000000ULL
+#define USEC_PER_MSEC 1000ULL
+#define NSEC_PER_USEC 1000ULL
+
+
+uint64_t StopWatch::getTotalElapsedMilliseconds() const {
+ usec_t elapsed = totalElapsed_;
+
+ if (started_)
+ elapsed += getElapsed();
+
+ return elapsed / USEC_PER_MSEC;
+}
+
+StopWatch::usec_t StopWatch::now() {
+ struct timespec ts;
+
+ assert(!clock_gettime(CLOCK_MONOTONIC, &ts));
+
+ return (usec_t) ts.tv_sec * USEC_PER_SEC + (usec_t) ts.tv_nsec / NSEC_PER_USEC;
+}
+
diff --git a/CommonAPI-Ping/src/StopWatch.h b/CommonAPI-Ping/src/StopWatch.h
new file mode 100644
index 0000000..e3ed72e
--- /dev/null
+++ b/CommonAPI-Ping/src/StopWatch.h
@@ -0,0 +1,56 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef STOP_WATCH_H_
+#define STOP_WATCH_H_
+
+#include <cstdint>
+
+
+class StopWatch {
+public:
+ typedef uint64_t usec_t;
+
+ StopWatch():
+ started_(false),
+ totalElapsed_(0),
+ startTimePoint_(0) {
+ }
+
+ inline void reset() {
+ started_ = false;
+ totalElapsed_ = 0;
+ }
+
+ inline void start() {
+ startTimePoint_ = now();
+ started_ = true;
+ }
+
+ inline void stop() {
+ totalElapsed_ += getElapsed();
+ started_ = false;
+ }
+
+ uint64_t getTotalElapsedMilliseconds() const;
+
+ inline uint64_t getTotalElapsedSeconds() const {
+ return getTotalElapsedMilliseconds() / 1000;
+ }
+
+private:
+ inline usec_t getElapsed() const {
+ return now() - startTimePoint_;
+ }
+
+ static usec_t now();
+
+ bool started_;
+ usec_t startTimePoint_;
+ usec_t totalElapsed_;
+};
+
+#endif // STOP_WATCH_H_