1#include "DMReporter.h"
2
3#include "SkDynamicAnnotations.h"
4#include "SkCommonFlags.h"
5#include "OverwriteLine.h"
6#include "ProcStats.h"
7
8namespace DM {
9
10void Reporter::printStatus(SkString name, SkMSec timeMs) const {
11    if (FLAGS_quiet) {
12        return;
13    }
14
15    // It's okay if these are a little off---they're just for show---so we can read unprotectedly.
16    const int32_t failed  = SK_ANNOTATE_UNPROTECTED_READ(fFailed);
17    const int32_t pending = SK_ANNOTATE_UNPROTECTED_READ(fPending) - 1;
18
19    SkString status;
20    status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pending);
21    if (failed > 0) {
22        status.appendf(", %d failed", failed);
23    }
24    if (FLAGS_verbose) {
25        int max_rss_mb = sk_tools::getMaxResidentSetSizeMB();
26        if (max_rss_mb >= 0) {
27            status.appendf("\t%4dM peak", max_rss_mb);
28        }
29        status.appendf("\t%5dms\t%s", timeMs, name.c_str());
30    }
31    SkDebugf("%s", status.c_str());
32}
33
34void Reporter::fail(SkString msg) {
35    sk_atomic_inc(&fFailed);
36
37    SkAutoMutexAcquire writer(&fMutex);
38    fFailures.push_back(msg);
39}
40
41void Reporter::getFailures(SkTArray<SkString>* failures) const {
42    SkAutoMutexAcquire reader(&fMutex);
43    *failures = fFailures;
44}
45
46}  // namespace DM
47