Skip to content

Commit

Permalink
Adapted to new Sciplot API
Browse files Browse the repository at this point in the history
  • Loading branch information
JPenuchot committed Aug 3, 2022
1 parent e0e8224 commit a671230
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion grapher/lib/grapher/plotters/compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void plotter_compare_t::plot(benchmark_set_t const &bset,

for (group_descriptor_t const &descriptor : group_descriptors) {
// Plot init
sciplot::Plot plot;
sciplot::Plot2D plot;
apply_config(plot, config);

// Generating predicates
Expand Down
15 changes: 12 additions & 3 deletions grapher/lib/grapher/plotters/compare_by.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <filesystem>
#include <fstream>
#include <string>
#include <thread>
#include <vector>

#include <boost/container/small_vector.hpp>
Expand Down Expand Up @@ -127,7 +128,6 @@ grapher::json_t plotter_compare_by_t::get_default_config() const {
void plotter_compare_by_t::plot(benchmark_set_t const &bset,
std::filesystem::path const &dest,
grapher::json_t const &config) const {
namespace sp = sciplot;
namespace fs = std::filesystem;

// Config reading
Expand Down Expand Up @@ -156,9 +156,11 @@ void plotter_compare_by_t::plot(benchmark_set_t const &bset,

// Drawing, ie. unwrapping the nested maps and drawing curves + saving plots

std::vector<std::thread> thread_pool;

for (auto const &[key, curve_aggregate] : curve_aggregate_map) {
// Plot init
sp::Plot plot;
sciplot::Plot2D plot;
apply_config(plot, config);

for (auto const &[bench_name, benchmark_curve] : curve_aggregate) {
Expand Down Expand Up @@ -205,7 +207,14 @@ void plotter_compare_by_t::plot(benchmark_set_t const &bset,
}
}

save_plot(plot, dest / to_string(key, demangle), config);
// Writing in parallel
thread_pool.emplace_back(&save_plot, std::move(plot),
dest / to_string(key, demangle), config);
}

// Joining before returning
for (std::thread &t : thread_pool) {
t.join();
}
}

Expand Down
9 changes: 4 additions & 5 deletions grapher/lib/grapher/plotters/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <fmt/core.h>

#include <sciplot/Plot2D.hpp>
#include <sciplot/sciplot.hpp>

#include "grapher/core.hpp"
Expand Down Expand Up @@ -40,16 +41,14 @@ void plotter_stack_t::plot(benchmark_set_t const &bset,

// Drawing

std::vector<sciplot::Plot> plots;
std::vector<sciplot::Plot2D> plots;

// Storing max y value for normalization
double max_y_val = 0.;

/// Draws a stacked curve graph for a given benchmark
auto draw_plot = [&](benchmark_case_t const &bench) -> sciplot::Plot {
namespace sp = sciplot;

sp::Plot plot;
auto draw_plot = [&](benchmark_case_t const &bench) -> sciplot::Plot2D {
sciplot::Plot2D plot;
apply_config(plot, config);

// x axis
Expand Down
12 changes: 7 additions & 5 deletions grapher/lib/grapher/utils/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <fstream>

#include <nlohmann/json.hpp>
#include <sciplot/Canvas.hpp>
#include <sciplot/Figure.hpp>

namespace grapher {

Expand Down Expand Up @@ -80,9 +82,9 @@ write_descriptors(std::vector<group_descriptor_t> const &descriptors) {
grapher::json_t::array_t res;
res.reserve(descriptors.size());

for (group_descriptor_t const &d : descriptors) {
res.push_back(group_descriptor_json(d));
}
std::transform(descriptors.begin(), descriptors.end(),
std::back_inserter(res), &group_descriptor_json);

return res;
}

Expand Down Expand Up @@ -137,7 +139,7 @@ grapher::json_t merge_into(grapher::json_t a, grapher::json_t const &b) {
return a;
}

void save_plot(sciplot::Plot const &plot, std::string const &dest,
void save_plot(sciplot::Plot2D const &plot, std::string const &dest,
grapher::json_t const &config) {
namespace fs = std::filesystem;
std::vector<std::string> plot_file_extensions = config.value(
Expand All @@ -157,7 +159,7 @@ void save_plot(sciplot::Plot const &plot, std::string const &dest,
file_dest.replace_filename(new_filename);
}

plot.save(dest + extension);
sciplot::Canvas{{sciplot::Figure{{plot}}}}.save(dest + extension);
}
}

Expand Down

0 comments on commit a671230

Please sign in to comment.