blob: 0bc77bd573adad4e3f221d76179613fb5e7d8272 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMReporter.h"
2
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00003#include "SkDynamicAnnotations.h"
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00004#include "SkCommandLineFlags.h"
commit-bot@chromium.org261c6662014-01-02 16:19:53 +00005#include "OverwriteLine.h"
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00006
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00007DEFINE_bool2(quiet, q, false, "If true, don't print status updates.");
8DEFINE_bool2(verbose, v, false, "If true, print status updates one-per-line.");
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00009
mtklein@google.comd36522d2013-10-16 13:02:15 +000010namespace DM {
11
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000012void Reporter::printStatus(SkString name, SkMSec timeMs) const {
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +000013 if (FLAGS_quiet) {
14 return;
15 }
16
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000017 // It's okay if these are a little off---they're just for show---so we can read unprotectedly.
18 const int32_t failed = SK_ANNOTATE_UNPROTECTED_READ(fFailed);
19 const int32_t pending = SK_ANNOTATE_UNPROTECTED_READ(fPending) - 1;
20
mtklein@google.coma7a9f372013-10-18 20:52:44 +000021 SkString status;
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000022 status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pending);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000023 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
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000032void Reporter::fail(SkString msg) {
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000033 sk_atomic_inc(&fFailed);
34
mtklein@google.comd36522d2013-10-16 13:02:15 +000035 SkAutoMutexAcquire writer(&fMutex);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000036 fFailures.push_back(msg);
mtklein@google.comd36522d2013-10-16 13:02:15 +000037}
38
39void Reporter::getFailures(SkTArray<SkString>* failures) const {
40 SkAutoMutexAcquire reader(&fMutex);
41 *failures = fFailures;
42}
43
44} // namespace DM