Skip to content

Commit 6ffd1b8

Browse files
committed
Log time of each iteration.
1 parent ee43564 commit 6ffd1b8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/sot_loader.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,40 @@ using namespace std;
3434
using namespace dynamicgraph::sot;
3535
namespace po = boost::program_options;
3636

37+
struct DataToLog
38+
{
39+
const std::size_t N;
40+
std::size_t idx;
41+
42+
std::vector<double> times;
43+
44+
DataToLog (std::size_t N_)
45+
: N (N_)
46+
, idx (0)
47+
, times (N, 0)
48+
{}
49+
50+
void record (const double t)
51+
{
52+
times[idx] = t;
53+
++idx;
54+
if (idx == N) idx = 0;
55+
}
56+
57+
void save (const char* prefix)
58+
{
59+
std::ostringstream oss;
60+
oss << prefix << "-times.log";
61+
62+
std::ofstream aof(oss.str().c_str());
63+
if (aof.is_open()) {
64+
for (std::size_t k = 0; k < N; ++k) {
65+
aof << times[ (idx + k) % N ] << '\n';
66+
}
67+
}
68+
aof.close();
69+
}
70+
};
3771

3872

3973
void workThreadLoader(SotLoader *aSotLoader)
@@ -59,10 +93,12 @@ void workThreadLoader(SotLoader *aSotLoader)
5993
gettimeofday(&stop,0);
6094

6195
unsigned long long dt = 1000000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec);
96+
dataToLog.record ((double)dt * 1e-6);
6297
if (period > dt) {
6398
usleep(period - (unsigned)dt);
6499
}
65100
}
101+
dataToLog.save ("/tmp/geometric_simu");
66102
cond.notify_all();
67103
ros::waitForShutdown();
68104
}

0 commit comments

Comments
 (0)