Skip to content

Commit 0da2c90

Browse files
committed
graphs.html: real template build latency, conditional label
Measure actual build_template() time in TemplateBuilder (was hardcoded 0 for embedded mode). Store in stat log as work_latency, exposed via getwork_latency graph source. Label adapts to mode via currency_info.embedded/has_rpc flags: - Embedded only: "Embedded Template Build Latency" - RPC + Embedded: "GetBlockTemplate Latency (RPC + Embedded)" - RPC only: "GetBlockTemplate Latency (RPC)"
1 parent 4730305 commit 0da2c90

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/core/web_server.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,7 @@ void MiningInterface::refresh_work()
21212121
m_last_work_update_time = std::chrono::duration_cast<std::chrono::seconds>(
21222122
std::chrono::steady_clock::now().time_since_epoch()).count();
21232123

2124+
m_last_work_latency.store(static_cast<double>(wd.m_latency), std::memory_order_relaxed);
21242125
LOG_INFO << "[LTC] refresh_work: height=" << wd.m_data.value("height", 0)
21252126
<< " txs=" << wd.m_hashes.size()
21262127
<< " latency=" << wd.m_latency << "ms"
@@ -4287,6 +4288,10 @@ nlohmann::json MiningInterface::rest_web_currency_info()
42874288
if (m_explorer_enabled && !m_explorer_url.empty())
42884289
result["explorer_url"] = m_explorer_url;
42894290

4291+
// Mode indicators for conditional UI
4292+
result["embedded"] = (m_embedded_node != nullptr);
4293+
result["has_rpc"] = (m_coin_rpc != nullptr);
4294+
42904295
return result;
42914296
}
42924297

@@ -5871,7 +5876,7 @@ nlohmann::json MiningInterface::rest_web_graph_data(const std::string& source, c
58715876
result.push_back({entry.time, nullptr, bin_width, 0});
58725877
}
58735878
else if (source == "getwork_latency") {
5874-
result.push_back({entry.time, 0.0, bin_width, 0});
5879+
result.push_back({entry.time, entry.work_latency, bin_width, 0});
58755880
}
58765881
else if (source == "memory_usage") {
58775882
result.push_back({entry.time, entry.memory_usage, bin_width, 0});
@@ -6072,6 +6077,9 @@ void MiningInterface::update_stat_log()
60726077
}
60736078
}
60746079

6080+
// Work latency (template build time in seconds, matching p2pool getwork_latency)
6081+
entry.work_latency = m_last_work_latency.load(std::memory_order_relaxed) / 1000.0;
6082+
60756083
{
60766084
std::lock_guard<std::mutex> lock(m_stat_log_mutex);
60776085
m_stat_log.push_back(entry);

src/core/web_server.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server
860860
std::atomic<bool> m_work_valid{false};
861861
std::atomic<uint64_t> m_work_generation{0}; // incremented on each refresh_work()
862862
std::atomic<int64_t> m_last_work_update_time{0}; // monotonic seconds since epoch
863+
std::atomic<double> m_last_work_latency{0}; // template build latency (ms)
863864
nlohmann::json m_cached_template;
864865

865866
public:
@@ -1216,6 +1217,7 @@ class MiningInterface : public jsonrpccxx::JsonRpc2Server
12161217
double attempts_to_block;
12171218
double block_value;
12181219
double memory_usage{0}; // RSS in bytes
1220+
double work_latency{0}; // template build latency (ms)
12191221
};
12201222
std::vector<StatLogEntry> m_stat_log;
12211223
mutable std::mutex m_stat_log_mutex;

src/impl/ltc/coin/template_builder.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class TemplateBuilder {
163163
const MWEBTracker* mweb_tracker = nullptr)
164164
{
165165
(void)is_testnet; // reserved for future per-network rules
166+
auto t0 = std::chrono::steady_clock::now();
166167

167168
auto tip_opt = chain.tip();
168169
if (!tip_opt)
@@ -304,7 +305,9 @@ class TemplateBuilder {
304305
<< " tip_ts=" << tip.header.m_timestamp
305306
<< " now=" << now_ts
306307
<< " synced=" << chain.is_synced();
307-
return rpc::WorkData{std::move(data), std::move(tx_objects), std::move(tx_hashes), 0};
308+
auto t1 = std::chrono::steady_clock::now();
309+
auto latency_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
310+
return rpc::WorkData{std::move(data), std::move(tx_objects), std::move(tx_hashes), latency_ms};
308311
}
309312

310313
};

web-static/graphs.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ <h2>Desired version rates</h2>
8080
<h2>Traffic rate</h2>
8181
<svg id="traffic_rate"></svg>
8282

83-
<h2>Bitcoind GetBlockTemplate Latency</h2>
83+
<h2 id="latency_title">Template Build Latency</h2>
8484
<svg id="getwork_latency"></svg>
8585

8686
<h2>Memory Usage</h2>
@@ -559,8 +559,14 @@ <h2>Memory Usage</h2>
559559
plot(d3.select('#traffic_rate'), 'B/s', 'B', data_to_lines(data, function(line){ return parseInt(line.label) }), true);
560560
});
561561

562+
var latencyLabel = currency_info.embedded ? "Template Build" :
563+
currency_info.has_rpc ? "GetBlockTemplate (RPC)" : "Template Build";
564+
d3.select("#latency_title").text(currency_info.embedded ?
565+
"Embedded Template Build Latency" :
566+
currency_info.has_rpc ? "GetBlockTemplate Latency (RPC + Embedded)" :
567+
"Template Build Latency");
562568
plot_later(d3.select("#getwork_latency"), "s", null, [
563-
{"url": "../web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": "Getwork Latency"}
569+
{"url": "../web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": latencyLabel}
564570
], false);
565571

566572
plot_later(d3.select("#memory_usage"), "B", null, [

0 commit comments

Comments
 (0)