mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use thread_local counter in logs for thread index.
This commit is contained in:
parent
8b14249cd2
commit
3a7faffa3a
3 changed files with 10 additions and 24 deletions
|
@ -8,10 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
|
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "mtproto/connection.h"
|
|
||||||
#include "core/crash_reports.h"
|
#include "core/crash_reports.h"
|
||||||
#include "core/launcher.h"
|
#include "core/launcher.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::atomic<int> ThreadCounter/* = 0*/;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
enum LogDataType {
|
enum LogDataType {
|
||||||
LogDataMain,
|
LogDataMain,
|
||||||
LogDataDebug,
|
LogDataDebug,
|
||||||
|
@ -45,11 +50,10 @@ QString _logsFilePath(LogDataType type, const QString &postfix = QString()) {
|
||||||
|
|
||||||
int32 LogsStartIndexChosen = -1;
|
int32 LogsStartIndexChosen = -1;
|
||||||
QString _logsEntryStart() {
|
QString _logsEntryStart() {
|
||||||
static int32 index = 0;
|
static thread_local auto threadId = ThreadCounter++;
|
||||||
QDateTime tm(QDateTime::currentDateTime());
|
static auto index = 0;
|
||||||
|
|
||||||
auto thread = qobject_cast<MTP::internal::Thread*>(QThread::currentThread());
|
const auto tm = QDateTime::currentDateTime();
|
||||||
auto threadId = thread ? thread->getThreadIndex() : 0;
|
|
||||||
|
|
||||||
return QString("[%1 %2-%3]").arg(tm.toString("hh:mm:ss.zzz")).arg(QString("%1").arg(threadId, 2, 10, QChar('0'))).arg(++index, 7, 10, QChar('0'));
|
return QString("[%1 %2-%3]").arg(tm.toString("hh:mm:ss.zzz")).arg(QString("%1").arg(threadId, 2, 10, QChar('0'))).arg(++index, 7, 10, QChar('0'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ Connection::Connection(not_null<Instance*> instance)
|
||||||
void Connection::start(SessionData *sessionData, ShiftedDcId shiftedDcId) {
|
void Connection::start(SessionData *sessionData, ShiftedDcId shiftedDcId) {
|
||||||
Expects(_thread == nullptr && _private == nullptr);
|
Expects(_thread == nullptr && _private == nullptr);
|
||||||
|
|
||||||
_thread = std::make_unique<Thread>();
|
_thread = std::make_unique<QThread>();
|
||||||
auto newData = std::make_unique<ConnectionPrivate>(
|
auto newData = std::make_unique<ConnectionPrivate>(
|
||||||
_instance,
|
_instance,
|
||||||
_thread.get(),
|
_thread.get(),
|
||||||
|
|
|
@ -33,24 +33,6 @@ class SessionData;
|
||||||
class RSAPublicKey;
|
class RSAPublicKey;
|
||||||
struct ConnectionOptions;
|
struct ConnectionOptions;
|
||||||
|
|
||||||
class Thread : public QThread {
|
|
||||||
// The Q_OBJECT meta info is used for qobject_cast!
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
Thread() {
|
|
||||||
static int ThreadCounter = 0;
|
|
||||||
_threadIndex = ++ThreadCounter;
|
|
||||||
}
|
|
||||||
int getThreadIndex() const {
|
|
||||||
return _threadIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _threadIndex = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
public:
|
public:
|
||||||
enum ConnectionType {
|
enum ConnectionType {
|
||||||
|
|
Loading…
Add table
Reference in a new issue