OLD | NEW |
1 #include "DMReporter.h" | 1 #include "DMReporter.h" |
2 | 2 |
3 #include "SkDynamicAnnotations.h" | 3 #include "SkDynamicAnnotations.h" |
4 #include "SkCommonFlags.h" | 4 #include "SkCommonFlags.h" |
5 #include "OverwriteLine.h" | 5 #include "OverwriteLine.h" |
6 | 6 #include "ProcStats.h" |
7 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_
FOR_ANDROID) | |
8 #include <sys/resource.h> | |
9 static long get_max_rss_kb() { | |
10 struct rusage ru; | |
11 getrusage(RUSAGE_SELF, &ru); | |
12 #if defined(SK_BUILD_FOR_MAC) | |
13 return ru.ru_maxrss / 1024; // Darwin reports bytes. | |
14 #else | |
15 return ru.ru_maxrss; // Linux reports kilobytes. | |
16 #endif | |
17 } | |
18 #else | |
19 static long get_max_rss_kb() { return 0; } | |
20 #endif | |
21 | 7 |
22 namespace DM { | 8 namespace DM { |
23 | 9 |
24 void Reporter::printStatus(SkString name, SkMSec timeMs) const { | 10 void Reporter::printStatus(SkString name, SkMSec timeMs) const { |
25 if (FLAGS_quiet) { | 11 if (FLAGS_quiet) { |
26 return; | 12 return; |
27 } | 13 } |
28 | 14 |
29 // It's okay if these are a little off---they're just for show---so we can r
ead unprotectedly. | 15 // It's okay if these are a little off---they're just for show---so we can r
ead unprotectedly. |
30 const int32_t failed = SK_ANNOTATE_UNPROTECTED_READ(fFailed); | 16 const int32_t failed = SK_ANNOTATE_UNPROTECTED_READ(fFailed); |
31 const int32_t pending = SK_ANNOTATE_UNPROTECTED_READ(fPending) - 1; | 17 const int32_t pending = SK_ANNOTATE_UNPROTECTED_READ(fPending) - 1; |
32 | 18 |
33 SkString status; | 19 SkString status; |
34 status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pe
nding); | 20 status.printf("%s%d tasks left", FLAGS_verbose ? "\n" : kSkOverwriteLine, pe
nding); |
35 if (failed > 0) { | 21 if (failed > 0) { |
36 status.appendf(", %d failed", failed); | 22 status.appendf(", %d failed", failed); |
37 } | 23 } |
38 if (FLAGS_verbose) { | 24 if (FLAGS_verbose) { |
39 if (long max_rss_kb = get_max_rss_kb()) { | 25 int max_rss_kb = sk_tools::getMaxResidentSetSizeKB(); |
40 status.appendf("\t%4ldM peak", max_rss_kb / 1024); | 26 if (max_rss_kb >= 0) { |
| 27 status.appendf("\t%4dM peak", max_rss_kb / 1024); |
41 } | 28 } |
42 status.appendf("\t%5dms\t%s", timeMs, name.c_str()); | 29 status.appendf("\t%5dms\t%s", timeMs, name.c_str()); |
43 } | 30 } |
44 SkDebugf("%s", status.c_str()); | 31 SkDebugf("%s", status.c_str()); |
45 } | 32 } |
46 | 33 |
47 void Reporter::fail(SkString msg) { | 34 void Reporter::fail(SkString msg) { |
48 sk_atomic_inc(&fFailed); | 35 sk_atomic_inc(&fFailed); |
49 | 36 |
50 SkAutoMutexAcquire writer(&fMutex); | 37 SkAutoMutexAcquire writer(&fMutex); |
51 fFailures.push_back(msg); | 38 fFailures.push_back(msg); |
52 } | 39 } |
53 | 40 |
54 void Reporter::getFailures(SkTArray<SkString>* failures) const { | 41 void Reporter::getFailures(SkTArray<SkString>* failures) const { |
55 SkAutoMutexAcquire reader(&fMutex); | 42 SkAutoMutexAcquire reader(&fMutex); |
56 *failures = fFailures; | 43 *failures = fFailures; |
57 } | 44 } |
58 | 45 |
59 } // namespace DM | 46 } // namespace DM |
OLD | NEW |