Merge branch 'issue/0004-network-reload-histogram' (reload page + histogram + WS stats)
This commit is contained in:
@@ -448,6 +448,12 @@ NetworkStats NetworkSession::stats() const {
|
||||
return stats_;
|
||||
}
|
||||
|
||||
bool NetworkSession::reload_page(bool ignore_cache) {
|
||||
if (!ws_ || !ws_->is_connected()) return false;
|
||||
std::string params = ignore_cache ? "{\"ignoreCache\":true}" : "{\"ignoreCache\":false}";
|
||||
return ws_->send_command("Page.reload", params) > 0;
|
||||
}
|
||||
|
||||
std::string NetworkSession::export_har_json() const {
|
||||
// HAR 1.2 minimo. log.entries[].request/response/timings.
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
|
||||
@@ -154,6 +154,15 @@ public:
|
||||
// Drag-and-drop import/export HAR.
|
||||
std::string export_har_json() const;
|
||||
|
||||
// Envia Page.reload via CDP. ignore_cache=true equivalente a Ctrl+Shift+R.
|
||||
bool reload_page(bool ignore_cache = false);
|
||||
|
||||
// Stats del WebSocket subyacente — utiles para diagnosticar si el canal
|
||||
// CDP esta vivo aunque la tabla siga vacia.
|
||||
uint64_t ws_frames_in() const { return ws_ ? ws_->frames_in() : 0; }
|
||||
uint64_t ws_bytes_in() const { return ws_ ? ws_->bytes_in() : 0; }
|
||||
uint64_t ws_bytes_out() const { return ws_ ? ws_->bytes_out() : 0; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<CdpWs> ws_;
|
||||
std::string ws_url_;
|
||||
|
||||
+79
-2
@@ -7,6 +7,7 @@
|
||||
// Estado cross-panel via g_session() (session_state.h).
|
||||
|
||||
#include "imgui.h"
|
||||
#include "implot.h"
|
||||
#include "core/icons_tabler.h"
|
||||
#include "core/tokens.h"
|
||||
|
||||
@@ -503,6 +504,11 @@ struct NetUiState {
|
||||
std::string selected_id; // requestId estable
|
||||
|
||||
int detail_tab = 0; // 0 headers, 1 payload, 2 response, 3 cookies, 4 timing, 5 ws
|
||||
|
||||
// Histograma overview (request starts/s).
|
||||
bool show_histogram = true;
|
||||
int histogram_bins = 30;
|
||||
bool reload_ignore_cache = false;
|
||||
};
|
||||
NetUiState g_net_ui;
|
||||
|
||||
@@ -745,6 +751,17 @@ void draw_request_detail(const NetworkRequest& r, NetworkSession* net) {
|
||||
}
|
||||
|
||||
void render_network_toolbar(NetworkSession* net) {
|
||||
// Reload page (Page.reload via CDP). Si no hay sesion, deshabilita.
|
||||
if (!net) ImGui::BeginDisabled();
|
||||
if (ImGui::Button(TI_REFRESH " Reload")) {
|
||||
if (net) net->reload_page(g_net_ui.reload_ignore_cache);
|
||||
}
|
||||
if (!net) ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Bypass cache", &g_net_ui.reload_ignore_cache);
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("|");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(TI_TRASH " Clear")) {
|
||||
if (net) net->clear_log();
|
||||
g_net_ui.selected_id.clear();
|
||||
@@ -755,6 +772,8 @@ void render_network_toolbar(NetworkSession* net) {
|
||||
g_net_ui.paused = !g_net_ui.paused;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox(TI_CHART_HISTOGRAM " Histogram", &g_net_ui.show_histogram);
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("|");
|
||||
ImGui::SameLine();
|
||||
bool preserve = net ? net->preserve_log() : true;
|
||||
@@ -833,6 +852,51 @@ void render_network_panel(bool* p_open) {
|
||||
|
||||
// Snapshot + filtrado.
|
||||
auto reqs = net->snapshot();
|
||||
|
||||
// ---------- Histograma overview ----------
|
||||
if (g_net_ui.show_histogram) {
|
||||
std::vector<double> starts;
|
||||
starts.reserve(reqs.size());
|
||||
double t_max = 1.0;
|
||||
for (const auto& r : reqs) {
|
||||
if (r->t_started >= 0.0) {
|
||||
starts.push_back(r->t_started);
|
||||
if (r->t_started > t_max) t_max = r->t_started;
|
||||
}
|
||||
}
|
||||
// Tamaño bin dinamico — bins fijo 30, rango 0..t_max.
|
||||
if (ImPlot::BeginPlot("##req_histogram", ImVec2(-1, 100),
|
||||
ImPlotFlags_NoTitle | ImPlotFlags_NoMouseText |
|
||||
ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMenus |
|
||||
ImPlotFlags_NoFrame)) {
|
||||
ImPlot::SetupAxes("t (s)", "reqs/bin",
|
||||
ImPlotAxisFlags_NoMenus,
|
||||
ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoMenus);
|
||||
ImPlot::SetupAxisLimits(ImAxis_X1, 0.0, t_max + 0.001, ImPlotCond_Always);
|
||||
|
||||
if (!starts.empty()) {
|
||||
ImPlot::PlotHistogram("Requests/bin",
|
||||
starts.data(), (int)starts.size(),
|
||||
g_net_ui.histogram_bins, 1.0,
|
||||
ImPlotRange(0.0, t_max + 0.001));
|
||||
}
|
||||
|
||||
// Marcadores DOMContentLoaded / Load.
|
||||
auto stats = net->stats();
|
||||
if (stats.dom_content_loaded > 0) {
|
||||
double x = stats.dom_content_loaded;
|
||||
ImPlot::TagX(x, fn_tokens::colors::info, "DCL");
|
||||
}
|
||||
if (stats.load_event > 0) {
|
||||
double x = stats.load_event;
|
||||
ImPlot::TagX(x, fn_tokens::colors::success, "L");
|
||||
}
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
ImGui::Separator();
|
||||
}
|
||||
// ---------- /histograma ----------
|
||||
|
||||
std::string filt = g_net_ui.filter_text;
|
||||
std::string filt_lower = filt;
|
||||
std::transform(filt_lower.begin(), filt_lower.end(), filt_lower.begin(), ::tolower);
|
||||
@@ -1002,8 +1066,21 @@ void render_network_panel(bool* p_open) {
|
||||
ImGui::Text("L: %.2f", stats.load_event);
|
||||
}
|
||||
ImGui::SameLine(); ImGui::TextDisabled("|"); ImGui::SameLine();
|
||||
ImGui::Text("WS bytes in: %llu out: %llu",
|
||||
(unsigned long long)0, (unsigned long long)0);
|
||||
{
|
||||
uint64_t fin = net->ws_frames_in();
|
||||
uint64_t bin = net->ws_bytes_in();
|
||||
uint64_t bout = net->ws_bytes_out();
|
||||
bool alive = (fin > 0);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text,
|
||||
alive ? fn_tokens::colors::success : fn_tokens::colors::warning);
|
||||
ImGui::Text("CDP: %s", alive ? "alive" : "no events");
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(%llu frames, in %s / out %s)",
|
||||
(unsigned long long)fin,
|
||||
fmt_size((int64_t)bin).c_str(),
|
||||
fmt_size((int64_t)bout).c_str());
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user