summaryrefslogtreecommitdiff
path: root/Simulator/include/simulation/history/SimulationHistory.h
blob: f43968b79f4ae7fb12c33de7adb6e807cc8c9167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include "History.h"
#include "WorkloadSnapshot.h"
#include "MachineSnapshot.h"

#include <unordered_map>

namespace Simulation
{
	using WorkloadHistory = History<WorkloadSnapshot>;
	using MachineHistory = History<MachineSnapshot>;
	using HistoryRef = std::tuple<std::reference_wrapper<WorkloadHistory>, std::reference_wrapper<MachineHistory>>;

	class SimulationHistory
	{
	public:
		/*
			Adds the workload snapshot at the given tick.
		*/
		void addSnapshot(uint32_t tick, WorkloadSnapshot snapshots)
		{
			workloadHistory.addSnapshotAtTick(tick, snapshots);
		}
		
		/*
			Adds the machine snapshot at the given tick.
		*/
		void addSnapshot(uint32_t tick, MachineSnapshot snapshots)
		{
			machineHistory.addSnapshotAtTick(tick, snapshots);
		}

		/*
			Returns the equal_range of the workload snapshots at the given tick.
		*/
		auto getWorkloadSnapshot(uint32_t tick)
		{
			return workloadHistory.snapshotsAtTick(tick);
		}

		/*
			Returns the equal_range of the machine snapshots at the given tick.
		*/
		auto getMachineSnapshot(uint32_t tick)
		{
			return machineHistory.snapshotsAtTick(tick);
		}

		/*
			Returns a const tuple ref of the entire cached history of machines and workloads.
		*/
		const HistoryRef getHistory()
		{
			return std::make_tuple(
				std::ref(workloadHistory),
				std::ref(machineHistory)
			);
		}

		/*
			Clears the cache of history.
		*/
		void clearHistory()
		{
			workloadHistory.clear();
			machineHistory.clear();
		}

		/*
			Returns the number of snapshots that are in the history cache.
		*/
		size_t historySize()
		{
			return workloadHistory.size();
		}

	private:
		WorkloadHistory workloadHistory;
		MachineHistory machineHistory;
	};
}