-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,69 @@ | ||
#include "./tox_dht_cap_histo.hpp" | ||
|
||
#include <imgui/imgui.h> | ||
|
||
void ToxDHTCapHisto::tick(float time_delta) { | ||
if (!_enabled) { | ||
return; | ||
} | ||
|
||
_time_since_last_add += time_delta; | ||
if (_time_since_last_add >= _value_add_interval) { | ||
_time_since_last_add = 0.f; // very loose | ||
|
||
const auto total = _tpi.toxDHTGetNumCloselist(); | ||
const auto with_cap = _tpi.toxDHTGetNumCloselistAnnounceCapable(); | ||
|
||
if (total == 0 || with_cap == 0) { | ||
_ratios.push_back(0.f); | ||
} else { | ||
_ratios.push_back(float(with_cap) / float(total)); | ||
} | ||
|
||
// TODO: limit | ||
while (_ratios.size() > 5*60) { | ||
_ratios.erase(_ratios.begin()); | ||
} | ||
} | ||
} | ||
|
||
void ToxDHTCapHisto::render(void) { | ||
{ // main window menubar injection | ||
// assumes the window "tomato" was rendered already by cg | ||
if (ImGui::Begin("tomato")) { | ||
if (ImGui::BeginMenuBar()) { | ||
ImGui::Separator(); | ||
if (ImGui::BeginMenu("Tox")) { | ||
ImGui::SeparatorText("DHT diagnostics"); | ||
|
||
ImGui::Checkbox("enabled", &_enabled); | ||
|
||
if (ImGui::MenuItem("show DHT announce capability histogram")) { | ||
_show_window = true; | ||
} | ||
|
||
ImGui::EndMenu(); | ||
} | ||
ImGui::EndMenuBar(); | ||
} | ||
|
||
} | ||
ImGui::End(); | ||
} | ||
|
||
|
||
if (_show_window) { | ||
if (ImGui::Begin("Tox DHT announce capability histogram", &_show_window)) { | ||
if (_enabled) { | ||
ImGui::PlotHistogram("##histogram", _ratios.data(), _ratios.size(), 0, nullptr, 0.f, 1.f, {-1, -1}); | ||
} else { | ||
ImGui::TextUnformatted("logging disabled!"); | ||
if (ImGui::Button("enable")) { | ||
_enabled = true; | ||
} | ||
} | ||
} | ||
ImGui::End(); | ||
} | ||
} | ||
|
This file contains 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,22 @@ | ||
#pragma once | ||
|
||
#include <solanaceae/toxcore/tox_private_interface.hpp> | ||
|
||
#include <vector> | ||
|
||
class ToxDHTCapHisto { | ||
ToxPrivateI& _tpi; | ||
|
||
bool _enabled {true}; | ||
bool _show_window {false}; | ||
|
||
std::vector<float> _ratios; | ||
const float _value_add_interval {1.f}; // every second | ||
float _time_since_last_add {0.f}; | ||
|
||
public: | ||
ToxDHTCapHisto(ToxPrivateI& tpi) : _tpi(tpi) {} | ||
|
||
void tick(float time_delta); | ||
void render(void); | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
#include <tox/tox_private.h> | ||
#include <solanaceae/toxcore/tox_private_interface.hpp> | ||
|
||
|
This file contains 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