Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 3ddbe05

Browse files
committedOct 3, 2018
API: miner_getstatdetail(). Several changes.
Change times to seconds. Add 'lastupdate' to global miner share info. Set lastupdate initially to time when farm got launched. This commit addresses a little bit of issue #1603.
1 parent e5d8aac commit 3ddbe05

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed
 

‎docs/API_DOCUMENTATION.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,12 @@ and expect back a response like this:
198198
"epoch_changes": 1, // Ethminer starts with epoch 0. First connection to pool increments this counter
199199
"hashrate": 46709128, // Overall HashRate in H/s
200200
"hostname": "<omitted-hostname>",
201-
"runtime": 4, // Total running time in minutes
201+
"runtime": 240, // Total running time in seconds
202202
"shares": { // Summarized info about shares
203203
"accepted": 5,
204204
"acceptedstale": 1,
205205
"invalid": 1,
206+
"lastupdate": 58, // Latest update of any share info of is X seconds ago
206207
"rejected": 0
207208
},
208209
"tstart": 63,
@@ -221,7 +222,7 @@ and expect back a response like this:
221222
"accepted": 3,
222223
"acceptedstale": 0,
223224
"invalid": 0,
224-
"lastupdate": 1, // Share info from this GPU updated X minutes ago
225+
"lastupdate": 58, // Share info from this GPU updated X seconds ago
225226
"rejected": 0
226227
},
227228
"temp": 53 // Temperature in °C
@@ -238,7 +239,7 @@ and expect back a response like this:
238239
"accepted": 2,
239240
"acceptedstale": 1,
240241
"invalid": 1,
241-
"lastupdate": 2,
242+
"lastupdate": 134,
242243
"rejected": 0
243244
},
244245
"temp": 56

‎libapicore/ApiServer.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ void ApiConnection::processRequest(Json::Value& jRequest, Json::Value& jResponse
675675
{
676676
jResponse["result"] = false;
677677
}
678-
679678
}
680679

681680
else if (_method == "miner_setverbosity")
@@ -922,8 +921,8 @@ Json::Value ApiConnection::getMinerStatHR()
922921
}
923922

924923

925-
Json::Value ApiConnection::getMinerStatDetailPerMiner(
926-
const WorkingProgress& p, const SolutionStats& s, size_t index)
924+
Json::Value ApiConnection::getMinerStatDetailPerMiner(const WorkingProgress& p,
925+
const SolutionStats& s, size_t index, const std::chrono::steady_clock::time_point& now)
927926
{
928927
Json::Value jRes;
929928
auto const& miner = Farm::f().getMiner(index);
@@ -941,9 +940,10 @@ Json::Value ApiConnection::getMinerStatDetailPerMiner(
941940
jshares["rejected"] = s.getRejects(index);
942941
jshares["invalid"] = s.getFailures(index);
943942
jshares["acceptedstale"] = s.getAcceptedStales(index);
944-
auto solution_lastupdated = std::chrono::duration_cast<std::chrono::minutes>(
945-
std::chrono::steady_clock::now() - s.getLastUpdated(index));
946-
jshares["lastupdate"] = uint64_t(solution_lastupdated.count()); // last update of this gpu stat was x minutes ago
943+
auto solution_lastupdated =
944+
std::chrono::duration_cast<std::chrono::seconds>(now - s.getLastUpdated(index));
945+
jshares["lastupdate"] =
946+
uint64_t(solution_lastupdated.count()); // last update of this gpu stat was x seconds ago
947947
jRes["shares"] = jshares;
948948

949949

@@ -995,8 +995,9 @@ Json::Value ApiConnection::getMinerStatDetailPerMiner(
995995
*/
996996
Json::Value ApiConnection::getMinerStatDetail()
997997
{
998-
auto runningTime = std::chrono::duration_cast<std::chrono::minutes>(
999-
std::chrono::steady_clock::now() - Farm::f().farmLaunched());
998+
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
999+
auto runningTime =
1000+
std::chrono::duration_cast<std::chrono::seconds>(now - Farm::f().farmLaunched());
10001001

10011002
SolutionStats s = Farm::f().getSolutionStats();
10021003
WorkingProgress p = Farm::f().miningProgress();
@@ -1007,7 +1008,7 @@ Json::Value ApiConnection::getMinerStatDetail()
10071008
Json::Value jRes;
10081009

10091010
jRes["version"] = ethminer_get_buildinfo()->project_name_with_version; // miner version.
1010-
jRes["runtime"] = uint64_t(runningTime.count()); // running time, in minutes.
1011+
jRes["runtime"] = uint64_t(runningTime.count()); // running time, in seconds.
10111012

10121013
{
10131014
// Even the client should know which host was queried
@@ -1052,7 +1053,7 @@ Json::Value ApiConnection::getMinerStatDetail()
10521053
{
10531054
for (size_t i = 0; i < Farm::f().getMiners().size(); i++)
10541055
{
1055-
jRes["gpus"].append(getMinerStatDetailPerMiner(p, s, i));
1056+
jRes["gpus"].append(getMinerStatDetailPerMiner(p, s, i, now));
10561057
}
10571058
}
10581059
else
@@ -1069,6 +1070,10 @@ Json::Value ApiConnection::getMinerStatDetail()
10691070
jshares["rejected"] = s.getRejects();
10701071
jshares["invalid"] = s.getFailures();
10711072
jshares["acceptedstale"] = s.getAcceptedStales();
1073+
auto solution_lastupdated =
1074+
std::chrono::duration_cast<std::chrono::seconds>(now - s.getLastUpdated());
1075+
jshares["lastupdate"] =
1076+
uint64_t(solution_lastupdated.count()); // last update of this gpu stat was x seconds ago
10721077
jRes["shares"] = jshares;
10731078

10741079
return jRes;

‎libapicore/ApiServer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class ApiConnection
5454
void onSendSocketDataCompleted(const boost::system::error_code& ec);
5555

5656
Json::Value getMinerStatDetail();
57-
Json::Value getMinerStatDetailPerMiner(
58-
const WorkingProgress& p, const SolutionStats& s, size_t index);
57+
Json::Value getMinerStatDetailPerMiner(const WorkingProgress& p, const SolutionStats& s,
58+
size_t index, const std::chrono::steady_clock::time_point& now);
5959

6060
Disconnected m_onDisconnected;
6161

‎libethcore/Farm.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ class Farm : public FarmFace
120120
* @brief Get information on the progress of mining this work package.
121121
* @return The progress with mining so far.
122122
*/
123-
WorkingProgress const& miningProgress() const
124-
{
125-
return m_progress;
126-
}
123+
WorkingProgress const& miningProgress() const { return m_progress; }
127124

128125
std::vector<std::shared_ptr<Miner>> getMiners() { return m_miners; }
129126

@@ -134,7 +131,7 @@ class Farm : public FarmFace
134131
return m_miners[index];
135132
}
136133

137-
SolutionStats getSolutionStats() { return m_solutionStats; } // returns a copy
134+
SolutionStats getSolutionStats() { return m_solutionStats; } // returns a copy
138135

139136
void failedSolution(unsigned _miner_index) override { m_solutionStats.failed(_miner_index); }
140137

@@ -233,8 +230,8 @@ class Farm : public FarmFace
233230
boost::asio::deadline_timer m_collectTimer;
234231
static const int m_collectInterval = 5000;
235232

236-
mutable SolutionStats m_solutionStats;
237233
std::chrono::steady_clock::time_point m_farm_launched = std::chrono::steady_clock::now();
234+
mutable SolutionStats m_solutionStats;
238235

239236
string m_pool_addresses;
240237

@@ -262,4 +259,3 @@ class Farm : public FarmFace
262259

263260
} // namespace eth
264261
} // namespace dev
265-

‎libethcore/Miner.h

+25-26
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#pragma once
1919

2020
#include <list>
21+
#include <numeric>
2122
#include <string>
2223
#include <thread>
23-
#include <numeric>
2424

2525
#include <boost/circular_buffer.hpp>
2626
#include <boost/timer.hpp>
@@ -89,7 +89,8 @@ class FormattedMemSize
8989
std::ostream& operator<<(std::ostream& os, const FormattedMemSize& s);
9090

9191
/// Pause mining
92-
typedef enum {
92+
typedef enum
93+
{
9394
MINING_NOT_PAUSED = 0x00000000,
9495
MINING_PAUSED_WAIT_FOR_T_START = 0x00000001,
9596
MINING_PAUSED_API = 0x00000002
@@ -121,10 +122,7 @@ struct MiningPause
121122
return (pause_reason != MinigPauseReason::MINING_NOT_PAUSED);
122123
}
123124

124-
bool is_mining_paused()
125-
{
126-
return is_mining_paused(get_mining_paused());
127-
}
125+
bool is_mining_paused() { return is_mining_paused(get_mining_paused()); }
128126

129127
std::string get_mining_paused_string(const MinigPauseReason& pause_reason)
130128
{
@@ -139,10 +137,7 @@ struct MiningPause
139137
return r;
140138
}
141139

142-
std::string get_mining_paused_string()
143-
{
144-
return get_mining_paused_string(get_mining_paused());
145-
}
140+
std::string get_mining_paused_string() { return get_mining_paused_string(get_mining_paused()); }
146141
};
147142

148143

@@ -174,40 +169,36 @@ class SolutionStats // Only updated by Poolmanager thread!
174169
if (m_accepts.size() <= miner_index)
175170
m_accepts.resize(miner_index + 1);
176171
m_accepts[miner_index]++;
177-
auto now = std::chrono::steady_clock::now();
178172
if (m_lastUpdated.size() <= miner_index)
179-
m_lastUpdated.resize(miner_index + 1, now);
180-
m_lastUpdated[miner_index] = now;
173+
m_lastUpdated.resize(miner_index + 1, m_tpInitalized);
174+
m_lastUpdated[miner_index] = std::chrono::steady_clock::now();
181175
}
182176
void rejected(unsigned miner_index)
183177
{
184178
if (m_rejects.size() <= miner_index)
185179
m_rejects.resize(miner_index + 1);
186180
m_rejects[miner_index]++;
187-
auto now = std::chrono::steady_clock::now();
188181
if (m_lastUpdated.size() <= miner_index)
189-
m_lastUpdated.resize(miner_index + 1, now);
190-
m_lastUpdated[miner_index] = now;
182+
m_lastUpdated.resize(miner_index + 1, m_tpInitalized);
183+
m_lastUpdated[miner_index] = std::chrono::steady_clock::now();
191184
}
192185
void failed(unsigned miner_index)
193186
{
194187
if (m_failures.size() <= miner_index)
195188
m_failures.resize(miner_index + 1);
196189
m_failures[miner_index]++;
197-
auto now = std::chrono::steady_clock::now();
198190
if (m_lastUpdated.size() <= miner_index)
199-
m_lastUpdated.resize(miner_index + 1, now);
200-
m_lastUpdated[miner_index] = now;
191+
m_lastUpdated.resize(miner_index + 1, m_tpInitalized);
192+
m_lastUpdated[miner_index] = std::chrono::steady_clock::now();
201193
}
202194
void acceptedStale(unsigned miner_index)
203195
{
204196
if (m_acceptedStales.size() <= miner_index)
205197
m_acceptedStales.resize(miner_index + 1);
206198
m_acceptedStales[miner_index]++;
207-
auto now = std::chrono::steady_clock::now();
208199
if (m_lastUpdated.size() <= miner_index)
209-
m_lastUpdated.resize(miner_index + 1, now);
210-
m_lastUpdated[miner_index] = now;
200+
m_lastUpdated.resize(miner_index + 1, m_tpInitalized);
201+
m_lastUpdated[miner_index] = std::chrono::steady_clock::now();
211202
}
212203

213204
unsigned getAccepts() const { return accumulate(m_accepts.begin(), m_accepts.end(), 0); }
@@ -245,9 +236,18 @@ class SolutionStats // Only updated by Poolmanager thread!
245236
std::chrono::steady_clock::time_point getLastUpdated(unsigned miner_index) const
246237
{
247238
if (m_lastUpdated.size() <= miner_index)
248-
return std::chrono::steady_clock::now();
239+
return m_tpInitalized;
249240
return m_lastUpdated[miner_index];
250241
}
242+
std::chrono::steady_clock::time_point getLastUpdated() const
243+
{
244+
/* return the newest update time of all GPUs */
245+
if (!m_lastUpdated.size())
246+
return m_tpInitalized;
247+
248+
auto max_index = std::max_element(m_lastUpdated.begin(), m_lastUpdated.end());
249+
return m_lastUpdated[std::distance(m_lastUpdated.begin(), max_index)];
250+
}
251251

252252
std::string getString(unsigned miner_index)
253253
{
@@ -267,12 +267,12 @@ class SolutionStats // Only updated by Poolmanager thread!
267267
}
268268

269269
private:
270-
271270
std::vector<unsigned> m_accepts = {};
272271
std::vector<unsigned> m_rejects = {};
273272
std::vector<unsigned> m_failures = {};
274273
std::vector<unsigned> m_acceptedStales = {};
275274
std::vector<std::chrono::steady_clock::time_point> m_lastUpdated = {};
275+
const std::chrono::steady_clock::time_point m_tpInitalized = std::chrono::steady_clock::now();
276276
};
277277

278278
std::ostream& operator<<(std::ostream& os, const SolutionStats& s);
@@ -320,8 +320,7 @@ class Miner : public Worker
320320
public:
321321
Miner(std::string const& _name, size_t _index)
322322
: Worker(_name + std::to_string(_index)), m_index(_index)
323-
{
324-
}
323+
{}
325324

326325
virtual ~Miner() = default;
327326

0 commit comments

Comments
 (0)
This repository has been archived.