Skip to content

Commit

Permalink
get_values now takes a vector of predicates instead of a group descri…
Browse files Browse the repository at this point in the history
…ptor to avoid unnecessary predicate re-generations
  • Loading branch information
JPenuchot committed Apr 5, 2022
1 parent 0c3deb6 commit 6066d53
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion grapher/include/grapher/utils/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace grapher {
/// For each iteration in entry, returns the sum of the values pointed by
/// value_jptr in the events matching the descriptor's predicates.
std::vector<double> get_values(benchmark_iteration_t const &iteration,
group_descriptor_t const &descriptor,
std::vector<predicate_t> const &predicates,
nlohmann::json::json_pointer value_jptr);

/// Merges the contents of b into a, with items of a being overwritten if items
Expand Down
6 changes: 5 additions & 1 deletion grapher/lib/grapher/plotters/compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "grapher/core.hpp"
#include "grapher/plotters/compare.hpp"
#include "grapher/predicates.hpp"
#include "grapher/utils/config.hpp"
#include "grapher/utils/json.hpp"
#include "grapher/utils/plot.hpp"
Expand Down Expand Up @@ -62,6 +63,9 @@ void plotter_compare_t::plot(benchmark_set_t const &bset,
sciplot::Plot plot;
apply_config(plot, config);

// Generating predicates
std::vector<predicate_t> predicates = get_predicates(descriptor);

for (benchmark_case_t const &bench : bset) {
std::vector<double> x_points;
std::vector<double> y_points;
Expand All @@ -77,7 +81,7 @@ void plotter_compare_t::plot(benchmark_set_t const &bset,
}

std::vector<double> const values =
get_values(iteration, descriptor, value_json_pointer);
get_values(iteration, predicates, value_json_pointer);

if (values.empty()) {
llvm::errs() << "[WARNING] No event in benchmark " << bench.name
Expand Down
5 changes: 4 additions & 1 deletion grapher/lib/grapher/plotters/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "grapher/core.hpp"
#include "grapher/plotters/stack.hpp"
#include "grapher/predicates.hpp"
#include "grapher/utils/config.hpp"
#include "grapher/utils/json.hpp"
#include "grapher/utils/plot.hpp"
Expand Down Expand Up @@ -84,10 +85,12 @@ void plotter_stack_t::plot(benchmark_set_t const &bset,
// Storing previous value as we iterate
std::string curve_name = descriptor.name;

std::vector<predicate_t> predicates = get_predicates(descriptor);

for (std::size_t i = 0; i < bench.iterations.size(); i++) {
benchmark_iteration_t const &iteration = bench.iterations[i];
std::vector<double> const values =
get_values(iteration, descriptor, feature_value_jptr);
get_values(iteration, predicates, feature_value_jptr);

if (values.empty()) {
llvm::errs() << "[ERROR] No event matching descriptor "
Expand Down
14 changes: 3 additions & 11 deletions grapher/lib/grapher/utils/json.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#include "grapher/utils/json.hpp"
#include "grapher/predicates.hpp"
#include "grapher/utils/config.hpp"

#include <algorithm>
#include <execution>
#include <fstream>
#include <iostream>
#include <optional>

#include <llvm/Support/raw_ostream.h>

#include <nlohmann/json.hpp>
#include <pstl/glue_execution_defs.h>

#include "grapher/predicates.hpp"
#include "grapher/utils/config.hpp"

namespace grapher {

std::vector<double> get_values(benchmark_iteration_t const &iteration,
group_descriptor_t const &descriptor,
std::vector<predicate_t> const &predicates,
nlohmann::json::json_pointer value_jptr) {
std::vector<double> res(iteration.samples.size());

Expand All @@ -37,8 +31,6 @@ std::vector<double> get_values(benchmark_iteration_t const &iteration,
nlohmann::json::array_t const &events =
j["traceEvents"].get_ref<nlohmann::json::array_t const &>();

std::vector<predicate_t> predicates = get_predicates(descriptor);

// Accumulate
double val = 0.;
for (nlohmann::json const &event : events) {
Expand Down

0 comments on commit 6066d53

Please sign in to comment.