Mercurial > hg > svcore
comparison data/fileio/FileSource.cpp @ 1033:3a48b22fed48
Debug reporting from FileSource
author | Chris Cannam |
---|---|
date | Thu, 26 Feb 2015 09:43:12 +0000 |
parents | 60e2927b1475 |
children | 24c48323c662 |
comparison
equal
deleted
inserted
replaced
1030:920699b6989d | 1033:3a48b22fed48 |
---|---|
30 #include <iostream> | 30 #include <iostream> |
31 #include <cstdlib> | 31 #include <cstdlib> |
32 | 32 |
33 #include <unistd.h> | 33 #include <unistd.h> |
34 | 34 |
35 //#define DEBUG_FILE_SOURCE 1 | 35 #define DEBUG_FILE_SOURCE 1 |
36 | 36 |
37 int | 37 int |
38 FileSource::m_count = 0; | 38 FileSource::m_count = 0; |
39 | 39 |
40 QMutex | 40 QMutex |
49 QMutex | 49 QMutex |
50 FileSource::m_mapMutex; | 50 FileSource::m_mapMutex; |
51 | 51 |
52 #ifdef DEBUG_FILE_SOURCE | 52 #ifdef DEBUG_FILE_SOURCE |
53 static int extantCount = 0; | 53 static int extantCount = 0; |
54 static int threadCount = 0; | |
54 static std::map<QString, int> urlExtantCountMap; | 55 static std::map<QString, int> urlExtantCountMap; |
56 static QMutex countMutex; | |
55 static void incCount(QString url) { | 57 static void incCount(QString url) { |
58 QMutexLocker locker(&countMutex); | |
56 ++extantCount; | 59 ++extantCount; |
57 if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) { | 60 if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) { |
58 urlExtantCountMap[url] = 1; | 61 urlExtantCountMap[url] = 1; |
59 } else { | 62 } else { |
60 ++urlExtantCountMap[url]; | 63 ++urlExtantCountMap[url]; |
61 } | 64 } |
62 cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; | 65 cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; |
63 } | 66 } |
64 static void decCount(QString url) { | 67 static void decCount(QString url) { |
68 QMutexLocker locker(&countMutex); | |
65 --extantCount; | 69 --extantCount; |
66 --urlExtantCountMap[url]; | 70 --urlExtantCountMap[url]; |
67 cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; | 71 cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; |
68 } | 72 } |
73 void | |
74 FileSource::debugReport() | |
75 { | |
76 QMutexLocker locker(&countMutex); | |
77 cerr << "\nFileSource::debugReport: Have " << extantCount << " FileSource object(s) extant across " << threadCount << " thread(s)" << endl; | |
78 cerr << "URLs by extant count:" << endl; | |
79 cerr << "Count | URL" << endl; | |
80 for (std::map<QString, int>::const_iterator i = urlExtantCountMap.begin(); | |
81 i != urlExtantCountMap.end(); ++i) { | |
82 cerr << i->second << " | " << i->first << endl; | |
83 } | |
84 cerr << "FileSource::debugReport done\n" << endl; | |
85 } | |
86 #else | |
87 void FileSource::debugReport() { } | |
69 #endif | 88 #endif |
70 | 89 |
71 static QThreadStorage<QNetworkAccessManager *> nms; | 90 static QThreadStorage<QNetworkAccessManager *> nms; |
72 | 91 |
73 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, | 92 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter, |
266 } | 285 } |
267 | 286 |
268 void | 287 void |
269 FileSource::init() | 288 FileSource::init() |
270 { | 289 { |
271 { // check we have a QNetworkAccessManager | |
272 QMutexLocker locker(&m_mapMutex); | |
273 if (!nms.hasLocalData()) { | |
274 nms.setLocalData(new QNetworkAccessManager()); | |
275 } | |
276 } | |
277 | |
278 if (isResource()) { | 290 if (isResource()) { |
279 #ifdef DEBUG_FILE_SOURCE | 291 #ifdef DEBUG_FILE_SOURCE |
280 cerr << "FileSource::init: Is a resource" << endl; | 292 cerr << "FileSource::init: Is a resource" << endl; |
281 #endif | 293 #endif |
282 QString resourceFile = m_url.toString(); | 294 QString resourceFile = m_url.toString(); |
459 << m_preferredContentType << "\"" << endl; | 471 << m_preferredContentType << "\"" << endl; |
460 #endif | 472 #endif |
461 req.setRawHeader | 473 req.setRawHeader |
462 ("Accept", | 474 ("Accept", |
463 QString("%1, */*").arg(m_preferredContentType).toLatin1()); | 475 QString("%1, */*").arg(m_preferredContentType).toLatin1()); |
476 } | |
477 | |
478 { // check we have a QNetworkAccessManager | |
479 QMutexLocker locker(&m_mapMutex); | |
480 if (!nms.hasLocalData()) { | |
481 #ifdef DEBUG_FILE_SOURCE | |
482 ++threadCount; | |
483 #endif | |
484 nms.setLocalData(new QNetworkAccessManager()); | |
485 } | |
464 } | 486 } |
465 | 487 |
466 m_reply = nms.localData()->get(req); | 488 m_reply = nms.localData()->get(req); |
467 | 489 |
468 connect(m_reply, SIGNAL(readyRead()), | 490 connect(m_reply, SIGNAL(readyRead()), |