blob: 5187a6f453ae6ab086793756d58e42436d83558a [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"
caryclark17f0b6d2014-07-22 10:15:34 -07004#include "SkCommonFlags.h"
commit-bot@chromium.org261c6662014-01-02 16:19:53 +00005#include "OverwriteLine.h"
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +00006
mtklein4e212e82014-08-04 14:10:19 -07007#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.comd36522d2013-10-16 13:02:15 +000018namespace DM {
19
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000020void Reporter::printStatus(SkString name, SkMSec timeMs) const {
commit-bot@chromium.org0caa68a2013-10-29 15:02:17 +000021 if (FLAGS_quiet) {
22 return;
23 }
24
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000025 // 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.coma7a9f372013-10-18 20:52:44 +000029 SkString status;
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000030 status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pending);
mtklein@google.coma7a9f372013-10-18 20:52:44 +000031 if (failed > 0) {
32 status.appendf(", %d failed", failed);
33 }
commit-bot@chromium.orga39874b2014-03-03 15:44:56 +000034 if (FLAGS_verbose) {
mtklein4e212e82014-08-04 14:10:19 -070035 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.orga39874b2014-03-03 15:44:56 +000039 }
commit-bot@chromium.orgd1a7e2e2014-02-28 20:28:59 +000040 SkDebugf("%s", status.c_str());
mtklein@google.comd36522d2013-10-16 13:02:15 +000041}
42
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000043void Reporter::fail(SkString msg) {
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +000044 sk_atomic_inc(&fFailed);
45
mtklein@google.comd36522d2013-10-16 13:02:15 +000046 SkAutoMutexAcquire writer(&fMutex);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000047 fFailures.push_back(msg);
mtklein@google.comd36522d2013-10-16 13:02:15 +000048}
49
50void Reporter::getFailures(SkTArray<SkString>* failures) const {
51 SkAutoMutexAcquire reader(&fMutex);
52 *failures = fFailures;
53}
54
55} // namespace DM