From 47c7f76f2cc38a8ad896dc79ac008706acbf4704 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 17 Mar 2016 21:03:08 +0300 Subject: [PATCH] added some additional logging for file downloadings --- Telegram/Deploy.sh | 3 -- Telegram/SourceFiles/facades.cpp | 4 ++ Telegram/SourceFiles/facades.h | 14 ++++++ .../SourceFiles/mtproto/mtpFileLoader.cpp | 44 +++++++++++++++++-- Telegram/SourceFiles/settingswidget.cpp | 18 ++++++-- 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Telegram/Deploy.sh b/Telegram/Deploy.sh index 4a54d780a..f87d403cf 100755 --- a/Telegram/Deploy.sh +++ b/Telegram/Deploy.sh @@ -188,7 +188,6 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ] || [ "$Build fi if [ "$DeployMac" == "1" ]; then - cp -v "$DeployPath/$UpdateFile" "$DropboxDeployPath/" cp -v "$DeployPath/$SetupFile" "$DropboxDeployPath/$DropboxSetupFile" if [ -d "$DropboxDeployPath/Telegram.app.dSYM" ]; then rm -rf "$DropboxDeployPath/Telegram.app.dSYM" @@ -196,7 +195,6 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ] || [ "$Build cp -rv "$DeployPath/Telegram.app.dSYM" "$DropboxDeployPath/" fi if [ "$DeployMac32" == "1" ]; then - mv -v "$Mac32DeployPath/$Mac32UpdateFile" "$DropboxDeployPath/" mv -v "$Mac32DeployPath/$Mac32SetupFile" "$DropboxDeployPath/$DropboxMac32SetupFile" if [ -d "$DropboxDeployPath/Telegram32.app.dSYM" ]; then rm -rf "$DropboxDeployPath/Telegram32.app.dSYM" @@ -207,7 +205,6 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ] || [ "$Build mv -v "$WinDeployPath/Telegram.pdb" "$DropboxDeployPath/" mv -v "$WinDeployPath/Updater.exe" "$DropboxDeployPath/" mv -v "$WinDeployPath/Updater.pdb" "$DropboxDeployPath/" - mv -v "$WinDeployPath/$WinUpdateFile" "$DropboxDeployPath/" if [ "$BetaVersion" == "0" ]; then mv -v "$WinDeployPath/$WinSetupFile" "$DropboxDeployPath/" fi diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index eccc5255c..63b8df37c 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -355,6 +355,8 @@ struct GlobalDataStruct { Adaptive::Layout AdaptiveLayout = Adaptive::NormalLayout; bool AdaptiveForWide = true; + int32 DebugLoggingFlags = 0; + // config int32 ChatSizeMax = 200; int32 MegagroupSizeMax = 1000; @@ -398,6 +400,8 @@ namespace Global { DefineVar(Global, Adaptive::Layout, AdaptiveLayout); DefineVar(Global, bool, AdaptiveForWide); + DefineVar(Global, int32, DebugLoggingFlags); + // config DefineVar(Global, int32, ChatSizeMax); DefineVar(Global, int32, MegagroupSizeMax); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index e572f45c1..26bcf391d 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -131,6 +131,12 @@ namespace Adaptive { }; }; +namespace DebugLogging { + enum Flags { + FileLoaderFlag = 0x00000001, + }; +} + namespace Global { bool started(); @@ -142,6 +148,8 @@ namespace Global { DeclareVar(Adaptive::Layout, AdaptiveLayout); DeclareVar(bool, AdaptiveForWide); + DeclareVar(int32, DebugLoggingFlags); + // config DeclareVar(int32, ChatSizeMax); DeclareVar(int32, MegagroupSizeMax); @@ -175,3 +183,9 @@ namespace Adaptive { return Global::AdaptiveForWide() && (Global::AdaptiveLayout() == WideLayout); } } + +namespace DebugLogging { + inline bool FileLoader() { + return (Global::DebugLoggingFlags() | FileLoaderFlag) != 0; + } +} diff --git a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp index f260f2ca4..311fbebf8 100644 --- a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp +++ b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp @@ -376,9 +376,33 @@ int32 mtpFileLoader::currentOffset(bool includeSkipped) const { return (_fileIsOpen ? _file.size() : _data.size()) - (includeSkipped ? 0 : _skippedBytes); } +namespace { + QString serializereqs(const QMap &reqs) { // serialize requests map in json-like format + QString result; + result.reserve(reqs.size() * 16 + 4); + result.append(qsl("{ ")); + for (auto i = reqs.cbegin(), e = reqs.cend(); i != e;) { + result.append(QString::number(i.key())).append(qsl(" : ")).append(QString::number(i.value())); + if (++i == e) { + break; + } else { + result.append(qsl(", ")); + } + } + result.append(qsl(" }")); + return result; + } +} + bool mtpFileLoader::loadPart() { - if (_complete || _lastComplete || (!_requests.isEmpty() && !_size)) return false; - if (_size && _nextRequestOffset >= _size) return false; + if (_complete || _lastComplete || (!_requests.isEmpty() && !_size)) { + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): loadPart() returned, _complete=%2, _lastComplete=%3, _requests.size()=%4, _size=%5").arg(_id).arg(Logs::b(_complete)).arg(Logs::b(_lastComplete)).arg(_requests.size()).arg(_size)); + return false; + } + if (_size && _nextRequestOffset >= _size) { + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): loadPart() returned, _size=%2, _nextRequestOffset=%3, _requests=%4").arg(_id).arg(_size).arg(_nextRequestOffset).arg(serializereqs(_requests))); + return false; + } int32 limit = DocumentDownloadPartSize; MTPInputFileLocation loc; @@ -412,12 +436,21 @@ bool mtpFileLoader::loadPart() { _requests.insert(reqId, dcIndex); _nextRequestOffset += limit; + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): requested part with offset=%2, _queue->queries=%3, _nextRequestOffset=%4, _requests=%5").arg(_id).arg(offset).arg(_queue->queries).arg(_nextRequestOffset).arg(serializereqs(_requests))); + return true; } void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRequestId req) { Requests::iterator i = _requests.find(req); - if (i == _requests.cend()) return loadNext(); + if (i == _requests.cend()) { + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): request req=%2 for offset=%3 not found in _requests=%4").arg(_id).arg(req).arg(offset).arg(serializereqs(_requests))); + return loadNext(); + } + if (result.type() != mtpc_upload_file) { + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): bad cons received! %2").arg(_id).arg(result.type())); + return cancel(true); + } int32 limit = (_locationType == UnknownFileLocation) ? DownloadPartSize : DocumentDownloadPartSize; int32 dcIndex = i.value(); @@ -428,6 +461,9 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe const MTPDupload_file &d(result.c_upload_file()); const string &bytes(d.vbytes.c_string().v); + + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): got part with offset=%2, bytes=%3, _queue->queries=%4, _nextRequestOffset=%5, _requests=%6").arg(_id).arg(offset).arg(bytes.size()).arg(_queue->queries).arg(_nextRequestOffset).arg(serializereqs(_requests))); + if (bytes.size()) { if (_fileIsOpen) { int64 fsize = _file.size(); @@ -502,6 +538,8 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe Local::writeImage(storageKey(*_location), StorageImageSaved(mtpToStorageType(_type), _data)); } } + } else { + if (DebugLogging::FileLoader() && _id) DEBUG_LOG(("FileLoader(%1): not done yet, _lastComplete=%2, _size=%3, _nextRequestOffset=%4, _requests=%5").arg(_id).arg(Logs::b(_lastComplete)).arg(_size).arg(_nextRequestOffset).arg(serializereqs(_requests))); } emit progress(this); loadNext(); diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index a6c0b8d88..a21faec32 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -811,11 +811,23 @@ void SettingsInner::keyPressEvent(QKeyEvent *e) { Ui::showLayer(box); from = size; break; - } else if (str == qstr("loadlang")) { - chooseCustomLang(); + } else if (str == qstr("loadlang")) { + chooseCustomLang(); + } else if (str == qstr("debugfiles") && cDebug()) { + if (DebugLogging::FileLoader()) { + Global::RefDebugLoggingFlags() &= ~DebugLogging::FileLoaderFlag; + } else { + Global::RefDebugLoggingFlags() |= DebugLogging::FileLoaderFlag; + } + Ui::showLayer(new InformBox(DebugLogging::FileLoader() ? "Enabled file download logging" : "Disabled file download logging")); } else if (str == qstr("crashplease")) { t_assert(!"Crashed in Settings!"); - } else if (qsl("debugmode").startsWith(str) || qsl("testmode").startsWith(str) || qsl("loadlang").startsWith(str) || qsl("crashplease").startsWith(str)) { + } else if ( + qsl("debugmode").startsWith(str) || + qsl("testmode").startsWith(str) || + qsl("loadlang").startsWith(str) || + qsl("debugfiles").startsWith(str) || + qsl("crashplease").startsWith(str)) { break; } ++from;