[ClientProfiler] Added.
[external/gamekit] Updated.
This commit is contained in:
parent
95a804d9fc
commit
46d1c4a3aa
2
external/gamekit
vendored
2
external/gamekit
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 88aee22de2424b4b9238642a487a8f0094f700b2
|
Subproject commit ca65aed9949a166e846bec09777ef821cf1949dc
|
87
source/client/core/ClientProfiler.cpp
Normal file
87
source/client/core/ClientProfiler.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* OpenMiner
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
||||||
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
||||||
|
*
|
||||||
|
* This file is part of OpenMiner.
|
||||||
|
*
|
||||||
|
* OpenMiner is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenMiner 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include <gk/core/Debug.hpp>
|
||||||
|
#include <gk/core/GameClock.hpp>
|
||||||
|
|
||||||
|
#include "ClientProfiler.hpp"
|
||||||
|
|
||||||
|
ClientProfiler *ClientProfiler::s_instance = nullptr;
|
||||||
|
|
||||||
|
void ClientProfiler::onBeginTick() {
|
||||||
|
m_ticks.emplace_back();
|
||||||
|
m_ticks.back().begin = gk::GameClock::getInstance().getTicks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientProfiler::onEndTick() {
|
||||||
|
m_ticks.back().end = gk::GameClock::getInstance().getTicks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientProfiler::startAction(const std::string &name) {
|
||||||
|
m_ticks.back().actions[name].durations.emplace_back();
|
||||||
|
m_ticks.back().actions[name].durations.back().first = gk::GameClock::getInstance().getTicks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientProfiler::endAction(const std::string &name) {
|
||||||
|
m_ticks.back().actions[name].durations.back().second = gk::GameClock::getInstance().getTicks(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClientProfiler::dump(u64 tickDurationMin) {
|
||||||
|
std::unordered_map<std::string, std::pair<u64, u64>> maxActionDuration;
|
||||||
|
|
||||||
|
u64 i = 0;
|
||||||
|
for (auto &tick : m_ticks) {
|
||||||
|
u64 tickDuration = tick.end - tick.begin;
|
||||||
|
if (tickDuration < tickDurationMin) continue;
|
||||||
|
|
||||||
|
gkDebug() << "Tick" << i++ << "took" << tickDuration << "ms";
|
||||||
|
|
||||||
|
if (tickDuration > 0) {
|
||||||
|
for (auto &[actionName, action] : tick.actions) {
|
||||||
|
u64 j = 0;
|
||||||
|
for (auto &[begin, end] : action.durations) {
|
||||||
|
u64 actionDuration = end - begin;
|
||||||
|
|
||||||
|
if (maxActionDuration.find(actionName) == maxActionDuration.end())
|
||||||
|
maxActionDuration.emplace(actionName, std::make_pair(actionDuration, 0));
|
||||||
|
|
||||||
|
maxActionDuration[actionName].first = std::max(maxActionDuration[actionName].first, actionDuration);
|
||||||
|
|
||||||
|
float actionPercentTotal = actionDuration / (float)tickDuration * 100.f;
|
||||||
|
|
||||||
|
gkDebug() << "Action" << actionName << j++ << "took" << actionDuration << "ms -" << actionPercentTotal << "% of tick";
|
||||||
|
}
|
||||||
|
|
||||||
|
maxActionDuration[actionName].second = std::max(maxActionDuration[actionName].second, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &[actionName, pair] : maxActionDuration) {
|
||||||
|
gkDebug() << "Max duration for action" << actionName << ":" << pair.first << "ms (" << pair.second << ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
65
source/client/core/ClientProfiler.hpp
Normal file
65
source/client/core/ClientProfiler.hpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* OpenMiner
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
||||||
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
||||||
|
*
|
||||||
|
* This file is part of OpenMiner.
|
||||||
|
*
|
||||||
|
* OpenMiner is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenMiner 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef CLIENTPROFILER_HPP_
|
||||||
|
#define CLIENTPROFILER_HPP_
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include <gk/core/IntTypes.hpp>
|
||||||
|
|
||||||
|
struct ClientAction {
|
||||||
|
std::deque<std::pair<u64, u64>> durations;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClientTick {
|
||||||
|
u64 begin;
|
||||||
|
u64 end;
|
||||||
|
std::unordered_map<std::string, ClientAction> actions;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ClientProfiler {
|
||||||
|
public:
|
||||||
|
void onBeginTick();
|
||||||
|
void onEndTick();
|
||||||
|
|
||||||
|
void dump(u64 tickDurationMin = 0);
|
||||||
|
|
||||||
|
void startAction(const std::string &name);
|
||||||
|
void endAction(const std::string &name);
|
||||||
|
|
||||||
|
static ClientProfiler &getInstance() { return *s_instance; }
|
||||||
|
static void setInstance(ClientProfiler *instance) { s_instance = instance; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ClientProfiler *s_instance;
|
||||||
|
|
||||||
|
std::deque<ClientTick> m_ticks;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLIENTPROFILER_HPP_
|
Loading…
x
Reference in New Issue
Block a user