mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMReporter.h" |
| 2 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 3 | #include "SkDynamicAnnotations.h" |
commit-bot@chromium.org | 0caa68a | 2013-10-29 15:02:17 +0000 | [diff] [blame] | 4 | #include "SkCommandLineFlags.h" |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 5 | #include "OverwriteLine.h" |
commit-bot@chromium.org | 0caa68a | 2013-10-29 15:02:17 +0000 | [diff] [blame] | 6 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 7 | DEFINE_bool2(quiet, q, false, "If true, don't print status updates."); |
| 8 | DEFINE_bool2(verbose, v, false, "If true, print status updates one-per-line."); |
commit-bot@chromium.org | 0caa68a | 2013-10-29 15:02:17 +0000 | [diff] [blame] | 9 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 10 | namespace DM { |
| 11 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 12 | void Reporter::printStatus(SkString name, SkMSec timeMs) const { |
commit-bot@chromium.org | 0caa68a | 2013-10-29 15:02:17 +0000 | [diff] [blame] | 13 | if (FLAGS_quiet) { |
| 14 | return; |
| 15 | } |
| 16 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 17 | // 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.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 21 | SkString status; |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 22 | status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pending); |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 23 | if (failed > 0) { |
| 24 | status.appendf(", %d failed", failed); |
| 25 | } |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 26 | if (FLAGS_verbose) { |
| 27 | status.appendf("\t%5dms %s", timeMs, name.c_str()); |
| 28 | } |
commit-bot@chromium.org | d1a7e2e | 2014-02-28 20:28:59 +0000 | [diff] [blame] | 29 | SkDebugf("%s", status.c_str()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 30 | } |
| 31 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 32 | void Reporter::fail(SkString msg) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 33 | sk_atomic_inc(&fFailed); |
| 34 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 35 | SkAutoMutexAcquire writer(&fMutex); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 36 | fFailures.push_back(msg); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void Reporter::getFailures(SkTArray<SkString>* failures) const { |
| 40 | SkAutoMutexAcquire reader(&fMutex); |
| 41 | *failures = fFailures; |
| 42 | } |
| 43 | |
| 44 | } // namespace DM |