OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include "SkRecord.h" | 10 #include "SkRecord.h" |
11 #include "SkRecordDraw.h" | 11 #include "SkRecordDraw.h" |
12 | 12 |
13 #include "DumpRecord.h" | 13 #include "DumpRecord.h" |
14 #include "Timer.h" | 14 #include "SkTime.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class Dumper { | 18 class Dumper { |
19 public: | 19 public: |
20 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) | 20 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) |
21 : fDigits(0) | 21 : fDigits(0) |
22 , fIndent(0) | 22 , fIndent(0) |
23 , fIndex(0) | 23 , fIndex(0) |
24 , fDraw(canvas, nullptr, nullptr, 0, nullptr) | 24 , fDraw(canvas, nullptr, nullptr, 0, nullptr) |
25 , fTimeWithCommand(timeWithCommand) { | 25 , fTimeWithCommand(timeWithCommand) { |
26 while (count > 0) { | 26 while (count > 0) { |
27 count /= 10; | 27 count /= 10; |
28 fDigits++; | 28 fDigits++; |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 template <typename T> | 32 template <typename T> |
33 void operator()(const T& command) { | 33 void operator()(const T& command) { |
34 Timer timer; | 34 auto start = SkTime::GetNSecs(); |
35 timer.start(); | 35 fDraw(command); |
36 fDraw(command); | 36 this->print(command, SkTime::GetNSecs() - start); |
37 timer.end(); | |
38 | |
39 this->print(command, timer.fCpu); | |
40 } | 37 } |
41 | 38 |
42 void operator()(const SkRecords::NoOp&) { | 39 void operator()(const SkRecords::NoOp&) { |
43 // Move on without printing anything. | 40 // Move on without printing anything. |
44 } | 41 } |
45 | 42 |
46 template <typename T> | 43 template <typename T> |
47 void print(const T& command, double time) { | 44 void print(const T& command, double ns) { |
48 this->printNameAndTime(command, time); | 45 this->printNameAndTime(command, ns); |
49 } | 46 } |
50 | 47 |
51 void print(const SkRecords::Restore& command, double time) { | 48 void print(const SkRecords::Restore& command, double ns) { |
52 --fIndent; | 49 --fIndent; |
53 this->printNameAndTime(command, time); | 50 this->printNameAndTime(command, ns); |
54 } | 51 } |
55 | 52 |
56 void print(const SkRecords::Save& command, double time) { | 53 void print(const SkRecords::Save& command, double ns) { |
57 this->printNameAndTime(command, time); | 54 this->printNameAndTime(command, ns); |
58 ++fIndent; | 55 ++fIndent; |
59 } | 56 } |
60 | 57 |
61 void print(const SkRecords::SaveLayer& command, double time) { | 58 void print(const SkRecords::SaveLayer& command, double ns) { |
62 this->printNameAndTime(command, time); | 59 this->printNameAndTime(command, ns); |
63 ++fIndent; | 60 ++fIndent; |
64 } | 61 } |
65 | 62 |
66 private: | 63 private: |
67 template <typename T> | 64 template <typename T> |
68 void printNameAndTime(const T& command, double time) { | 65 void printNameAndTime(const T& command, double ns) { |
| 66 int us = (int)(ns * 1e-3); |
69 if (!fTimeWithCommand) { | 67 if (!fTimeWithCommand) { |
70 printf("%6.1f ", time * 1000); | 68 printf("%6dus ", us); |
71 } | 69 } |
72 printf("%*d ", fDigits, fIndex++); | 70 printf("%*d ", fDigits, fIndex++); |
73 for (int i = 0; i < fIndent; i++) { | 71 for (int i = 0; i < fIndent; i++) { |
74 putchar('\t'); | 72 printf(" "); |
75 } | 73 } |
76 if (fTimeWithCommand) { | 74 if (fTimeWithCommand) { |
77 printf("%6.1f ", time * 1000); | 75 printf("%6dus ", us); |
78 } | 76 } |
79 puts(NameOf(command)); | 77 puts(NameOf(command)); |
80 } | 78 } |
81 | 79 |
82 template <typename T> | 80 template <typename T> |
83 static const char* NameOf(const T&) { | 81 static const char* NameOf(const T&) { |
84 #define CASE(U) case SkRecords::U##_Type: return #U; | 82 #define CASE(U) case SkRecords::U##_Type: return #U; |
85 switch(T::kType) { SK_RECORD_TYPES(CASE); } | 83 switch(T::kType) { SK_RECORD_TYPES(CASE); } |
86 #undef CASE | 84 #undef CASE |
87 SkDEBUGFAIL("Unknown T"); | 85 SkDEBUGFAIL("Unknown T"); |
(...skipping 14 matching lines...) Expand all Loading... |
102 } // namespace | 100 } // namespace |
103 | 101 |
104 void DumpRecord(const SkRecord& record, | 102 void DumpRecord(const SkRecord& record, |
105 SkCanvas* canvas, | 103 SkCanvas* canvas, |
106 bool timeWithCommand) { | 104 bool timeWithCommand) { |
107 Dumper dumper(canvas, record.count(), timeWithCommand); | 105 Dumper dumper(canvas, record.count(), timeWithCommand); |
108 for (int i = 0; i < record.count(); i++) { | 106 for (int i = 0; i < record.count(); i++) { |
109 record.visit<void>(i, dumper); | 107 record.visit<void>(i, dumper); |
110 } | 108 } |
111 } | 109 } |
OLD | NEW |