diff options
author | David Robillard <d@drobilla.net> | 2017-03-19 09:13:46 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-03-19 09:13:46 +0100 |
commit | f062189c8219041fad45cfd340c367e5c4796933 (patch) | |
tree | 346222e8dc724e2a1d8ebc2a3aacc2bb1d8b4698 /src/server/Load.hpp | |
parent | 1a31907d1ad2e9c8ed0cdced09e81f7a7ec07504 (diff) | |
download | ingen-f062189c8219041fad45cfd340c367e5c4796933.tar.gz ingen-f062189c8219041fad45cfd340c367e5c4796933.tar.bz2 ingen-f062189c8219041fad45cfd340c367e5c4796933.zip |
Shrink status bar text and fix initial DSP load display
Diffstat (limited to 'src/server/Load.hpp')
-rw-r--r-- | src/server/Load.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/server/Load.hpp b/src/server/Load.hpp new file mode 100644 index 00000000..ed9ee406 --- /dev/null +++ b/src/server/Load.hpp @@ -0,0 +1,57 @@ +/* + This file is part of Ingen. + Copyright 2007-2017 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_LOAD_HPP +#define INGEN_ENGINE_LOAD_HPP + +namespace Ingen { +namespace Server { + +struct Load +{ + void update(uint64_t time, uint64_t available) { + const uint64_t load = time * 100 / available; + if (load < min) { + min = load; + changed = true; + } + if (load > max) { + max = load; + changed = true; + } + if (++n == 1) { + mean = load; + changed = true; + } else { + const float a = mean + ((float)load - mean) / (float)++n; + if (a != mean) { + changed = floorf(a) != floorf(mean); + mean = a; + } + } + } + + uint64_t min = std::numeric_limits<uint64_t>::max(); + uint64_t max = 0; + float mean = 0.0f; + uint64_t n = 0; + bool changed = false; +}; + +} // namespace Server +} // namespace Ingen + +#endif // INGEN_ENGINE_LOAD_HPP |