(ws connect) display statistics about how much time it takes to stop the connection / cf #168

This commit is contained in:
Benjamin Sergeant 2020-03-24 20:29:09 -07:00
parent 179e17895d
commit 37cb2cc266
7 changed files with 91 additions and 48 deletions

View File

@ -1,6 +1,10 @@
# Changelog
All changes to this project will be documented in this file.
## [9.0.3] - 2020-03-24
(ws connect) display statistics about how much time it takes to stop the connection
## [9.0.2] - 2020-03-24
(socket) works with unique_ptr<Socket> instead of shared_ptr<Socket> in many places

View File

@ -6,4 +6,4 @@
#pragma once
#define IX_WEBSOCKET_VERSION "9.0.2"
#define IX_WEBSOCKET_VERSION "9.0.3"

View File

@ -35,6 +35,7 @@ endif()
add_executable(ws
../third_party/msgpack11/msgpack11.cpp
${JSONCPP_SOURCES}
IXBench.cpp
ws_http_client.cpp
ws_ping_pong.cpp

44
ws/IXBench.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
* IXBench.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
*/
#include "IXBench.h"
#include <spdlog/spdlog.h>
namespace ix
{
Bench::Bench(const std::string& description)
: _description(description)
, _start(std::chrono::system_clock::now())
, _reported(false)
{
;
}
Bench::~Bench()
{
if (!_reported)
{
report();
}
}
void Bench::report()
{
auto now = std::chrono::system_clock::now();
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start);
_ms = milliseconds.count();
spdlog::info("{} completed in {} ms", _description, _ms);
_reported = true;
}
uint64_t Bench::getDuration() const
{
return _ms;
}
}

28
ws/IXBench.h Normal file
View File

@ -0,0 +1,28 @@
/*
* IXBench.h
* Author: Benjamin Sergeant
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
*/
#include <string>
#include <chrono>
#include <stdint.h>
namespace ix
{
class Bench
{
public:
Bench(const std::string& description);
~Bench();
void report();
uint64_t getDuration() const;
private:
std::string _description;
std::chrono::time_point<std::chrono::system_clock> _start;
uint64_t _ms;
bool _reported;
};
}

View File

@ -4,10 +4,12 @@
* Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved.
*/
#include "linenoise.hpp"
#include "IXBench.h"
#include <ixwebsocket/IXSocket.h>
#include <ixwebsocket/IXSocketTLSOptions.h>
#include <ixwebsocket/IXWebSocket.h>
#include "linenoise.hpp"
#include <spdlog/spdlog.h>
#include <sstream>
@ -129,7 +131,10 @@ namespace ix
void WebSocketConnect::stop()
{
_webSocket.stop();
{
Bench bench("ws_connect: stop connection");
_webSocket.stop();
}
}
void WebSocketConnect::start()

View File

@ -4,9 +4,8 @@
* Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved.
*/
#include <chrono>
#include <condition_variable>
#include <fstream>
#include "IXBench.h"
#include <ixcrypto/IXBase64.h>
#include <ixcrypto/IXHash.h>
#include <ixcrypto/IXUuid.h>
@ -14,6 +13,10 @@
#include <ixwebsocket/IXSocketTLSOptions.h>
#include <ixwebsocket/IXWebSocket.h>
#include <msgpack11/msgpack11.hpp>
#include <chrono>
#include <condition_variable>
#include <fstream>
#include <mutex>
#include <spdlog/spdlog.h>
#include <sstream>
@ -195,48 +198,6 @@ namespace ix
_webSocket.start();
}
class Bench
{
public:
Bench(const std::string& description)
: _description(description)
, _start(std::chrono::system_clock::now())
, _reported(false)
{
;
}
~Bench()
{
if (!_reported)
{
report();
}
}
void report()
{
auto now = std::chrono::system_clock::now();
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start);
_ms = milliseconds.count();
spdlog::info("{} completed in {} ms", _description, _ms);
_reported = true;
}
uint64_t getDuration() const
{
return _ms;
}
private:
std::string _description;
std::chrono::time_point<std::chrono::system_clock> _start;
uint64_t _ms;
bool _reported;
};
bool WebSocketSender::sendMessage(const std::string& filename, bool throttle)
{
std::vector<uint8_t> content;