summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Clock.hpp60
-rw-r--r--src/server/Engine.cpp9
-rw-r--r--src/server/Engine.hpp2
-rw-r--r--src/server/PreProcessor.cpp4
4 files changed, 65 insertions, 10 deletions
diff --git a/src/server/Clock.hpp b/src/server/Clock.hpp
new file mode 100644
index 00000000..d9526d02
--- /dev/null
+++ b/src/server/Clock.hpp
@@ -0,0 +1,60 @@
+/*
+ This file is part of Ingen.
+ Copyright 2016 David Robillard <http://drobilla.net/>
+
+ Ingen is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or any later version.
+
+ Ingen 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 details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with Ingen. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef INGEN_ENGINE_CLOCK_HPP
+#define INGEN_ENGINE_CLOCK_HPP
+
+#ifdef __MACH__
+# include <mach/mach.h>
+# include <mach/mach_time.h>
+#endif
+
+namespace Ingen {
+namespace Server {
+
+class Clock {
+public:
+#ifdef __MACH__
+
+ Clock() { mach_timebase_info(&_timebase); }
+
+ uint64_t now_microseconds() const {
+ const uint64_t now = mach_absolute_time();
+ return now * _timebase.numer / _timebase.denom / 1e3;
+ }
+
+private:
+ mach_timebase_info_data_t _timebase;
+
+#else
+
+ uint64_t now_microseconds() const {
+ struct timespec time;
+# if defined(CLOCK_MONOTONIC_RAW)
+ clock_gettime(CLOCK_MONOTONIC_RAW, &time);
+# else
+ clock_gettime(CLOCK_MONOTONIC, &time);
+# endif
+ return (uint64_t)time.tv_sec * 1e6 + (uint64_t)time.tv_nsec / 1e3;
+ }
+
+#endif
+};
+
+} // namespace Server
+} // namespace Ingen
+
+#endif // INGEN_ENGINE_CLOCK_HPP
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index 0b468ce1..2d458bc4 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -321,14 +321,7 @@ Engine::event_time()
uint64_t
Engine::current_time(const RunContext& context) const
{
- struct timespec time;
-#ifdef CLOCK_MONOTONIC_RAW
- clock_gettime(CLOCK_MONOTONIC_RAW, &time);
-#else
- clock_gettime(CLOCK_MONOTONIC, &time);
-#endif
-
- return (uint64_t)time.tv_sec * 1e6 + (uint64_t)time.tv_nsec / 1e3;
+ return _clock.now_microseconds();
}
void
diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp
index fc80d64b..d7e4f87b 100644
--- a/src/server/Engine.hpp
+++ b/src/server/Engine.hpp
@@ -27,6 +27,7 @@
#include "ingen/ingen.h"
#include "ingen/types.hpp"
+#include "Clock.hpp"
#include "Event.hpp"
#include "RunContext.hpp"
#include "EventWriter.hpp"
@@ -205,6 +206,7 @@ private:
uint64_t _cycle_start_time;
Load _event_load;
Load _run_load;
+ Clock _clock;
std::mt19937 _rand_engine;
std::uniform_real_distribution<float> _uniform_dist;
diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp
index 9933bde2..1fd02cf3 100644
--- a/src/server/PreProcessor.cpp
+++ b/src/server/PreProcessor.cpp
@@ -137,8 +137,8 @@ PreProcessor::process(RunContext& context, PostProcessor& dest, size_t limit)
if (engine.world()->conf().option("trace").get<int32_t>()) {
const uint64_t start = engine.cycle_start_time(context);
const uint64_t end = engine.current_time(context);
- fprintf(stderr, "Processed %zu events in %zu us\n",
- n_processed, end - start);
+ fprintf(stderr, "Processed %zu events in %u us\n",
+ n_processed, (unsigned)(end - start));
}
Event* next = (Event*)last->next();