diff --git a/CMakeLists.txt b/CMakeLists.txt index b8de6521e209f00a7d6272a6f6d9b20f618d066e..d50d7b896d059121030dbea80b9a59c0d4bf9f7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -726,7 +726,6 @@ message("======================================================================= ${SRC_DIR}/utility/frame_capture.hpp ${SRC_DIR}/utility/frame_capture.cpp ${SRC_DIR}/utility/geometry_buffer.hpp ${SRC_DIR}/utility/geometry_buffer.cpp ${SRC_DIR}/utility/indirect_cache.hpp ${SRC_DIR}/utility/indirect_cache.cpp - ${SRC_DIR}/utility/latency.hpp ${SRC_DIR}/utility/latency.cpp ${SRC_DIR}/utility/pass_timer.hpp ${SRC_DIR}/utility/pass_timer.cpp ${SRC_DIR}/utility/shadow_cache.hpp ${SRC_DIR}/utility/shadow_cache.cpp ${SRC_DIR}/utility/statistic.hpp ${SRC_DIR}/utility/statistic.cpp diff --git a/src/headset/remote_headset.cpp b/src/headset/remote_headset.cpp index 07dc88bc4e8220df7dfb2b29b9a9f185a0a7c7b0..972cd17385779208b68f5afc5a98c283599c630d 100644 --- a/src/headset/remote_headset.cpp +++ b/src/headset/remote_headset.cpp @@ -43,18 +43,12 @@ bool RemoteHeadset::on_create() this->statistic_send_queue_size = make_statistic("host_send_queue", UNIT_KBITS); this->statistic_receive_bitrate = make_statistic("host_receive_bitrate", UNIT_MBITS_PER_SECOND); this->statistic_receive_queue_size = make_statistic("host_receive_queue", UNIT_KBITS); - this->statistic_latency = make_latency_statistic("latency"); - + statistic_log->add_statistic(this->statistic_send_bitrate); statistic_log->add_statistic(this->statistic_send_queue_size); statistic_log->add_statistic(this->statistic_receive_bitrate); statistic_log->add_statistic(this->statistic_receive_queue_size); - this->statistic_list.push_back(this->statistic_latency->get_total_latency()); - this->statistic_list.push_back(this->statistic_latency->get_server_response()); - this->statistic_list.push_back(this->statistic_latency->get_frame_decoded()); - this->statistic_list.push_back(this->statistic_latency->get_command_construct()); - this->statistic_list.push_back(this->statistic_latency->get_command_executed()); this->statistic_list.push_back(this->statistic_send_bitrate); this->statistic_list.push_back(this->statistic_send_queue_size); this->statistic_list.push_back(this->statistic_receive_bitrate); @@ -110,11 +104,6 @@ void RemoteHeadset::on_destroy() this->transport->destroy(); } - if (this->statistic_latency != nullptr) - { - statistic_latency->write_to_file(); - } - this->destroy_framebuffers(); this->destroy_encoders(); } @@ -413,10 +402,6 @@ bool RemoteHeadset::create_transport() { this->on_controller_thumbstick(controller, thumbstick); }); - this->transport->set_on_latency([this](FrameNumber frame_number, FrameId frame_id, TransformId transform_id, double timestamp_transfrom_query, double timestamp_server_response, double timestamp_frame_decoded, double timestamp_command_construct, double timestamp_command_executed) - { - this->on_latency(frame_number, frame_id, transform_id, timestamp_transfrom_query, timestamp_server_response, timestamp_frame_decoded, timestamp_command_construct, timestamp_command_executed); - }); this->transport->set_on_performance_sample([this](std::optional<FrameNumber> frame_number, std::optional<FrameId> frame_id, std::optional<TransformId> transform_id, Unit unit, bool log_only, double sample, const std::string& name) { this->on_performance_sample(frame_number, frame_id, transform_id, unit, log_only, sample, name); @@ -691,23 +676,6 @@ void RemoteHeadset::on_controller_thumbstick(Controller controller, const glm::v lock.unlock(); } -void RemoteHeadset::on_latency(FrameNumber frame_number, FrameId frame_id, TransformId transform_id, double timestamp_transform_query, double timestamp_server_response, double timestamp_frame_decoded, double timestamp_command_construct, double timestamp_command_executed) -{ - LatencyCapture capture; - capture.frame_id = frame_id; - capture.frame_number = frame_number; - capture.transform_id = transform_id; - capture.timestamp_transform_query = timestamp_transform_query; - capture.timestamp_server_response = timestamp_server_response; - capture.timestamp_frame_decoded = timestamp_frame_decoded; - capture.timestamp_command_construct = timestamp_command_construct; - capture.timestamp_command_executed = timestamp_command_executed; - - std::unique_lock<std::mutex> lock(this->transport_mutex); - this->statistic_latency->submit_capture(capture); - lock.unlock(); -} - void RemoteHeadset::on_performance_sample(std::optional<FrameNumber> frame_number, std::optional<FrameId> frame_id, std::optional<TransformId> transform_id, Unit unit, bool log_only, double sample, const std::string& name) { std::unique_lock<std::mutex> lock(this->transport_mutex); diff --git a/src/headset/remote_headset.hpp b/src/headset/remote_headset.hpp index aa34cb9f68eb4d616b963592c6ee42c792f7308d..4ba84800945dd627e08b6709e1327208f7bca54a 100644 --- a/src/headset/remote_headset.hpp +++ b/src/headset/remote_headset.hpp @@ -12,8 +12,6 @@ #include "transport/transport.hpp" #include "encoder/encoder.hpp" -#include "utility/latency.hpp" - class RemoteHeadset : public Headset { public: @@ -70,7 +68,6 @@ private: void on_controller_event(Controller controller, ControllerState controller_state); void on_controller_button(Controller controller, Button button, ButtonState button_state); void on_controller_thumbstick(Controller controller, const glm::vec2& thumbstick); - void on_latency(FrameNumber frame_number, FrameId frame_id, TransformId transform_id, double timestamp_transform_query, double timestamp_server_response, double timestamp_frame_decoded, double timestamp_command_construct, double timestamp_command_executed); void on_performance_sample(std::optional<FrameNumber> frame_number, std::optional<FrameId> frame_id, std::optional<TransformId> transform_id, Unit unit, bool log_only, double sample, const std::string& name); void on_transport_error(); void on_encode_error(); @@ -134,5 +131,4 @@ private: Statistic::Ptr statistic_send_queue_size; Statistic::Ptr statistic_receive_bitrate; Statistic::Ptr statistic_receive_queue_size; - LatencyStatistic::Ptr statistic_latency; //NOTE: Protected by transport_mutex }; \ No newline at end of file diff --git a/src/transport/transport.hpp b/src/transport/transport.hpp index 4363aafe6d3a6b1c7b22b4358933a48f71ae2bd0..eedfcb859ec198cf77306934588bbcd7b108ef3e 100644 --- a/src/transport/transport.hpp +++ b/src/transport/transport.hpp @@ -88,19 +88,14 @@ public: // thumbstick: Position of the thumbstick on the specified controller typedef std::function<void(Controller controller, const glm::vec2& thumbstick)> OnControllerThumbstick; - // OnLatency: Used to transmit latency related information. This packet is optional - // frame_number: Identifies the frame to which the information in this packet belongs - // frame_id: Identifies the frame id (e.g. left or right eye) to which the information in this packet belongs - // transform_id: Identifies the head transformation which was used to render the specified image - // timestamp_transform_query: Time between the statup of the application on the headset and the quering of the head transform on the headset - // timestamp_server_response: Time between the statup of the application on the headset and the response from the host-system to the head transformation send by the headset application - // timestamp_frame_decoded: Time between the statup of the application on the headset and the completion of the image decoding on the headset - // timestamp_command_construct: Time between the statup of the application on the headset and the submission of the rendering command - // timestamp_command_executed: Time between the statup of the application on the headset and the completion of the rendering command - typedef std::function<void(FrameNumber frame_number, FrameId frame_id, TransformId transform_id, double timestamp_transform_query, double timestamp_server_response, double timestamp_frame_decoded, double timestamp_command_construct, double timestamp_command_executed)> OnLatency; - - - + // OnPerformanceSample: Used to transmit performance related samples. + // frame_number: Identifies the frame to which the information in this packet belongs + // frame_id: Identifies the frame id (e.g. left or right eye) to which the information in this packet belongs + // transform_id: Identifies the head transformation which was used during rendering + // unit: Specifies the unit of the value parameter + // log_only: Indicates whether the given value should only be loged + // value: The value of the sample + // name: The name of the sample typedef std::function<void(std::optional<FrameNumber> frame_number, std::optional<FrameId> frame_id, std::optional<TransformId> transform_id, Unit unit, bool log_only, double sample, const std::string& name)> OnPerformanceSample; // OnTransportError: Called in case of error or disconnect. After that the transport method transitions to the error state @@ -180,7 +175,6 @@ public: virtual void set_on_controller_event(OnControllerEvent function) = 0; virtual void set_on_controller_button(OnControllerButton function) = 0; virtual void set_on_controller_thumbstick(OnControllerThumbstick function) = 0; - virtual void set_on_latency(OnLatency function) = 0; virtual void set_on_performance_sample(OnPerformanceSample function) = 0; virtual void set_on_transport_error(OnTransportError function) = 0; diff --git a/src/transport/udp_packet.cpp b/src/transport/udp_packet.cpp index e47e4272aabffc6bce83fe19628ac83dfe2c92ba..5500fae49c324f9248af84c179324e6e132d7d37 100644 --- a/src/transport/udp_packet.cpp +++ b/src/transport/udp_packet.cpp @@ -107,11 +107,11 @@ bool convert_udp_performance_sample_unit(UDPPerformanceSampleUnit udp_unit, Unit case UDP_PERFORMANCE_SAMPLE_UNIT_UNDEFINED: unit = UNIT_UNDEFINED; break; - case UDP_PERFORMANCE_SAMPLE_UNIT_BITS: - unit = UNIT_BITS; + case UDP_PERFORMANCE_SAMPLE_UNIT_HOURS: + unit = UNIT_HOURS; break; - case UDP_PERFORMANCE_SAMPLE_UNIT_BYTES: - unit = UNIT_BYTES; + case UDP_PERFORMANCE_SAMPLE_UNIT_MINUTES: + unit = UNIT_MINUTES; break; case UDP_PERFORMANCE_SAMPLE_UNIT_SECONDS: unit = UNIT_SECONDS; @@ -119,12 +119,51 @@ bool convert_udp_performance_sample_unit(UDPPerformanceSampleUnit udp_unit, Unit case UDP_PERFORMANCE_SAMPLE_UNIT_MILLISECONDS: unit = UNIT_MILLISECONDS; break; - case UDP_PERFORMANCE_SAMPLE_UNIT_MBITS_PER_SECOND: - unit = UNIT_MBITS_PER_SECOND; + case UDP_PERFORMANCE_SAMPLE_UNIT_MIRCOSECONDS: + unit = UNIT_MIRCOSECONDS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_BITS: + unit = UNIT_BITS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_KBITS: + unit = UNIT_KBITS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_MBITS: + unit = UNIT_MBITS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_KIBITS: + unit = UNIT_KIBITS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_MIBITS: + unit = UNIT_MIBITS; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_BYTES: + unit = UNIT_BYTES; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_KBYTES: + unit = UNIT_KBYTES; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_MBYTES: + unit = UNIT_MBYTES; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_KIBYTES: + unit = UNIT_KIBYTES; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_MIBYTES: + unit = UNIT_MIBYTES; break; case UDP_PERFORMANCE_SAMPLE_UNIT_UNDEFINED_PER_SECOND: unit = UNIT_UNDEFINED_PER_SECOND; break; + case UDP_PERFORMANCE_SAMPLE_UNIT_BITS_PER_SECOND: + unit = UNIT_BITS_PER_SECOND; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_KBITS_PER_SECOND: + unit = UNIT_KBITS_PER_SECOND; + break; + case UDP_PERFORMANCE_SAMPLE_UNIT_MBITS_PER_SECOND: + unit = UNIT_MBITS_PER_SECOND; + break; default: lava::log()->error("UDP-Transport: Unkown performance sample unit!"); return false; diff --git a/src/transport/udp_packet.hpp b/src/transport/udp_packet.hpp index 39e8b6b51e0c62bfe5d175e7b85c27830eefa82e..ab19362951827620eb646bb9897709cece83cf62 100644 --- a/src/transport/udp_packet.hpp +++ b/src/transport/udp_packet.hpp @@ -28,11 +28,10 @@ enum UDPPacketId : uint32_t UDP_PACKET_ID_FRAME_CONFIG_NAL = 0x09, UDP_PACKET_ID_FRAME_NAL = 0x0A, UDP_PACKET_ID_FRAME_METADATA = 0x0B, - UDP_PACKET_ID_LATENCY = 0x0C, - UDP_PACKET_ID_PERFORMANCE_SAMPLE = 0x0D, - UDP_PACKET_ID_OVERLAY_CONFIG = 0x0E, - UDP_PACKET_ID_OVERLAY_TEXT = 0x0F, - UDP_PACKET_ID_OVERLAY_GRAPH = 0x10, + UDP_PACKET_ID_PERFORMANCE_SAMPLE = 0x0C, + UDP_PACKET_ID_OVERLAY_CONFIG = 0x0D, + UDP_PACKET_ID_OVERLAY_TEXT = 0x0E, + UDP_PACKET_ID_OVERLAY_GRAPH = 0x0F, UDP_PACKET_ID_MAX_COUNT }; @@ -75,12 +74,25 @@ enum UDPButtonState : uint32_t enum UDPPerformanceSampleUnit : uint32_t { UDP_PERFORMANCE_SAMPLE_UNIT_UNDEFINED = 0x00, - UDP_PERFORMANCE_SAMPLE_UNIT_BITS = 0x01, - UDP_PERFORMANCE_SAMPLE_UNIT_BYTES = 0x02, + UDP_PERFORMANCE_SAMPLE_UNIT_HOURS = 0x01, + UDP_PERFORMANCE_SAMPLE_UNIT_MINUTES = 0x02, UDP_PERFORMANCE_SAMPLE_UNIT_SECONDS = 0x03, UDP_PERFORMANCE_SAMPLE_UNIT_MILLISECONDS = 0x04, - UDP_PERFORMANCE_SAMPLE_UNIT_MBITS_PER_SECOND = 0x05, - UDP_PERFORMANCE_SAMPLE_UNIT_UNDEFINED_PER_SECOND = 0x06 + UDP_PERFORMANCE_SAMPLE_UNIT_MIRCOSECONDS = 0x05, + UDP_PERFORMANCE_SAMPLE_UNIT_BITS = 0x06, + UDP_PERFORMANCE_SAMPLE_UNIT_KBITS = 0x07, //NOTE: Base 1000 + UDP_PERFORMANCE_SAMPLE_UNIT_MBITS = 0x08, //NOTE: Base 1000 + UDP_PERFORMANCE_SAMPLE_UNIT_KIBITS = 0x09, //NOTE: Base 1024 + UDP_PERFORMANCE_SAMPLE_UNIT_MIBITS = 0x0A, //NOTE: Base 1024 + UDP_PERFORMANCE_SAMPLE_UNIT_BYTES = 0x0B, + UDP_PERFORMANCE_SAMPLE_UNIT_KBYTES = 0x0C, //NOTE: Base 1000 + UDP_PERFORMANCE_SAMPLE_UNIT_MBYTES = 0x0D, //NOTE: Base 1000 + UDP_PERFORMANCE_SAMPLE_UNIT_KIBYTES = 0x0E, //NOTE: Base 1024 + UDP_PERFORMANCE_SAMPLE_UNIT_MIBYTES = 0x0F, //NOTE: Base 1024 + UDP_PERFORMANCE_SAMPLE_UNIT_UNDEFINED_PER_SECOND = 0x10, + UDP_PERFORMANCE_SAMPLE_UNIT_BITS_PER_SECOND = 0x11, + UDP_PERFORMANCE_SAMPLE_UNIT_KBITS_PER_SECOND = 0x12, //NOTE: Base 1000 + UDP_PERFORMANCE_SAMPLE_UNIT_MBITS_PER_SECOND = 0x13, //NOTE: Base 1000 }; typedef uint32_t UDPFrameId; @@ -235,22 +247,6 @@ struct UDPPacketFrameMetadata //Followed by: Metadata }; -struct UDPPacketLatency -{ - UDPPacketId id = UDP_PACKET_ID_LATENCY; - uint32_t size = 0; - - UDPFrameNumber frame_number; - UDPFrameId frame_id; - UDPTransformId transform_id; - - double timestamp_transform_query = 0.0; - double timestamp_server_response = 0.0; - double timestamp_frame_decoded = 0.0; - double timestamp_command_construct = 0.0; - double timestamp_command_executed = 0.0; -}; - struct UDPPacketOverlayConfig { UDPPacketId id = UDP_PACKET_ID_OVERLAY_CONFIG; diff --git a/src/transport/udp_transport.cpp b/src/transport/udp_transport.cpp index f71f7969cb1c8a43626aea1888f44319c352306b..311101a55ee025b2f0960709ac85fe491ab34938 100644 --- a/src/transport/udp_transport.cpp +++ b/src/transport/udp_transport.cpp @@ -374,11 +374,6 @@ void UDPTransport::set_on_controller_thumbstick(OnControllerThumbstick function) this->on_controller_thumbstick = std::move(function); } -void UDPTransport::set_on_latency(OnLatency function) -{ - this->on_latency = std::move(function); -} - void UDPTransport::set_on_performance_sample(OnPerformanceSample function) { this->on_performance_sample = std::move(function); @@ -606,8 +601,7 @@ void UDPTransport::receive_datagram() case UDP_PACKET_ID_CONTROLLER_TRANSFORM: case UDP_PACKET_ID_CONTROLLER_EVENT: case UDP_PACKET_ID_CONTROLLER_BUTTON: - case UDP_PACKET_ID_CONTROLLER_THUMBSTICK: - case UDP_PACKET_ID_LATENCY: + case UDP_PACKET_ID_CONTROLLER_THUMBSTICK: case UDP_PACKET_ID_PERFORMANCE_SAMPLE: this->receive_queue.push_back(datagram); break; @@ -763,9 +757,6 @@ void UDPTransport::process_receive_queue() case UDP_PACKET_ID_CONTROLLER_THUMBSTICK: this->parse_controller_thumbstick(datagram); break; - case UDP_PACKET_ID_LATENCY: - this->parse_latency(datagram); - break; case UDP_PACKET_ID_PERFORMANCE_SAMPLE: this->parse_performance_sample(datagram); break; @@ -964,22 +955,6 @@ void UDPTransport::parse_controller_thumbstick(const Datagram& datagram) this->on_controller_thumbstick(controller, packet->thumbstick); } -void UDPTransport::parse_latency(const Datagram& datagram) -{ - UDPPacketLatency* packet = (UDPPacketLatency*)datagram.buffer; - - if (packet->id != UDP_PACKET_ID_LATENCY) - { - lava::log()->error("UDP-Transport: Wrong packet id for latency packet!"); - this->on_transport_error(); - this->set_state(TRANSPORT_STATE_ERROR); - - return; - } - - this->on_latency(packet->frame_number, packet->frame_id, packet->transform_id, packet->timestamp_transform_query, packet->timestamp_server_response, packet->timestamp_frame_decoded, packet->timestamp_command_construct, packet->timestamp_command_executed); -} - void UDPTransport::parse_performance_sample(const Datagram& datagram) { UDPPacketPerformanceSample* packet = (UDPPacketPerformanceSample*)datagram.buffer; diff --git a/src/transport/udp_transport.hpp b/src/transport/udp_transport.hpp index efbcbac993e6f5b319fbc976fe45bf55e0abb036..4a80198c49d7c6cdf3b49307be3a4fd1797ad75a 100644 --- a/src/transport/udp_transport.hpp +++ b/src/transport/udp_transport.hpp @@ -39,7 +39,6 @@ public: void set_on_controller_event(OnControllerEvent function) override; void set_on_controller_button(OnControllerButton function) override; void set_on_controller_thumbstick(OnControllerThumbstick function) override; - void set_on_latency(OnLatency function) override; void set_on_performance_sample(OnPerformanceSample function) override; void set_on_transport_error(OnTransportError function) override; @@ -69,7 +68,6 @@ private: void parse_controller_event(const Datagram& datagram); void parse_controller_button(const Datagram& datagram); void parse_controller_thumbstick(const Datagram& datagram); - void parse_latency(const Datagram& datagram); void parse_performance_sample(const Datagram& datagram); private: @@ -105,7 +103,6 @@ private: OnControllerEvent on_controller_event; OnControllerButton on_controller_button; OnControllerThumbstick on_controller_thumbstick; - OnLatency on_latency; OnPerformanceSample on_performance_sample; OnTransportError on_transport_error; }; \ No newline at end of file diff --git a/src/utility/latency.cpp b/src/utility/latency.cpp deleted file mode 100644 index 87d9f3a0e2586912eeb5a24e32091d025c87e2aa..0000000000000000000000000000000000000000 --- a/src/utility/latency.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "latency.hpp" -#include <liblava/lava.hpp> -#include <fstream> -#include <chrono> -#include <filesystem> - -LatencyStatistic::LatencyStatistic(const std::string& base_directory) : base_directory(base_directory) -{ - this->statistic_total_latency = make_statistic("Total Latency", UNIT_MILLISECONDS); - this->statistic_server_response = make_statistic("Server Response", UNIT_MILLISECONDS); - this->statistic_frame_decoded = make_statistic("Frame Decoded", UNIT_MILLISECONDS); - this->statistic_command_construct = make_statistic("Command Construct", UNIT_MILLISECONDS); - this->statistic_command_executed = make_statistic("Command Executed", UNIT_MILLISECONDS); -} - -void LatencyStatistic::interface() -{ - this->statistic_total_latency->interface(128); - this->statistic_server_response->interface(128); - this->statistic_frame_decoded->interface(128); - this->statistic_command_construct->interface(128); - this->statistic_command_executed->interface(128); -} - -bool LatencyStatistic::write_to_file() -{ - if (!std::filesystem::exists(this->base_directory)) - { - std::filesystem::create_directory(this->base_directory); - } - - return this->write_captures(); -} - -void LatencyStatistic::submit_capture(const LatencyCapture& capture) -{ - double total_latency = capture.timestamp_command_executed - capture.timestamp_transform_query; - double server_response = capture.timestamp_server_response - capture.timestamp_transform_query; - double frame_decoded = capture.timestamp_frame_decoded - capture.timestamp_server_response; - double command_construct = capture.timestamp_command_construct - capture.timestamp_frame_decoded; - double command_executed = capture.timestamp_command_executed - capture.timestamp_command_construct; - - this->statistic_total_latency->add_sample(total_latency); - this->statistic_server_response->add_sample(server_response); - this->statistic_frame_decoded->add_sample(frame_decoded); - this->statistic_command_construct->add_sample(command_construct); - this->statistic_command_executed->add_sample(command_executed); - - this->captures.push_back(capture); -} - -void LatencyStatistic::clear_captures() -{ - this->captures.clear(); -} - -const Statistic::Ptr& LatencyStatistic::get_total_latency() const -{ - return this->statistic_total_latency; -} - -const Statistic::Ptr& LatencyStatistic::get_server_response() const -{ - return this->statistic_server_response; -} - -const Statistic::Ptr& LatencyStatistic::get_frame_decoded() const -{ - return this->statistic_frame_decoded; -} - -const Statistic::Ptr& LatencyStatistic::get_command_construct() const -{ - return this->statistic_command_construct; -} - -const Statistic::Ptr& LatencyStatistic::get_command_executed() const -{ - return this->statistic_command_executed; -} - -bool LatencyStatistic::write_captures() -{ - std::string file_name = this->build_file_name(); - - std::fstream file; - file.open(this->base_directory + "/" + file_name, std::ios::out); - - if (!file.good()) - { - lava::log()->error("can't write to file '" + file_name + "' for pass statistic"); - - return false; - } - - file << "frame_id; "; - file << "frame_number; "; - file << "transform_id; "; - file << "timestamp_transform_query; "; - file << "timestamp_server_response; "; - file << "timestamp_frame_decoded; "; - file << "timestamp_command_construct; "; - file << "timestamp_command_executed; "; - file << "total_latency" << std::endl; - - file << std::fixed << std::setprecision(3); - - for (const LatencyCapture& capture : this->captures) - { - double total_latency = capture.timestamp_command_executed - capture.timestamp_transform_query; - - file << capture.frame_id << "; "; - file << capture.frame_number << "; "; - file << capture.transform_id << "; "; - file << capture.timestamp_transform_query << "; "; - file << capture.timestamp_server_response << "; "; - file << capture.timestamp_frame_decoded << "; "; - file << capture.timestamp_command_construct << "; "; - file << capture.timestamp_command_executed << "; "; - file << total_latency << std::endl; - } - - return true; -} - -std::string LatencyStatistic::build_file_name() -{ - time_t system_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - tm local_time = *localtime(&system_time); - - std::string name = "latency"; - name += "_" + std::to_string(local_time.tm_mday); - name += "-" + std::to_string(local_time.tm_mon + 1); - name += "-" + std::to_string(local_time.tm_year + 1900); - name += "_" + std::to_string(local_time.tm_hour); - name += "-" + std::to_string(local_time.tm_min); - name += "-" + std::to_string(local_time.tm_sec); - name += ".csv"; - - return name; -} - -LatencyStatistic::Ptr make_latency_statistic(const std::string& base_directory) -{ - return std::make_shared<LatencyStatistic>(base_directory); -} \ No newline at end of file diff --git a/src/utility/latency.hpp b/src/utility/latency.hpp deleted file mode 100644 index a479ad29c384992fcd13465eb3c8ce8ba4e12d66..0000000000000000000000000000000000000000 --- a/src/utility/latency.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - A latency statistic can be used to store the latencies in case of an remote headset. - When calling write_to_file(...), the values submitted to the statistic are written to a csv-file. - The created file can be found in the base directory which was specified during the creation. - Example: - - LatencyStatistic::Ptr statistic = make_latency_statistic("latency"); - - statistic->submit_capture(...); - statistic->write_to_file(); -*/ - -#pragma once -#include <vector> -#include <string> -#include <memory> -#include <cstdint> - -#include "utility/statistic.hpp" - -struct LatencyCapture -{ - uint32_t frame_id = 0; - uint32_t frame_number = 0; - uint32_t transform_id = 0; - - double timestamp_transform_query = 0.0; - double timestamp_server_response = 0.0; - double timestamp_frame_decoded = 0.0; - double timestamp_command_construct = 0.0; - double timestamp_command_executed = 0.0; -}; - -class LatencyStatistic -{ -public: - typedef std::shared_ptr<LatencyStatistic> Ptr; - -public: - LatencyStatistic(const std::string& base_directory); - - void interface(); - bool write_to_file(); - - void submit_capture(const LatencyCapture& capture); - void clear_captures(); - - const Statistic::Ptr& get_total_latency() const; - const Statistic::Ptr& get_server_response() const; - const Statistic::Ptr& get_frame_decoded() const; - const Statistic::Ptr& get_command_construct() const; - const Statistic::Ptr& get_command_executed() const; - -private: - bool write_captures(); - - std::string build_file_name(); - -private: - std::string base_directory = ""; - std::vector<LatencyCapture> captures; - - Statistic::Ptr statistic_total_latency; - Statistic::Ptr statistic_server_response; - Statistic::Ptr statistic_frame_decoded; - Statistic::Ptr statistic_command_construct; - Statistic::Ptr statistic_command_executed; -}; - -LatencyStatistic::Ptr make_latency_statistic(const std::string& base_directory); \ No newline at end of file