-
Notifications
You must be signed in to change notification settings - Fork 1
FEAT: to_ingress_queue_size metric #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0ef9914
Initial version of LinkQueue
PaulRalnikov cd4ae5e
Delete useless usage of MetricsCollector in Link
PaulRalnikov 2736e47
Started MetricCollector refactoring
PaulRalnikov 5638ec4
Maybe final sollution
PaulRalnikov 698b57f
Rerfactoring MetricsCollector::set_filter
PaulRalnikov 0af0b24
Add LinkQueueSizeStorage class
PaulRalnikov 6252295
Merged queue_size metrics
PaulRalnikov 87cb7a5
Merge branch 'main' into fix-link-queues
PaulRalnikov 40197b4
Update source/metrics/write_to_csv.cpp
PaulRalnikov 710ecc6
Update source/metrics/plot_metadata.hpp
PaulRalnikov 459bac4
Add const to front
PaulRalnikov 47784ec
Merge branch 'main' into fix-link-queues
PaulRalnikov 1645e86
Merge branch 'main' into fix-link-queues
PaulRalnikov 0365ad2
Apply suggestion from @ArtyomPeshkov
PaulRalnikov fd85b27
Apply suggestion from @ArtyomPeshkov
PaulRalnikov 48c96eb
Apply suggestion from @ArtyomPeshkov
PaulRalnikov d1fb2dd
Update source/metrics/write_to_csv.cpp
PaulRalnikov c8368a4
Merge branch 'main' into fix-link-queues
PaulRalnikov 6d2b13f
Change LinkQueue constructor agrument list
PaulRalnikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include "link_queue.hpp" | ||
|
|
||
| #include "metrics/metrics_collector.hpp" | ||
| #include "scheduler.hpp" | ||
| #include "simple_packet_queue.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| std::string to_string(LinkQueueType type) { | ||
| switch (type) { | ||
| case LinkQueueType::FromEgress: | ||
| return "from_ingress_queue_size"; | ||
| case LinkQueueType::ToIngress: | ||
| return "to_ingress_queue_size"; | ||
| default: | ||
| LOG_ERROR(fmt::format("Undefined link queue type: {}", | ||
| static_cast<int>(type))); | ||
| return "queue_size"; | ||
| } | ||
| } | ||
|
|
||
| LinkQueue::LinkQueue(SimplePacketQueue a_queue, Id a_link_id, | ||
| LinkQueueType a_type) | ||
| : m_queue(std::move(a_queue)), m_link_id(a_link_id), m_type(a_type) {} | ||
|
|
||
| bool LinkQueue::push(Packet packet) { | ||
| bool result = m_queue.push(std::move(packet)); | ||
| MetricsCollector::get_instance().add_queue_size( | ||
| m_link_id, Scheduler::get_instance().get_current_time(), | ||
| m_queue.get_size(), m_type); | ||
| return result; | ||
| } | ||
|
|
||
| Packet LinkQueue::front() const { return m_queue.front(); } | ||
|
|
||
| void LinkQueue::pop() { | ||
| m_queue.pop(); | ||
| MetricsCollector::get_instance().add_queue_size( | ||
| m_link_id, Scheduler::get_instance().get_current_time(), | ||
| m_queue.get_size(), m_type); | ||
| } | ||
|
|
||
| SizeByte LinkQueue::get_size() const { return m_queue.get_size(); } | ||
|
|
||
| bool LinkQueue::empty() const { return m_queue.empty(); } | ||
|
|
||
| SizeByte LinkQueue::get_max_size() const { return m_queue.get_max_size(); } | ||
|
|
||
| } // namespace sim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #pragma once | ||
|
|
||
| #include "simple_packet_queue.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| enum class LinkQueueType { FromEgress, ToIngress }; | ||
|
|
||
| std::string to_string(LinkQueueType type); | ||
|
|
||
| // Class for two types of links: | ||
| // eggress queue of sourse link device or | ||
| // ingress queue of desination link device | ||
| class LinkQueue : public IPacketQueue { | ||
| public: | ||
| LinkQueue(SimplePacketQueue a_queue, Id a_link_id, LinkQueueType a_type); | ||
|
ArtyomPeshkov marked this conversation as resolved.
Outdated
|
||
| ~LinkQueue() = default; | ||
|
|
||
| bool push(Packet packet) final; | ||
| Packet front() const final; | ||
| void pop() final; | ||
|
|
||
| SizeByte get_size() const final; | ||
| bool empty() const final; | ||
| SizeByte get_max_size() const final; | ||
|
|
||
| private: | ||
| SimplePacketQueue m_queue; | ||
| Id m_link_id; | ||
| LinkQueueType m_type; | ||
| }; | ||
| } // namespace sim | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "draw_plots.hpp" | ||
|
|
||
| #include "utils/safe_matplot.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, | ||
| PlotMetadata metadata) { | ||
| if (data.empty()) { | ||
| return; | ||
| } | ||
| auto fig = put_on_same_plot(data, metadata); | ||
|
|
||
| matplot::safe_save(fig, path.string()); | ||
| } | ||
|
|
||
| matplot::figure_handle put_on_same_plot(PlotMetricsData data, | ||
| PlotMetadata metadata) { | ||
| auto fig = matplot::figure(true); | ||
| auto ax = fig->current_axes(); | ||
| ax->hold(matplot::on); | ||
|
|
||
| for (auto& [values, name] : data) { | ||
| values.draw_on_plot(fig, name); | ||
| } | ||
| ax->xlabel(metadata.x_label); | ||
| ax->ylabel(metadata.y_label); | ||
| ax->title(metadata.title); | ||
| ax->legend(std::vector<std::string>()); | ||
| return fig; | ||
| } | ||
|
|
||
| } // namespace sim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #pragma once | ||
| #include <matplot/matplot.h> | ||
|
|
||
| #include "metrics_storage.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| using PlotMetricsData = std::vector<std::pair<MetricsStorage, std::string> >; | ||
|
|
||
| // Puts data from different DataStorage on one plot | ||
| matplot::figure_handle put_on_same_plot(PlotMetricsData data, | ||
| PlotMetadata metadata); | ||
|
|
||
| // Draws data from different DataStorage on one plot | ||
| void draw_on_same_plot(std::filesystem::path path, PlotMetricsData data, | ||
| PlotMetadata metadata); | ||
| } // namespace sim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #include "links_queue_size_storage.hpp" | ||
|
|
||
| #include "draw_plots.hpp" | ||
| #include "link/i_link.hpp" | ||
| #include "multi_id_metrics_storage.hpp" | ||
| #include "utils/safe_matplot.hpp" | ||
| #include "write_to_csv.hpp" | ||
|
|
||
| namespace sim { | ||
|
|
||
| LinksQueueSizeStorage::LinksQueueSizeStorage(std::string a_filter) | ||
| : m_filter(a_filter) {} | ||
|
|
||
| void LinksQueueSizeStorage::add_record(Id id, LinkQueueType type, TimeNs time, | ||
| double value) { | ||
| std::pair<Id, LinkQueueType> key = std::make_pair(id, type); | ||
| auto it = m_storage.find(key); | ||
| if (it == m_storage.end()) { | ||
| std::string filename = get_metrics_filename(id); | ||
| if (!std::regex_match(filename, m_filter)) { | ||
| m_storage[std::move(key)] = std::nullopt; | ||
| } else { | ||
| MetricsStorage new_storage; | ||
| new_storage.add_record(time, value); | ||
| m_storage.emplace(std::move(key), std::move(new_storage)); | ||
| } | ||
| } else if (it->second.has_value()) { | ||
| it->second->add_record(time, value); | ||
| } | ||
| } | ||
|
|
||
| void LinksQueueSizeStorage::export_to_files( | ||
| std::filesystem::path output_dir_path) const { | ||
| std::map<Id, std::vector<std::pair<MetricsStorage, std::string> > > | ||
| multi_id_storage; | ||
| for (const auto& [key, values] : data()) { | ||
| auto [id, type] = key; | ||
| multi_id_storage[id].emplace_back(values, to_string(type)); | ||
| } | ||
| for (auto [id, storages] : multi_id_storage) { | ||
| write_to_csv(storages, output_dir_path / get_metrics_filename(id)); | ||
| } | ||
| } | ||
|
|
||
| void LinksQueueSizeStorage::draw_plots( | ||
| std::filesystem::path output_dir_path) const { | ||
| // for data from both from_ingress and to_ingress queue sizes | ||
| std::map<Id, PlotMetricsData> queue_size_data; | ||
| for (auto& [key, values] : data()) { | ||
| auto [link_id, type] = key; | ||
| std::string curve_name = to_string(type); | ||
| std::replace(curve_name.begin(), curve_name.end(), '_', ' '); | ||
| queue_size_data[link_id].emplace_back(values, curve_name); | ||
| } | ||
| for (auto [link_id, data] : queue_size_data) { | ||
| auto link = | ||
| IdentifierFactory::get_instance().get_object<ILink>(link_id); | ||
| PlotMetadata metadata = { | ||
| "Time, ns", "Values, bytes", | ||
| fmt::format("Queue size from {} to {}", link->get_from()->get_id(), | ||
| link->get_to()->get_id())}; | ||
|
|
||
| auto fig = put_on_same_plot(data, metadata); | ||
| auto ax = fig->current_axes(); | ||
|
|
||
| auto limits = ax->xlim(); | ||
|
|
||
| auto draw_gorizontal_line = [&limits]( | ||
| double line_y, std::string_view name, | ||
| std::initializer_list<float> color) { | ||
| matplot::line(0, line_y, limits[1], line_y) | ||
| ->line_width(1.5) | ||
| .color(color) | ||
| .display_name(name); | ||
| }; | ||
|
|
||
| draw_gorizontal_line(link->get_max_from_egress_buffer_size().value(), | ||
| "max from egress", {1.f, 0.f, 0.f}); | ||
| draw_gorizontal_line(link->get_max_to_ingress_queue_size().value(), | ||
| "max to ingress", {0.f, 0.f, 1.f}); | ||
|
|
||
| ax->xlim({0, limits[1]}); | ||
| ax->color("white"); | ||
|
|
||
| std::filesystem::path plot_path = | ||
| output_dir_path / fmt::format("{}.svg", link_id); | ||
|
|
||
| matplot::safe_save(fig, plot_path.string()); | ||
| } | ||
| } | ||
|
|
||
| std::map<std::pair<Id, LinkQueueType>, MetricsStorage> | ||
| LinksQueueSizeStorage::data() const { | ||
| std::map<std::pair<Id, LinkQueueType>, MetricsStorage> result; | ||
| for (auto [id, maybe_storage] : m_storage) { | ||
| if (maybe_storage) { | ||
| result[id] = maybe_storage.value(); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| std::string LinksQueueSizeStorage::get_metrics_filename(Id id) const { | ||
| return fmt::format("queue_size/{}.csv", id); | ||
| } | ||
| } // namespace sim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
| #include <filesystem> | ||
| #include <map> | ||
| #include <optional> | ||
| #include <regex> | ||
| #include <utility> | ||
|
|
||
| #include "link/packet_queue/link_queue.hpp" | ||
| #include "metrics_storage.hpp" | ||
| #include "types.hpp" | ||
|
|
||
| namespace sim { | ||
| class LinksQueueSizeStorage { | ||
| public: | ||
| LinksQueueSizeStorage(std::string filter); | ||
|
|
||
| void add_record(Id id, LinkQueueType type, TimeNs time, double value); | ||
| void export_to_files(std::filesystem::path output_dir_path) const; | ||
| void draw_plots(std::filesystem::path output_dir_path) const; | ||
|
|
||
| std::map<std::pair<Id, LinkQueueType>, MetricsStorage> data() const; | ||
|
|
||
| private: | ||
| std::string get_metrics_filename(Id id) const; | ||
|
|
||
| // If m_storage does not contain some id, there was no check is metrics file | ||
| // name for id correspond to m_filter | ||
| // If m_storage[id] = std::nullopt, this check was failed | ||
| // Otherwice, check was succseed | ||
| std::map<std::pair<Id, LinkQueueType>, std::optional<MetricsStorage>> | ||
| m_storage; | ||
|
|
||
| std::regex m_filter; | ||
| }; | ||
| } // namespace sim |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.