ZaStoGram/TMessagesProj/jni/tgnet/BuffersStorage.h
loop-uh e36f09b3e5 Add network debug logging with throttling and metrics
Introduces enhanced debugging infrastructure for network operations:

- Added NetworkDebugCounters namespace to track partial packet statistics using atomic counters
- Added throttled logging for unmapped TL constructors to prevent log spam, with per-constructor statistics and configurable intervals
- Improved debug message formats with more context (assembled bytes, constructor types, action context)
- Renamed debug messages to use clearer naming convention (e.g., tl_debug_unmapped_packet)

These changes enable better visibility into network operations while controlling log volume through intelligent throttling.
2026-06-27 20:03:11 +03:00

48 lines
1.3 KiB
C++

/*
* This is the source code of tgnet library v. 1.1
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2015-2018.
*/
#ifndef BUFFERSSTORAGE_H
#define BUFFERSSTORAGE_H
#include <vector>
#include <map>
#include <pthread.h>
#include <stdint.h>
class NativeByteBuffer;
struct BufferPoolDebugStats {
uint32_t allocFallbackCount = 0;
uint32_t reusedCount = 0;
uint32_t peakCachedCount = 0;
int64_t lastSummaryLogTime = 0;
};
class BuffersStorage {
public:
BuffersStorage(bool threadSafe);
NativeByteBuffer *getFreeBuffer(uint32_t size);
void reuseFreeBuffer(NativeByteBuffer *buffer);
static BuffersStorage &getInstance();
private:
std::vector<NativeByteBuffer *> freeBuffers8;
std::vector<NativeByteBuffer *> freeBuffers128;
std::vector<NativeByteBuffer *> freeBuffers1024;
std::vector<NativeByteBuffer *> freeBuffers4096;
std::vector<NativeByteBuffer *> freeBuffers16384;
std::vector<NativeByteBuffer *> freeBuffers32768;
std::vector<NativeByteBuffer *> freeBuffersBig;
std::map<uint32_t, int64_t> lastPressureLogByCapacity;
std::map<uint32_t, BufferPoolDebugStats> bufferPoolStatsByCapacity;
bool isThreadSafe = true;
pthread_mutex_t mutex;
};
#endif