@@ -16,6 +16,7 @@ limitations under the License.
16
16
17
17
#include < cinttypes>
18
18
#include < cstdint>
19
+ #include < cstring>
19
20
20
21
#include " tensorflow/lite/kernels/internal/compatibility.h"
21
22
#include " tensorflow/lite/micro/micro_error_reporter.h"
@@ -67,4 +68,48 @@ void MicroProfiler::LogCsv() const {
67
68
#endif
68
69
}
69
70
71
+ void MicroProfiler::LogTicksPerTagCsv () {
72
+ #if !defined(TF_LITE_STRIP_ERROR_STRINGS)
73
+ MicroPrintf (
74
+ " \" Unique Tag\" ,\" Total ticks across all events with that tag.\" " );
75
+ int total_ticks = 0 ;
76
+ for (int i = 0 ; i < num_events_; ++i) {
77
+ uint32_t ticks = end_ticks_[i] - start_ticks_[i];
78
+ TFLITE_DCHECK (tags_[i] != nullptr );
79
+ int position = FindExistingOrNextPosition (tags_[i]);
80
+ TFLITE_DCHECK (position >= 0 );
81
+ total_ticks_per_tag[position].tag = tags_[i];
82
+ total_ticks_per_tag[position].ticks =
83
+ total_ticks_per_tag[position].ticks + ticks;
84
+ total_ticks += ticks;
85
+ }
86
+
87
+ for (int i = 0 ; i < num_events_; ++i) {
88
+ TicksPerTag each_tag_entry = total_ticks_per_tag[i];
89
+ if (each_tag_entry.tag == nullptr ) {
90
+ break ;
91
+ }
92
+ MicroPrintf (" %s, %d" , each_tag_entry.tag , each_tag_entry.ticks );
93
+ }
94
+ MicroPrintf (" total number of ticks, %d" , total_ticks);
95
+ #endif
96
+ }
97
+
98
+ // This method finds a particular array element in the total_ticks_per_tag array
99
+ // with the matching tag_name passed in the method. If it can find a
100
+ // matching array element that has the same tag_name, then it will return the
101
+ // position of the matching element. But if it unable to find a matching element
102
+ // with the given tag_name, it will return the next available empty position
103
+ // from the array.
104
+ int MicroProfiler::FindExistingOrNextPosition (const char * tag_name) {
105
+ int pos = 0 ;
106
+ for (; pos < num_events_; pos++) {
107
+ TicksPerTag each_tag_entry = total_ticks_per_tag[pos];
108
+ if (each_tag_entry.tag == nullptr ||
109
+ strcmp (each_tag_entry.tag , tag_name) == 0 ) {
110
+ return pos;
111
+ }
112
+ }
113
+ return pos < num_events_ ? pos : -1 ;
114
+ }
70
115
} // namespace tflite
0 commit comments