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