Measure map download and loading times and send them to the server
This commit is contained in:
@@ -426,6 +426,11 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap()
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
static uint32_t u32_duration(const std::chrono::steady_clock::time_point &begin, const std::chrono::steady_clock::time_point &end) {
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
|
||||
return ClampTo<uint32_t>(ms);
|
||||
}
|
||||
|
||||
/** Tell the server we received the complete map. */
|
||||
NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk()
|
||||
{
|
||||
@@ -435,6 +440,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk()
|
||||
my_client->status = STATUS_ACTIVE;
|
||||
|
||||
auto p = std::make_unique<Packet>(PACKET_CLIENT_MAP_OK);
|
||||
p->Send_uint32(u32_duration(my_client->cm_map_begin, my_client->cm_map_done));
|
||||
p->Send_uint32(u32_duration(my_client->cm_map_done, my_client->cm_map_loaded));
|
||||
my_client->SendPacket(std::move(p));
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
@@ -838,6 +845,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe
|
||||
|
||||
if (this->savegame != nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||
|
||||
this->cm_map_begin = std::chrono::steady_clock::now();
|
||||
this->savegame = std::make_shared<PacketReader>();
|
||||
|
||||
_frame_counter = _frame_counter_server = _frame_counter_max = p.Recv_uint32();
|
||||
@@ -894,11 +902,13 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
||||
|
||||
this->savegame->Reset();
|
||||
this->cm_map_done = std::chrono::steady_clock::now();
|
||||
|
||||
/* The map is done downloading, load it */
|
||||
ClearErrorMessages();
|
||||
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, this->savegame);
|
||||
this->savegame = nullptr;
|
||||
this->cm_map_loaded = std::chrono::steady_clock::now();
|
||||
|
||||
/* Long savegame loads shouldn't affect the lag calculation! */
|
||||
this->last_packet = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -35,6 +35,10 @@ private:
|
||||
|
||||
ServerStatus status; ///< Status of the connection with the server.
|
||||
|
||||
std::chrono::steady_clock::time_point cm_map_begin;
|
||||
std::chrono::steady_clock::time_point cm_map_done;
|
||||
std::chrono::steady_clock::time_point cm_map_loaded;
|
||||
|
||||
protected:
|
||||
friend void NetworkExecuteLocalCommandQueue();
|
||||
friend void NetworkClose(bool close_admins);
|
||||
|
||||
Reference in New Issue
Block a user