Dump a trace. Assumes that AggregateThreadSpecificEntries and Sort have already been called on it. On some architectures long long ints are not same as std::int64_t, and time is printed as %lld, so static_casts are necessary.
| 96 | // On some architectures long long ints are not same as std::int64_t, and |
| 97 | // time is printed as %lld, so static_casts are necessary. |
| 98 | void Dump(const Trace& trace) { |
| 99 | const char* trace_filename = getenv("RUY_TRACE_FILE"); |
| 100 | FILE* trace_file = trace_filename ? fopen(trace_filename, "w") : stderr; |
| 101 | if (!trace_file) { |
| 102 | fprintf(stderr, "Failed to open %s for write, errno=%d\n", trace_filename, |
| 103 | errno); |
| 104 | RUY_CHECK(false); |
| 105 | } |
| 106 | fprintf(trace_file, "thread_count:%d\n", trace.thread_count); |
| 107 | fprintf(trace_file, "rows:%d\n", trace.block_map.dims[Side::kLhs]); |
| 108 | fprintf(trace_file, "cols:%d\n", trace.block_map.dims[Side::kRhs]); |
| 109 | fprintf(trace_file, "Execute: %lld\n", |
| 110 | static_cast<long long int>( |
| 111 | ToInt64Nanoseconds(trace.time_execute - trace.time_start))); |
| 112 | for (const TraceEntry& entry : trace.entries) { |
| 113 | long long int time = static_cast<long long int>( |
| 114 | ToInt64Nanoseconds(entry.time_point - trace.time_start)); |
| 115 | switch (entry.event) { |
| 116 | case TraceEvent::kThreadStart: |
| 117 | fprintf(trace_file, "ThreadStart: %lld, %d\n", time, entry.thread_id); |
| 118 | break; |
| 119 | case TraceEvent::kThreadLoopStart: |
| 120 | fprintf(trace_file, "ThreadLoopStart: %lld, %d\n", time, |
| 121 | entry.thread_id); |
| 122 | break; |
| 123 | case TraceEvent::kThreadEnd: |
| 124 | fprintf(trace_file, "ThreadEnd: %lld, %d\n", time, entry.thread_id); |
| 125 | break; |
| 126 | case TraceEvent::kBlockReserved: { |
| 127 | std::uint32_t block_id = entry.params[0]; |
| 128 | SidePair<int> block; |
| 129 | GetBlockByIndex(trace.block_map, block_id, &block); |
| 130 | SidePair<int> start, end; |
| 131 | GetBlockMatrixCoords(trace.block_map, block, &start, &end); |
| 132 | fprintf(trace_file, |
| 133 | "BlockReserved: %lld, %d, %d, %d, %d, %d, %d, %d, %d\n", time, |
| 134 | entry.thread_id, block_id, block[Side::kLhs], block[Side::kRhs], |
| 135 | start[Side::kLhs], start[Side::kRhs], end[Side::kLhs], |
| 136 | end[Side::kRhs]); |
| 137 | break; |
| 138 | } |
| 139 | case TraceEvent::kBlockPackedLhs: { |
| 140 | std::uint32_t block = entry.params[0]; |
| 141 | int start, end; |
| 142 | GetBlockMatrixCoords(Side::kLhs, trace.block_map, block, &start, &end); |
| 143 | fprintf(trace_file, "BlockPackedLhs: %lld, %d, %d, %d, %d\n", time, |
| 144 | entry.thread_id, block, start, end); |
| 145 | break; |
| 146 | } |
| 147 | case TraceEvent::kBlockPackedRhs: { |
| 148 | std::uint32_t block = entry.params[0]; |
| 149 | int start, end; |
| 150 | GetBlockMatrixCoords(Side::kRhs, trace.block_map, block, &start, &end); |
| 151 | fprintf(trace_file, "BlockPackedRhs: %lld, %d, %d, %d, %d\n", time, |
| 152 | entry.thread_id, block, start, end); |
| 153 | break; |
| 154 | } |
| 155 | case TraceEvent::kBlockFinished: { |
no test coverage detected