Browse Source

api: export card labels and count, renames stats command

renammed to "threads", stats was too much generic
2upstream
Tanguy Pruvot 10 years ago
parent
commit
3e43553735
  1. 30
      api.cpp
  2. 13
      api/index.php
  3. 9
      api/local-sample.php

30
api.cpp

@ -110,6 +110,9 @@ extern uint64_t global_hashrate;
extern uint32_t accepted_count; extern uint32_t accepted_count;
extern uint32_t rejected_count; extern uint32_t rejected_count;
extern int device_map[8];
extern char *device_name[8];
#define gpu_threads opt_n_threads #define gpu_threads opt_n_threads
/***************************************************************/ /***************************************************************/
@ -119,7 +122,8 @@ static void gpustatus(int thr_id)
if (thr_id >= 0 && thr_id < gpu_threads) { if (thr_id >= 0 && thr_id < gpu_threads) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu; struct cgpu_info *cgpu = &thr_info[thr_id].gpu;
char buf[512]; *buf = '\0'; char buf[512]; *buf = '\0';
char pstate[8]; *pstate = '\0'; char pstate[8];
char* card;
cgpu->thr_id = thr_id; cgpu->thr_id = thr_id;
@ -152,9 +156,11 @@ static void gpustatus(int thr_id)
if (cgpu->gpu_pstate == -1) if (cgpu->gpu_pstate == -1)
*pstate= '\0'; *pstate= '\0';
snprintf(buf, sizeof(buf), "GPU=%d;TEMP=%.1f;FAN=%d;FREQ=%d;" card = device_name[device_map[thr_id]];
"PST=%s;KHS=%.2f;HWF=%d;I=%d|",
thr_id, cgpu->gpu_temp, cgpu->gpu_fan, snprintf(buf, sizeof(buf), "GPU=%d;CARD=%s;TEMP=%.1f;FAN=%d;"
"FREQ=%d;PST=%s;KHS=%.2f;HWF=%d;I=%d|",
thr_id, card, cgpu->gpu_temp, cgpu->gpu_fan,
cgpu->gpu_clock, pstate, cgpu->khashes, cgpu->gpu_clock, pstate, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity); cgpu->hw_errors, cgpu->intensity);
@ -179,9 +185,10 @@ static char *getsummary(char *params)
*buffer = '\0'; *buffer = '\0';
sprintf(buffer, "NAME=%s;VER=%s;API=%s;" sprintf(buffer, "NAME=%s;VER=%s;API=%s;"
"ALGO=%s;KHS=%.2f;ACC=%d;REJ=%d;ACCMN=%.3f;DIFF=%.6f;UPTIME=%.0f;TS=%u|", "ALGO=%s;GPUS=%d;KHS=%.2f;ACC=%d;REJ=%d;"
"ACCMN=%.3f;DIFF=%.6f;UPTIME=%.0f;TS=%u|",
PACKAGE_NAME, PACKAGE_VERSION, APIVERSION, PACKAGE_NAME, PACKAGE_VERSION, APIVERSION,
algo, (double)global_hashrate / 1000.0, algo, gpu_threads, (double)global_hashrate / 1000.0,
accepted_count, rejected_count, accepted_count, rejected_count,
accps, global_diff, uptime, (uint32_t) ts); accps, global_diff, uptime, (uint32_t) ts);
return buffer; return buffer;
@ -190,7 +197,7 @@ static char *getsummary(char *params)
/** /**
* Returns gpu/thread specific stats * Returns gpu/thread specific stats
*/ */
static char *getstats(char *params) static char *getthreads(char *params)
{ {
*buffer = '\0'; *buffer = '\0';
for (int i = 0; i < gpu_threads; i++) for (int i = 0; i < gpu_threads; i++)
@ -211,9 +218,10 @@ static char *gethistory(char *params)
int records = stats_get_history(thr, data, ARRAY_SIZE(data)); int records = stats_get_history(thr, data, ARRAY_SIZE(data));
for (int i = 0; i < records; i++) { for (int i = 0; i < records; i++) {
time_t ts = data[i].tm_stat; time_t ts = data[i].tm_stat;
p += sprintf(p, "GPU=%d;KHS=%.2f;DIFF=%.6f;COUNT=%u;FOUND=%u;TS=%u|", p += sprintf(p, "GPU=%d;KHS=%.2f;DIFF=%.6f;"
data[i].gpu_id, data[i].hashrate, data[i].difficulty, data[i].hashcount, "COUNT=%u;FOUND=%u;TS=%u|",
data[i].hashfound, (uint32_t)ts); data[i].gpu_id, data[i].hashrate, data[i].difficulty,
data[i].hashcount, data[i].hashfound, (uint32_t)ts);
} }
return buffer; return buffer;
} }
@ -224,7 +232,7 @@ struct CMDS {
char *(*func)(char *); char *(*func)(char *);
} cmds[] = { } cmds[] = {
{ "summary", getsummary }, { "summary", getsummary },
{ "stats", getstats }, { "threads", getthreads },
{ "histo", gethistory }, { "histo", gethistory },
/* keep it the last */ /* keep it the last */
{ "help", gethelp }, { "help", gethelp },

13
api/index.php

@ -7,6 +7,10 @@ $configs = array(
//'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */ //'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */
); );
// 5 seconds max.
set_time_limit(5);
error_reporting(0);
function getdataFromPears() function getdataFromPears()
{ {
global $host, $configs; global $host, $configs;
@ -22,7 +26,7 @@ function getdataFromPears()
function ignoreField($key) function ignoreField($key)
{ {
$ignored = array('API','VER'); $ignored = array('API','VER','GPU','CARD');
return in_array($key, $ignored); return in_array($key, $ignored);
} }
@ -33,6 +37,7 @@ function translateField($key)
$intl['VER'] = 'Version'; $intl['VER'] = 'Version';
$intl['ALGO'] = 'Algorithm'; $intl['ALGO'] = 'Algorithm';
$intl['GPUS'] = 'GPUs';
$intl['KHS'] = 'Hash rate (kH/s)'; $intl['KHS'] = 'Hash rate (kH/s)';
$intl['ACC'] = 'Accepted shares'; $intl['ACC'] = 'Accepted shares';
$intl['ACCMN'] = 'Accepted / mn'; $intl['ACCMN'] = 'Accepted / mn';
@ -84,9 +89,11 @@ function displayData($data)
$htm .= '<tr><td class="key">'.translateField($key).'</td>'. $htm .= '<tr><td class="key">'.translateField($key).'</td>'.
'<td class="val">'.translateValue($key, $val, $summary)."</td></tr>\n"; '<td class="val">'.translateValue($key, $val, $summary)."</td></tr>\n";
} }
if (isset($summary['KHS']))
$totals[$summary['ALGO']] += floatval($summary['KHS']); $totals[$summary['ALGO']] += floatval($summary['KHS']);
foreach ($stats['stats'] as $g=>$gpu) { foreach ($stats['threads'] as $g=>$gpu) {
$htm .= '<tr><th class="gpu" colspan="2">'.$g."</th></tr>\n"; $card = isset($gpu['CARD']) ? $gpu['CARD'] : '';
$htm .= '<tr><th class="gpu" colspan="2">'.$g." $card</th></tr>\n";
foreach ($gpu as $key=>$val) { foreach ($gpu as $key=>$val) {
if (!empty($val) && !ignoreField($key)) if (!empty($val) && !ignoreField($key))
$htm .= '<tr><td class="key">'.translateField($key).'</td>'. $htm .= '<tr><td class="key">'.translateField($key).'</td>'.

9
api/local-sample.php

@ -5,6 +5,10 @@
defined('API_HOST') || define('API_HOST', '127.0.0.1'); defined('API_HOST') || define('API_HOST', '127.0.0.1');
defined('API_PORT') || define('API_PORT', 4068); defined('API_PORT') || define('API_PORT', 4068);
// 3 seconds max.
set_time_limit(3);
error_reporting(0);
function getsock($port) function getsock($port)
{ {
$socket = null; $socket = null;
@ -106,10 +110,11 @@ function request($cmd)
ob_start(); ob_start();
$summary = request('summary'); $summary = request('summary');
$stats = request('stats'); $threads = request('threads');
$histo = request('histo');
ob_end_clean(); ob_end_clean();
//echo ob_get_clean()."\n"; //echo ob_get_clean()."\n";
header("Content-Type: application/json"); header("Content-Type: application/json");
echo json_encode(compact('summary', 'stats'))."\n"; echo json_encode(compact('summary', 'threads', 'histo'))."\n";
?> ?>

Loading…
Cancel
Save