Path: blob/master/modules/multiplayer/multiplayer_debugger.h
10277 views
/**************************************************************************/1/* multiplayer_debugger.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/debugger/engine_profiler.h"3334class MultiplayerSynchronizer;3536class MultiplayerDebugger {37public:38struct RPCNodeInfo {39ObjectID node;40String node_path;41int incoming_rpc = 0;42int incoming_size = 0;43int outgoing_rpc = 0;44int outgoing_size = 0;45};4647struct RPCFrame {48Vector<RPCNodeInfo> infos;4950Array serialize();51bool deserialize(const Array &p_arr);52};5354struct SyncInfo {55ObjectID synchronizer;56ObjectID config;57ObjectID root_node;58int incoming_syncs = 0;59int incoming_size = 0;60int outgoing_syncs = 0;61int outgoing_size = 0;6263void write_to_array(Array &r_arr) const;64bool read_from_array(const Array &p_arr, int p_offset);6566SyncInfo() {}67SyncInfo(MultiplayerSynchronizer *p_sync);68};6970struct ReplicationFrame {71HashMap<ObjectID, SyncInfo> infos;7273Array serialize();74bool deserialize(const Array &p_arr);75};7677private:78class BandwidthProfiler : public EngineProfiler {79protected:80struct BandwidthFrame {81uint32_t timestamp;82int packet_size;83};8485int bandwidth_in_ptr = 0;86Vector<BandwidthFrame> bandwidth_in;87int bandwidth_out_ptr = 0;88Vector<BandwidthFrame> bandwidth_out;89uint64_t last_bandwidth_time = 0;9091int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer);9293public:94void toggle(bool p_enable, const Array &p_opts);95void add(const Array &p_data);96void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);97};9899class RPCProfiler : public EngineProfiler {100private:101HashMap<ObjectID, RPCNodeInfo> rpc_node_data;102uint64_t last_profile_time = 0;103104void init_node(const ObjectID p_node);105106public:107void toggle(bool p_enable, const Array &p_opts);108void add(const Array &p_data);109void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);110};111112class ReplicationProfiler : public EngineProfiler {113private:114HashMap<ObjectID, SyncInfo> sync_data;115uint64_t last_profile_time = 0;116117public:118void toggle(bool p_enable, const Array &p_opts);119void add(const Array &p_data);120void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time);121};122123static Error _capture(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured);124125public:126static void initialize();127static void deinitialize();128};129130131