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" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 4 | #include "SkCommonFlags.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 | |
mtklein | 4e212e8 | 2014-08-04 14:10:19 -0700 | [diff] [blame^] | 7 | #ifdef SK_BUILD_FOR_UNIX |
| 8 | #include <sys/resource.h> |
| 9 | static long get_max_rss_kb() { |
| 10 | struct rusage ru; |
| 11 | getrusage(RUSAGE_SELF, &ru); |
| 12 | return ru.ru_maxrss; |
| 13 | } |
| 14 | #else |
| 15 | static long get_max_rss_kb() { return 0; } |
| 16 | #endif |
| 17 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 18 | namespace DM { |
| 19 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 20 | void Reporter::printStatus(SkString name, SkMSec timeMs) const { |
commit-bot@chromium.org | 0caa68a | 2013-10-29 15:02:17 +0000 | [diff] [blame] | 21 | if (FLAGS_quiet) { |
| 22 | return; |
| 23 | } |
| 24 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 25 | // It's okay if these are a little off---they're just for show---so we can read unprotectedly. |
| 26 | const int32_t failed = SK_ANNOTATE_UNPROTECTED_READ(fFailed); |
| 27 | const int32_t pending = SK_ANNOTATE_UNPROTECTED_READ(fPending) - 1; |
| 28 | |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 29 | SkString status; |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 30 | status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pending); |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 31 | if (failed > 0) { |
| 32 | status.appendf(", %d failed", failed); |
| 33 | } |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 34 | if (FLAGS_verbose) { |
mtklein | 4e212e8 | 2014-08-04 14:10:19 -0700 | [diff] [blame^] | 35 | if (long max_rss_kb = get_max_rss_kb()) { |
| 36 | status.appendf("\t%4ldM peak", max_rss_kb / 1024); |
| 37 | } |
| 38 | status.appendf("\t%5dms\t%s", timeMs, name.c_str()); |
commit-bot@chromium.org | a39874b | 2014-03-03 15:44:56 +0000 | [diff] [blame] | 39 | } |
commit-bot@chromium.org | d1a7e2e | 2014-02-28 20:28:59 +0000 | [diff] [blame] | 40 | SkDebugf("%s", status.c_str()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 41 | } |
| 42 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 43 | void Reporter::fail(SkString msg) { |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 44 | sk_atomic_inc(&fFailed); |
| 45 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 46 | SkAutoMutexAcquire writer(&fMutex); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 47 | fFailures.push_back(msg); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void Reporter::getFailures(SkTArray<SkString>* failures) const { |
| 51 | SkAutoMutexAcquire reader(&fMutex); |
| 52 | *failures = fFailures; |
| 53 | } |
| 54 | |
| 55 | } // namespace DM |