Skip to content

Commit 3731d60

Browse files
make columns aligns in channel utilization files
1 parent 9ee1ba7 commit 3731d60

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

vpr/src/base/stats.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <set>
55
#include <fstream>
66
#include <string>
7+
#include <iomanip>
78

89
#include "physical_types_util.h"
910
#include "route_tree.h"
@@ -249,18 +250,35 @@ static void write_channel_occupancy_to_file(const vtr::Matrix<int>& chanx_occ,
249250
const vtr::Matrix<int>& chany_occ) {
250251
const auto& device_ctx = g_vpr_ctx.device();
251252

253+
constexpr int w_coord = 6;
254+
constexpr int w_value = 12;
255+
constexpr int w_percent = 10;
256+
252257
// Write X-directed channels
253258
std::ofstream chanx_file("chanx_occupancy.txt");
254259
if (chanx_file.is_open()) {
255-
chanx_file << "x,y,occupancy,percentage,capacity\n";
260+
chanx_file << std::setw(w_coord) << "x"
261+
<< std::setw(w_coord) << "y"
262+
<< std::setw(w_value) << "occupancy"
263+
<< std::setw(w_percent) << "%"
264+
<< std::setw(w_value) << "capacity"
265+
<< "\n";
266+
256267
for (size_t j = 0; j < chanx_occ.dim_size(1); ++j) {
257268
int capacity = device_ctx.chan_width.x_list[j];
258269
for (size_t i = 0; i < chanx_occ.dim_size(0); ++i) {
259270
int occ = chanx_occ[i][j];
260-
float percent = capacity > 0 ? static_cast<float>(occ) / capacity : 0.0f;
261-
chanx_file << i << "," << j << "," << occ << "," << percent << "," << capacity << "\n";
271+
float percent = capacity > 0 ? static_cast<float>(occ) / capacity * 100.0f : 0.0f;
272+
273+
chanx_file << std::setw(w_coord) << i
274+
<< std::setw(w_coord) << j
275+
<< std::setw(w_value) << occ
276+
<< std::setw(w_percent) << std::fixed << std::setprecision(3) << percent
277+
<< std::setw(w_value) << capacity
278+
<< "\n";
262279
}
263280
}
281+
264282
chanx_file.close();
265283
} else {
266284
VTR_LOG_WARN("Failed to open chanx_occupancy.txt for writing.\n");
@@ -269,15 +287,28 @@ static void write_channel_occupancy_to_file(const vtr::Matrix<int>& chanx_occ,
269287
// Write Y-directed channels
270288
std::ofstream chany_file("chany_occupancy.txt");
271289
if (chany_file.is_open()) {
272-
chany_file << "x,y,occupancy,percentage,capacity\n";
290+
chany_file << std::setw(w_coord) << "x"
291+
<< std::setw(w_coord) << "y"
292+
<< std::setw(w_value) << "occupancy"
293+
<< std::setw(w_percent) << "%"
294+
<< std::setw(w_value) << "capacity"
295+
<< "\n";
296+
273297
for (size_t i = 0; i < chany_occ.dim_size(0); ++i) {
274298
int capacity = device_ctx.chan_width.y_list[i];
275299
for (size_t j = 0; j < chany_occ.dim_size(1); ++j) {
276300
int occ = chany_occ[i][j];
277-
float percent = capacity > 0 ? static_cast<float>(occ) / capacity : 0.0f;
278-
chany_file << i << "," << j << "," << occ << "," << percent << "," << capacity << "\n";
301+
float percent = capacity > 0 ? static_cast<float>(occ) / capacity * 100.0f : 0.0f;
302+
303+
chany_file << std::setw(w_coord) << i
304+
<< std::setw(w_coord) << j
305+
<< std::setw(w_value) << occ
306+
<< std::setw(w_percent) << std::fixed << std::setprecision(3) << percent
307+
<< std::setw(w_value) << capacity
308+
<< "\n";
279309
}
280310
}
311+
281312
chany_file.close();
282313
} else {
283314
VTR_LOG_WARN("Failed to open chany_occupancy.txt for writing.\n");

0 commit comments

Comments
 (0)