From 16d3dc100424dc6f8b94f8e3ba4a8f034f069a30 Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Wed, 15 Nov 2023 14:20:44 +0500 Subject: [PATCH] Added stat counter for desktop session. --- source/host/CMakeLists.txt | 2 + source/host/client_session_desktop.cc | 22 +++++- source/host/client_session_desktop.h | 3 + source/host/stat_counter.cc | 106 ++++++++++++++++++++++++++ source/host/stat_counter.h | 67 ++++++++++++++++ 5 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 source/host/stat_counter.cc create mode 100644 source/host/stat_counter.h diff --git a/source/host/CMakeLists.txt b/source/host/CMakeLists.txt index bad2071216..bc470ec3a3 100644 --- a/source/host/CMakeLists.txt +++ b/source/host/CMakeLists.txt @@ -67,6 +67,8 @@ list(APPEND SOURCE_HOST_CORE service_constants.h service_main.cc service_main.h + stat_counter.cc + stat_counter.h system_settings.cc system_settings.h unconfirmed_client_session.cc diff --git a/source/host/client_session_desktop.cc b/source/host/client_session_desktop.cc index d94c6a43f0..1ee982df01 100644 --- a/source/host/client_session_desktop.cc +++ b/source/host/client_session_desktop.cc @@ -65,9 +65,10 @@ ClientSessionDesktop::ClientSessionDesktop(proto::SessionType session_type, std::unique_ptr channel, std::shared_ptr task_runner) : ClientSession(session_type, std::move(channel)), - overflow_detection_timer_(base::WaitableTimer::Type::REPEATED, std::move(task_runner)), + overflow_detection_timer_(base::WaitableTimer::Type::REPEATED, task_runner), incoming_message_(std::make_unique()), - outgoing_message_(std::make_unique()) + outgoing_message_(std::make_unique()), + stat_counter_(id(), task_runner) { LOG(LS_INFO) << "Ctor"; } @@ -194,21 +195,31 @@ void ClientSessionDesktop::onReceived(uint8_t /* channel_id */, const base::Byte out_mouse_event.set_y(pos_y); desktop_session_proxy_->injectMouseEvent(out_mouse_event); + stat_counter_.addMouseEvent(); } else if (incoming_message_->has_key_event()) { if (sessionType() == proto::SESSION_TYPE_DESKTOP_MANAGE) + { desktop_session_proxy_->injectKeyEvent(incoming_message_->key_event()); + stat_counter_.addKeyboardEvent(); + } } else if (incoming_message_->has_text_event()) { if (sessionType() == proto::SESSION_TYPE_DESKTOP_MANAGE) + { desktop_session_proxy_->injectTextEvent(incoming_message_->text_event()); + stat_counter_.addTextEvent(); + } } else if (incoming_message_->has_clipboard_event()) { if (sessionType() == proto::SESSION_TYPE_DESKTOP_MANAGE) + { desktop_session_proxy_->injectClipboardEvent(incoming_message_->clipboard_event()); + stat_counter_.addIncomingClipboardEvent(); + } } else if (incoming_message_->has_extension()) { @@ -332,7 +343,10 @@ void ClientSessionDesktop::encodeScreen(const base::Frame* frame, const base::Mo } if (outgoing_message_->has_video_packet() || outgoing_message_->has_cursor_shape()) + { sendMessage(proto::HOST_CHANNEL_ID_SESSION, base::serialize(*outgoing_message_)); + stat_counter_.addVideoPacket(); + } } //-------------------------------------------------------------------------------------------------- @@ -350,6 +364,7 @@ void ClientSessionDesktop::encodeAudio(const proto::AudioPacket& audio_packet) return; sendMessage(proto::HOST_CHANNEL_ID_SESSION, base::serialize(*outgoing_message_)); + stat_counter_.addAudioPacket(); } //-------------------------------------------------------------------------------------------------- @@ -366,6 +381,7 @@ void ClientSessionDesktop::setVideoErrorCode(proto::VideoErrorCode error_code) outgoing_message_->Clear(); outgoing_message_->mutable_video_packet()->set_error_code(error_code); sendMessage(proto::HOST_CHANNEL_ID_SESSION, base::serialize(*outgoing_message_)); + stat_counter_.addVideoError(); } //-------------------------------------------------------------------------------------------------- @@ -386,6 +402,7 @@ void ClientSessionDesktop::setCursorPosition(const proto::CursorPosition& cursor position->set_y(pos_y); sendMessage(proto::HOST_CHANNEL_ID_SESSION, base::serialize(*outgoing_message_)); + stat_counter_.addCursorPosition(); } //-------------------------------------------------------------------------------------------------- @@ -418,6 +435,7 @@ void ClientSessionDesktop::injectClipboardEvent(const proto::ClipboardEvent& eve outgoing_message_->Clear(); outgoing_message_->mutable_clipboard_event()->CopyFrom(event); sendMessage(proto::HOST_CHANNEL_ID_SESSION, base::serialize(*outgoing_message_)); + stat_counter_.addOutgoingClipboardEvent(); } else { diff --git a/source/host/client_session_desktop.h b/source/host/client_session_desktop.h index be020ab979..6177b8aa90 100644 --- a/source/host/client_session_desktop.h +++ b/source/host/client_session_desktop.h @@ -26,6 +26,7 @@ #include "base/waitable_timer.h" #include "host/client_session.h" #include "host/desktop_session.h" +#include "host/stat_counter.h" #if defined(OS_WIN) #include "host/task_manager.h" @@ -121,6 +122,8 @@ class ClientSessionDesktop std::unique_ptr incoming_message_; std::unique_ptr outgoing_message_; + StatCounter stat_counter_; + DISALLOW_COPY_AND_ASSIGN(ClientSessionDesktop); }; diff --git a/source/host/stat_counter.cc b/source/host/stat_counter.cc new file mode 100644 index 0000000000..c1875ebdc6 --- /dev/null +++ b/source/host/stat_counter.cc @@ -0,0 +1,106 @@ +// +// Aspia Project +// Copyright (C) 2016-2023 Dmitry Chapyshev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "host/stat_counter.h" + +#include "base/logging.h" + +namespace host { + +//-------------------------------------------------------------------------------------------------- +StatCounter::StatCounter(uint32_t client_session_id, std::shared_ptr task_runner) + : client_session_id_(client_session_id), + timer_(base::WaitableTimer::Type::REPEATED, std::move(task_runner)) +{ + timer_.start(std::chrono::seconds(30), std::bind(&StatCounter::onTimeout, this)); +} + +//-------------------------------------------------------------------------------------------------- +StatCounter::~StatCounter() +{ + timer_.stop(); +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addVideoPacket() +{ + ++video_packets_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addAudioPacket() +{ + ++audio_packets_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addIncomingClipboardEvent() +{ + ++incoming_clipboard_events_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addOutgoingClipboardEvent() +{ + ++outgoing_clipboard_events_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addKeyboardEvent() +{ + ++keyboard_events_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addTextEvent() +{ + ++text_events_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addMouseEvent() +{ + ++mouse_events_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addVideoError() +{ + ++video_error_count_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::addCursorPosition() +{ + ++cursor_positions_; +} + +//-------------------------------------------------------------------------------------------------- +void StatCounter::onTimeout() +{ + LOG(LS_INFO) << "### Statistics (sid=" << client_session_id_ << "###"; + LOG(LS_INFO) << "Packets: video=" << video_packets_ << " audio=" << audio_packets_ + << " video_error=" << video_error_count_; + LOG(LS_INFO) << "Clipboard: in=" << incoming_clipboard_events_ + << " out=" << outgoing_clipboard_events_; + LOG(LS_INFO) << "Input: keyboard=" << keyboard_events_ << " mouse=" << mouse_events_ + << " text=" << text_events_; + LOG(LS_INFO) << "Cursor positions: " << cursor_positions_; +} + +} // namespace host diff --git a/source/host/stat_counter.h b/source/host/stat_counter.h new file mode 100644 index 0000000000..7296ce074b --- /dev/null +++ b/source/host/stat_counter.h @@ -0,0 +1,67 @@ +// +// Aspia Project +// Copyright (C) 2016-2023 Dmitry Chapyshev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef HOST_STAT_COUNTER_H +#define HOST_STAT_COUNTER_H + +#include "base/macros_magic.h" +#include "base/waitable_timer.h" + +#include + +namespace host { + +class StatCounter +{ +public: + StatCounter(uint32_t client_session_id, std::shared_ptr task_runner); + ~StatCounter(); + + void addVideoPacket(); + void addAudioPacket(); + void addIncomingClipboardEvent(); + void addOutgoingClipboardEvent(); + void addKeyboardEvent(); + void addTextEvent(); + void addMouseEvent(); + void addVideoError(); + void addCursorPosition(); + +private: + void onTimeout(); + + const uint32_t client_session_id_; + + base::WaitableTimer timer_; + + uint64_t video_packets_ = 0; + uint64_t audio_packets_ = 0; + uint64_t incoming_clipboard_events_ = 0; + uint64_t outgoing_clipboard_events_ = 0; + uint64_t keyboard_events_ = 0; + uint64_t text_events_ = 0; + uint64_t mouse_events_ = 0; + uint64_t video_error_count_ = 0; + uint64_t cursor_positions_ = 0; + + DISALLOW_COPY_AND_ASSIGN(StatCounter); +}; + +} // namespace host + +#endif // HOST_STAT_COUNTER_H