Various improvements.
GitOrigin-RevId: 4eb8b7e43d10f1b5657f40aa2b7eef1c93429ca7
This commit is contained in:
parent
4635b7b791
commit
c055ec15f9
@ -452,7 +452,6 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/net/MtprotoHeader.cpp
|
td/telegram/net/MtprotoHeader.cpp
|
||||||
td/telegram/net/NetActor.cpp
|
td/telegram/net/NetActor.cpp
|
||||||
td/telegram/net/NetQuery.cpp
|
td/telegram/net/NetQuery.cpp
|
||||||
td/telegram/net/NetQueryCounter.cpp
|
|
||||||
td/telegram/net/NetQueryCreator.cpp
|
td/telegram/net/NetQueryCreator.cpp
|
||||||
td/telegram/net/NetQueryDelayer.cpp
|
td/telegram/net/NetQueryDelayer.cpp
|
||||||
td/telegram/net/NetQueryDispatcher.cpp
|
td/telegram/net/NetQueryDispatcher.cpp
|
||||||
|
@ -288,7 +288,7 @@ class TdReceiver {
|
|||||||
|
|
||||||
class MultiImpl {
|
class MultiImpl {
|
||||||
public:
|
public:
|
||||||
MultiImpl(std::shared_ptr<NetQueryStats> net_query_stats) {
|
explicit MultiImpl(std::shared_ptr<NetQueryStats> net_query_stats) {
|
||||||
concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>();
|
concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>();
|
||||||
concurrent_scheduler_->init(3);
|
concurrent_scheduler_->init(3);
|
||||||
concurrent_scheduler_->start();
|
concurrent_scheduler_->start();
|
||||||
@ -369,10 +369,6 @@ class MultiImplPool {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<NetQueryStats> get_net_query_stats() const {
|
|
||||||
return net_query_stats_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
std::vector<std::weak_ptr<MultiImpl>> impls_;
|
std::vector<std::weak_ptr<MultiImpl>> impls_;
|
||||||
|
@ -8,19 +8,19 @@
|
|||||||
|
|
||||||
///\file
|
///\file
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
#include "td/telegram/TdCallback.h"
|
||||||
|
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/td_api.hpp"
|
#include "td/telegram/td_api.hpp"
|
||||||
|
|
||||||
#include "td/telegram/TdCallback.h"
|
#include "td/actor/actor.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class Td;
|
|
||||||
class NetQueryStats;
|
class NetQueryStats;
|
||||||
|
class Td;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a low-level Actor interface for interaction with TDLib. The interface is a lot more flexible than
|
* This is a low-level Actor interface for interaction with TDLib. The interface is a lot more flexible than
|
||||||
@ -30,6 +30,9 @@ class ClientActor : public Actor {
|
|||||||
public:
|
public:
|
||||||
struct Options {
|
struct Options {
|
||||||
std::shared_ptr<NetQueryStats> net_query_stats;
|
std::shared_ptr<NetQueryStats> net_query_stats;
|
||||||
|
|
||||||
|
Options() {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,7 +423,7 @@ class Global : public ActorContext {
|
|||||||
|
|
||||||
ActorId<StateManager> state_manager_;
|
ActorId<StateManager> state_manager_;
|
||||||
|
|
||||||
LazySchedulerLocalStorage<td::unique_ptr<NetQueryCreator>> net_query_creator_;
|
LazySchedulerLocalStorage<unique_ptr<NetQueryCreator>> net_query_creator_;
|
||||||
unique_ptr<NetQueryDispatcher> net_query_dispatcher_;
|
unique_ptr<NetQueryDispatcher> net_query_dispatcher_;
|
||||||
|
|
||||||
unique_ptr<ConfigShared> shared_config_;
|
unique_ptr<ConfigShared> shared_config_;
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
#include "td/telegram/files/FileId.h"
|
#include "td/telegram/files/FileId.h"
|
||||||
#include "td/telegram/net/MtprotoHeader.h"
|
#include "td/telegram/net/MtprotoHeader.h"
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
|
#include "td/telegram/net/NetQueryStats.h"
|
||||||
#include "td/telegram/StateManager.h"
|
#include "td/telegram/StateManager.h"
|
||||||
#include "td/telegram/TdCallback.h"
|
#include "td/telegram/TdCallback.h"
|
||||||
#include "td/telegram/TdParameters.h"
|
#include "td/telegram/TdParameters.h"
|
||||||
#include "td/telegram/TermsOfService.h"
|
#include "td/telegram/TermsOfService.h"
|
||||||
|
|
||||||
#include "td/telegram/net/NetQueryStats.h"
|
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
#include "td/telegram/net/NetQueryCounter.h"
|
|
||||||
|
|
||||||
namespace td {
|
|
||||||
|
|
||||||
std::atomic<uint64> NetQueryCounter::counter_{0};
|
|
||||||
|
|
||||||
} // namespace td
|
|
@ -9,38 +9,31 @@
|
|||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class NetQueryCounter {
|
class NetQueryCounter {
|
||||||
public:
|
public:
|
||||||
using Counter = std::atomic<uint64>;
|
using Counter = std::atomic<uint64>;
|
||||||
// deprecated
|
|
||||||
NetQueryCounter(bool is_alive = false) {
|
|
||||||
if (is_alive) {
|
|
||||||
*this = NetQueryCounter(&counter_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64 get_count() {
|
NetQueryCounter() = default;
|
||||||
return counter_.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
NetQueryCounter(Counter *counter) : ptr_(counter) {
|
explicit NetQueryCounter(Counter *counter) : ptr_(counter) {
|
||||||
counter->fetch_add(1);
|
CHECK(counter != nullptr);
|
||||||
|
counter->fetch_add(1, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
return (bool)ptr_;
|
return static_cast<bool>(ptr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Deleter {
|
struct Deleter {
|
||||||
void operator()(Counter *ptr) {
|
void operator()(Counter *ptr) {
|
||||||
ptr->fetch_sub(1);
|
ptr->fetch_sub(1, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static Counter counter_;
|
|
||||||
std::unique_ptr<Counter, Deleter> ptr_;
|
std::unique_ptr<Counter, Deleter> ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
|
#include "td/telegram/net/NetQueryStats.h"
|
||||||
#include "td/telegram/UniqueId.h"
|
#include "td/telegram/UniqueId.h"
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
|
@ -8,12 +8,13 @@
|
|||||||
|
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
|
|
||||||
#include "td/utils/logging.h"
|
|
||||||
#include "td/utils/format.h"
|
#include "td/utils/format.h"
|
||||||
|
#include "td/utils/logging.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
uint64 NetQueryStats::get_count() const {
|
uint64 NetQueryStats::get_count() const {
|
||||||
return count_;
|
return count_.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetQueryStats::dump_pending_network_queries() {
|
void NetQueryStats::dump_pending_network_queries() {
|
||||||
|
@ -5,14 +5,16 @@
|
|||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/telegram/net/NetQueryCounter.h"
|
#include "td/telegram/net/NetQueryCounter.h"
|
||||||
|
|
||||||
#include "td/utils/int_types.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/TsList.h"
|
#include "td/utils/TsList.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
struct NetQueryDebug {
|
struct NetQueryDebug {
|
||||||
double start_timestamp_ = 0;
|
double start_timestamp_ = 0;
|
||||||
int32 my_id_ = 0;
|
int32 my_id_ = 0;
|
||||||
@ -27,11 +29,6 @@ struct NetQueryDebug {
|
|||||||
|
|
||||||
class NetQueryStats {
|
class NetQueryStats {
|
||||||
public:
|
public:
|
||||||
[[deprecated]] static NetQueryStats &get_default_stats() {
|
|
||||||
static NetQueryStats res;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetQueryCounter register_query(TsListNode<NetQueryDebug> *query) {
|
NetQueryCounter register_query(TsListNode<NetQueryDebug> *query) {
|
||||||
if (use_list_.load(std::memory_order_relaxed)) {
|
if (use_list_.load(std::memory_order_relaxed)) {
|
||||||
list_.put(query);
|
list_.put(query);
|
||||||
@ -40,6 +37,7 @@ class NetQueryStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64 get_count() const;
|
uint64 get_count() const;
|
||||||
|
|
||||||
void dump_pending_network_queries();
|
void dump_pending_network_queries();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -47,4 +45,5 @@ class NetQueryStats {
|
|||||||
std::atomic<bool> use_list_{true};
|
std::atomic<bool> use_list_{true};
|
||||||
TsList<NetQueryDebug> list_;
|
TsList<NetQueryDebug> list_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
x
Reference in New Issue
Block a user