From 070ce923574dcc57435cb3fb2dfe86b6a38cd249 Mon Sep 17 00:00:00 2001 From: MDBijman Date: Tue, 24 Jan 2017 12:15:26 +0100 Subject: Initial code commit with organized dependencies --- Simulator/include/database/Queries.h | 131 +++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Simulator/include/database/Queries.h (limited to 'Simulator/include/database/Queries.h') diff --git a/Simulator/include/database/Queries.h b/Simulator/include/database/Queries.h new file mode 100644 index 00000000..73afc1a1 --- /dev/null +++ b/Simulator/include/database/Queries.h @@ -0,0 +1,131 @@ +#pragma once +#include "Query.h" + +namespace Database +{ + namespace Queries + { + Query GET_QUEUED_EXPERIMENTS(std::string(R"query( + SELECT experiment_id FROM queued_experiments; + )query")); + + Query<> REMOVE_QUEUED_EXPERIMENT(std::string(R"query( + DELETE FROM queued_experiments WHERE experiment_id = $id; + )query")); + + Query GET_EXPERIMENT_BY_ID(std::string(R"query( + SELECT id, simulation_id, path_id, trace_id, scheduler_name, name FROM experiments WHERE id = $id; + )query")); + + Query GET_PATH_BY_ID(std::string(R"query( + SELECT id, simulation_id, name, datetime_created FROM paths WHERE id = $id; + )query")); + + Query GET_SECTION_BY_PATH_ID(std::string(R"query( + SELECT id, path_id, datacenter_id, start_tick FROM sections WHERE path_id = $id; + )query")); + + + /* + Returns the type of the scheduler of the given simulation section. + Returns: + Binds: + */ + Query GET_SCHEDULER_TYPE_OF_EXPERIMENT(std::string(R"query( + SELECT scheduler_name FROM experiments WHERE id = $id; + )query")); + + /* + Returns the id of the trace of the given simulation section. + Returns: + Binds: + */ + Query GET_TRACE_OF_EXPERIMENT(std::string(R"query( + SELECT trace_id FROM experiments WHERE id = $id; + )query")); + + /* + Returns all columns of each room belonging to the given datacenter. + Returns: + Binds: + */ + Query GET_ROOMS_OF_DATACENTER(std::string(R"query( + SELECT * FROM rooms WHERE datacenter_id = $id; + )query")); + + /* + Returns all columns of each rack belonging to the given room. + Returns: + Binds: + */ + Query GET_RACKS_OF_ROOM(std::string(R"query( + SELECT racks.* FROM tiles, objects, racks + WHERE objects.id = tiles.object_id + AND objects.id = racks.id + AND tiles.room_id = $id; + )query")); + + /* + Returns the machine in a given rack. + Returns: + Binds: + */ + Query GET_MACHINES_OF_RACK(std::string(R"query( + SELECT id, position FROM machines + WHERE rack_id = $rid; + )query")); + + /* + Returns all columns of each task belonging to the given trace. + Returns: + Binds: + */ + Query GET_TASKS_OF_TRACE(std::string(R"query( + SELECT * FROM tasks WHERE trace_id = $id; + )query")); + + /* + Returns the information of each cpu in the given rack, and their corresponding machine. + Returns: + Binds: + */ + Query GET_CPUS_IN_RACK(std::string(R"query( + SELECT machines.position AS slot, cpus.clock_rate_mhz AS machine_speed, cpus.number_of_cores AS cores, cpus.energy_consumption_w AS energy_consumption, cpus.failure_model_id AS failure_model_id FROM cpus, machine_cpus, machines + WHERE machine_cpus.cpu_id = cpus.id + AND machine_cpus.machine_id = machines.id + AND machines.rack_id = $id; + )query")); + + /* + Returns the information of each gpu in the given rack, and their corresponding machine. + Returns: + Binds: + */ + Query GET_GPUS_IN_RACK(std::string(R"query( + SELECT machines.position AS slot, gpus.clock_rate_mhz AS speed, gpus.number_of_cores AS cores, gpus.energy_consumption_w AS energy_consumption, gpus.failure_model_id AS failure_model_id FROM gpus, machine_gpus, machines + WHERE machine_gpus.gpu_id = gpus.id + AND machine_gpus.machine_id = machines.id + AND machines.rack_id = $id; + )query")); + + /* + Inserts the state of a workload into the task_state table. + Returns: <> + Binds: + */ + Query<> WRITE_WORKLOAD_STATE(std::string(R"query( + INSERT INTO task_states (task_id, experiment_id, tick, flops_left) + VALUES ($tid, $ssid, $tick, $flops); + )query")); + + /* + Inserts the state of a machine into the machine_state table. + Returns: <> + Binds: + */ + Query<> WRITE_MACHINE_STATE(std::string(R"query( + INSERT INTO machine_states (task_id, machine_id, experiment_id, tick, temperature_c, in_use_memory_mb, load_fraction) + VALUES ($tid, $mid, $ssid, $tick, $temp, $mem, $load); + )query")); + } +} -- cgit v1.2.3