From 2005056cd51c3f295c7e5be6a160d8025c40a082 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Tue, 30 May 2017 19:31:00 +0200 Subject: [PATCH] Measure times in hardcoded queries Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D410 --- src/query/engine.hpp | 22 +++++++++++++++++++ tests/integration/hardcoded_query/clique.hpp | 9 ++++---- .../create_full_profile_conceals_return.cpp | 3 --- .../create_full_profile_return.cpp | 3 --- .../create_full_profile_reveals_return.cpp | 3 --- .../hardcoded_query/create_garment.cpp | 3 --- .../create_garment_conceals.cpp | 3 --- .../create_garment_reveals.cpp | 3 --- .../hardcoded_query/delete_all.cpp | 3 --- .../hardcoded_query/match_garment.cpp | 3 --- .../match_garment_default_outfit.cpp | 3 --- ...match_garment_set_label_general_return.hpp | 3 --- .../hardcoded_query/match_profile.cpp | 3 --- .../match_profile_garment_score.cpp | 3 --- .../match_profile_garment_set_score.cpp | 3 --- .../match_profile_garment_update_score.cpp | 3 --- 16 files changed, 26 insertions(+), 47 deletions(-) diff --git a/src/query/engine.hpp b/src/query/engine.hpp index 59558020c..f309a3600 100644 --- a/src/query/engine.hpp +++ b/src/query/engine.hpp @@ -69,14 +69,36 @@ class QueryEngine : public Loggable { return true; } + clock_t start_time = clock(); auto preprocessed = preprocessor.preprocess(query); + clock_t end_parsing_time = clock(); auto plan = LoadCypher(preprocessed); + clock_t end_planning_time = clock(); auto result = plan->run(db_accessor, preprocessed.arguments, stream); + clock_t end_execution_time = clock(); if (UNLIKELY(!result)) { // info because it might be something like deadlock in which // case one thread is stopped and user has try again logger.info("Unable to execute query (execution returned false)"); + return result; } + + // helper function for calculating time in seconds + auto time_second = [](clock_t start, clock_t end) { + return query::TypedValue(double(end - start) / CLOCKS_PER_SEC); + }; + + std::map summary; + summary["query_parsing_time"] = time_second(start_time, end_parsing_time); + // This doesn't do any actual planning, but benchmarking harness knows how + // to work with this field. + summary["query_planning_time"] = + time_second(end_parsing_time, end_planning_time); + summary["query_plan_execution_time"] = + time_second(end_planning_time, end_execution_time); + summary["type"] = "rw"; + stream.Summary(summary); + return result; } diff --git a/tests/integration/hardcoded_query/clique.hpp b/tests/integration/hardcoded_query/clique.hpp index f2b9c2402..47792e322 100644 --- a/tests/integration/hardcoded_query/clique.hpp +++ b/tests/integration/hardcoded_query/clique.hpp @@ -186,8 +186,10 @@ bool run_general_query(GraphDbAccessor &db_accessor, const Parameters &args, for (auto x : V) { auto edge = get_edge(vertices[profile_index], *vertices_indexed[x]); if (edge == nullptr) continue; - auto prop = query::TypedValue(edge->PropsAt(db_accessor.property("score"))); - if (prop.type() == query::TypedValue::Type::Int) res += prop.Value(); + auto prop = + query::TypedValue(edge->PropsAt(db_accessor.property("score"))); + if (prop.type() == query::TypedValue::Type::Int) + res += prop.Value(); } return res; }; @@ -213,8 +215,5 @@ bool run_general_query(GraphDbAccessor &db_accessor, const Parameters &args, result.push_back(calc_score(results[i])); stream.Result(result); } - std::map meta{ - std::make_pair(std::string("type"), query::TypedValue(std::string("r")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_full_profile_conceals_return.cpp b/tests/integration/hardcoded_query/create_full_profile_conceals_return.cpp index 27468aaa5..2681f958b 100644 --- a/tests/integration/hardcoded_query/create_full_profile_conceals_return.cpp +++ b/tests/integration/hardcoded_query/create_full_profile_conceals_return.cpp @@ -28,9 +28,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_full_profile_return.cpp b/tests/integration/hardcoded_query/create_full_profile_return.cpp index df5217e46..63dd7118a 100644 --- a/tests/integration/hardcoded_query/create_full_profile_return.cpp +++ b/tests/integration/hardcoded_query/create_full_profile_return.cpp @@ -26,9 +26,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_full_profile_reveals_return.cpp b/tests/integration/hardcoded_query/create_full_profile_reveals_return.cpp index c68b5df11..bace8efe6 100644 --- a/tests/integration/hardcoded_query/create_full_profile_reveals_return.cpp +++ b/tests/integration/hardcoded_query/create_full_profile_reveals_return.cpp @@ -28,9 +28,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_garment.cpp b/tests/integration/hardcoded_query/create_garment.cpp index 0cf551cf4..f1e9fe2b5 100644 --- a/tests/integration/hardcoded_query/create_garment.cpp +++ b/tests/integration/hardcoded_query/create_garment.cpp @@ -26,9 +26,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_garment_conceals.cpp b/tests/integration/hardcoded_query/create_garment_conceals.cpp index 736a1b104..2b54094ab 100644 --- a/tests/integration/hardcoded_query/create_garment_conceals.cpp +++ b/tests/integration/hardcoded_query/create_garment_conceals.cpp @@ -28,9 +28,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/create_garment_reveals.cpp b/tests/integration/hardcoded_query/create_garment_reveals.cpp index 75bbac042..8d42e643c 100644 --- a/tests/integration/hardcoded_query/create_garment_reveals.cpp +++ b/tests/integration/hardcoded_query/create_garment_reveals.cpp @@ -28,9 +28,6 @@ class CPUPlan : public PlanInterface { stream.Header(headers); std::vector result{TypedValue(v)}; stream.Result(result); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/delete_all.cpp b/tests/integration/hardcoded_query/delete_all.cpp index b188ed17b..6c8f3aa32 100644 --- a/tests/integration/hardcoded_query/delete_all.cpp +++ b/tests/integration/hardcoded_query/delete_all.cpp @@ -20,9 +20,6 @@ class CPUPlan : public PlanInterface { for (auto v : db_accessor.vertices()) db_accessor.detach_remove_vertex(v); std::vector headers; stream.Header(headers); - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/match_garment.cpp b/tests/integration/hardcoded_query/match_garment.cpp index 5cf1bd061..10d5e6a12 100644 --- a/tests/integration/hardcoded_query/match_garment.cpp +++ b/tests/integration/hardcoded_query/match_garment.cpp @@ -31,9 +31,6 @@ class CPUPlan : public PlanInterface { stream.Result(result); } } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("r")))}; - stream.Summary(meta); return true; } ~CPUPlan() {} diff --git a/tests/integration/hardcoded_query/match_garment_default_outfit.cpp b/tests/integration/hardcoded_query/match_garment_default_outfit.cpp index 78652f4a5..d85c836f8 100644 --- a/tests/integration/hardcoded_query/match_garment_default_outfit.cpp +++ b/tests/integration/hardcoded_query/match_garment_default_outfit.cpp @@ -49,9 +49,6 @@ class CPUPlan : public PlanInterface { std::vector result{TypedValue(e)}; stream.Result(result); } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/match_garment_set_label_general_return.hpp b/tests/integration/hardcoded_query/match_garment_set_label_general_return.hpp index 0d5720676..cf09e4a20 100644 --- a/tests/integration/hardcoded_query/match_garment_set_label_general_return.hpp +++ b/tests/integration/hardcoded_query/match_garment_set_label_general_return.hpp @@ -31,8 +31,5 @@ bool run_general_query(GraphDbAccessor &db_accessor, const Parameters &args, stream.Result(result); } } - std::map meta{std::make_pair( - std::string("type"), query::TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/match_profile.cpp b/tests/integration/hardcoded_query/match_profile.cpp index a295e62d6..310423fde 100644 --- a/tests/integration/hardcoded_query/match_profile.cpp +++ b/tests/integration/hardcoded_query/match_profile.cpp @@ -37,9 +37,6 @@ class CPUPlan : public PlanInterface { stream.Result(result); } } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("r")))}; - stream.Summary(meta); return true; } ~CPUPlan() {} diff --git a/tests/integration/hardcoded_query/match_profile_garment_score.cpp b/tests/integration/hardcoded_query/match_profile_garment_score.cpp index a31840598..58bbf225e 100644 --- a/tests/integration/hardcoded_query/match_profile_garment_score.cpp +++ b/tests/integration/hardcoded_query/match_profile_garment_score.cpp @@ -52,9 +52,6 @@ class CPUPlan : public PlanInterface { stream.Result(result); } } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("r")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/match_profile_garment_set_score.cpp b/tests/integration/hardcoded_query/match_profile_garment_set_score.cpp index 252fb3911..168319544 100644 --- a/tests/integration/hardcoded_query/match_profile_garment_set_score.cpp +++ b/tests/integration/hardcoded_query/match_profile_garment_set_score.cpp @@ -56,9 +56,6 @@ class CPUPlan : public PlanInterface { std::vector result{TypedValue(e)}; stream.Result(result); } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; } diff --git a/tests/integration/hardcoded_query/match_profile_garment_update_score.cpp b/tests/integration/hardcoded_query/match_profile_garment_update_score.cpp index bd357a0a5..56fc3ff15 100644 --- a/tests/integration/hardcoded_query/match_profile_garment_update_score.cpp +++ b/tests/integration/hardcoded_query/match_profile_garment_update_score.cpp @@ -53,9 +53,6 @@ class CPUPlan : public PlanInterface { stream.Result(result); } } - std::map meta{ - std::make_pair(std::string("type"), TypedValue(std::string("rw")))}; - stream.Summary(meta); return true; }