blob: 4bb25d349dffe193b853c1b3481ef9177db824ac [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMReporter.h"
2
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00003#include "SkCommandLineFlags.h"
commit-bot@chromium.org261c6662014-01-02 16:19:53 +00004#include "OverwriteLine.h"
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00005
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00006DEFINE_bool2(quiet, q, false, "If true, don't print status updates.");
7DEFINE_bool2(verbose, v, false, "If true, print status updates one-per-line.");
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00008
mtklein@google.comd36522d2013-10-16 13:02:15 +00009namespace DM {
10
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000011void Reporter::finish(SkString name, SkMSec timeMs) {
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000012 sk_atomic_inc(&fFinished);
13
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +000014 if (FLAGS_quiet) {
15 return;
16 }
17
mtklein@google.coma7a9f372013-10-18 20:52:44 +000018 SkString status;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000019 status.printf("%s%d tasks left",
20 FLAGS_verbose ? "\n" : kSkOverwriteLine,
21 this->started() - this->finished());
mtklein@google.coma7a9f372013-10-18 20:52:44 +000022 const int failed = this->failed();
23 if (failed > 0) {
24 status.appendf(", %d failed", failed);
25 }
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000026 if (FLAGS_verbose) {
27 status.appendf("\t%5dms %s", timeMs, name.c_str());
28 }
commit-bot@chromium.orgd1a7e2e2014-02-28 20:28:59 +000029 SkDebugf("%s", status.c_str());
mtklein@google.comd36522d2013-10-16 13:02:15 +000030}
31
32int32_t Reporter::failed() const {
33 SkAutoMutexAcquire reader(&fMutex);
34 return fFailures.count();
35}
36
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000037void Reporter::fail(SkString msg) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000038 SkAutoMutexAcquire writer(&fMutex);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000039 fFailures.push_back(msg);
mtklein@google.comd36522d2013-10-16 13:02:15 +000040}
41
42void Reporter::getFailures(SkTArray<SkString>* failures) const {
43 SkAutoMutexAcquire reader(&fMutex);
44 *failures = fFailures;
45}
46
47} // namespace DM