22 #include <Eigen/Eigen> 23 #include <boost/algorithm/string/predicate.hpp> 24 #include <boost/filesystem.hpp> 25 #include <boost/foreach.hpp> 35 #ifdef HAVE_PYTHONLIBS 44 int main(
int argc,
char **argv) {
52 PRINT_ERROR(
RED "ERROR: ./timing_comparison <file_times1.txt> ... <file_timesN.txt>\n" RESET);
53 PRINT_ERROR(
RED "ERROR: rosrun ov_eval timing_comparison <file_times1.txt> ... <file_timesN.txt>\n" RESET);
54 std::exit(EXIT_FAILURE);
58 std::vector<std::string> names;
59 std::vector<ov_eval::Statistics> total_times;
60 PRINT_INFO(
"======================================\n");
61 for (
int z = 1; z < argc; z++) {
64 boost::filesystem::path path(argv[z]);
65 std::string name = path.stem().string();
66 PRINT_INFO(
"[TIME]: loading data for %s\n", name.c_str());
69 std::vector<std::string> names_temp;
70 std::vector<double> times;
71 std::vector<Eigen::VectorXd> timing_values;
73 PRINT_DEBUG(
"[TIME]: loaded %d timestamps from file (%d categories)!!\n", (
int)times.size(), (int)names_temp.size());
76 std::vector<ov_eval::Statistics> stats;
77 for (
size_t i = 0; i < names_temp.size(); i++)
81 for (
size_t i = 0; i < times.size(); i++) {
82 for (
size_t c = 0; c < names_temp.size(); c++) {
83 stats.at(c).timestamps.push_back(times.at(i));
84 stats.at(c).values.push_back(timing_values.at(i)(c));
89 for (
size_t i = 0; i < names_temp.size(); i++) {
90 stats.at(i).calculate();
91 PRINT_INFO(
"mean_time = %.4f | std = %.4f | 99th = %.4f | max = %.4f (%s)\n", stats.at(i).mean, stats.at(i).std,
92 stats.at(i).ninetynine, stats.at(i).max, names_temp.at(i).c_str());
97 names.push_back(name);
98 total_times.push_back(stats.at(stats.size() - 1));
102 PRINT_INFO(
"======================================\n");
105 #ifdef HAVE_PYTHONLIBS 111 std::vector<std::string> colors = {
"black",
"blue",
"red",
"green",
"cyan",
"magenta"};
117 double starttime = (total_times.at(0).timestamps.empty()) ? 0 : total_times.at(0).timestamps.at(0);
118 double endtime = (total_times.at(0).timestamps.empty()) ? 0 : total_times.at(0).timestamps.at(total_times.at(0).timestamps.size() - 1);
119 for (
size_t i = 0; i < total_times.size(); i++) {
120 for (
size_t j = 0; j < total_times.at(i).timestamps.size(); j++) {
121 total_times.at(i).timestamps.at(j) -= starttime;
126 for (
size_t n = 0; n < names.size(); n++) {
130 std::vector<double> times_skipped;
131 for (
size_t t = 0; t < total_times.at(n).timestamps.size(); t++) {
132 if (t % keep_every == 0) {
133 times_skipped.push_back(total_times.at(n).timestamps.at(t));
136 std::vector<double> values_skipped;
137 for (
size_t t = 0; t < total_times.at(n).values.size(); t++) {
138 if (t % keep_every == 0) {
139 values_skipped.push_back(total_times.at(n).values.at(t));
144 std::map<std::string, std::string> params;
145 params.insert({
"label", names.at(n)});
146 params.insert({
"linestyle",
"-"});
147 params.insert({
"color", colors.at(n % colors.size())});
Statistics object for a given set scalar time series values.
void figure_size(size_t w, size_t h)
bool plot(const std::vector< Numeric > &x, const std::vector< Numeric > &y, const std::map< std::string, std::string > &keywords)
void show(const bool block=true)
int main(int argc, char **argv)
static void setPrintLevel(const std::string &level)
#define PRINT_ERROR(x...)
void xlim(Numeric left, Numeric right)
void xlabel(const std::string &str, const std::map< std::string, std::string > &keywords={})
void ylabel(const std::string &str, const std::map< std::string, std::string > &keywords={})
#define PRINT_DEBUG(x...)
static void load_timing_flamegraph(std::string path, std::vector< std::string > &names, std::vector< double > ×, std::vector< Eigen::VectorXd > &timing_values)
Load comma separated timing file from pid_ros.py file.