Browse Source

api: add meminfo query to debug mem storages

2upstream
Tanguy Pruvot 10 years ago
parent
commit
047e79a9fc
  1. 22
      api.cpp
  2. 27
      hashlog.cpp
  3. 2
      miner.h
  4. 18
      stats.cpp

22
api.cpp

@ -225,6 +225,25 @@ static char *gethistory(char *params)
return buffer; return buffer;
} }
/**
* Some debug infos about memory usage
*/
static char *getmeminfo(char *params)
{
uint64_t smem, hmem, totmem;
uint32_t srec, hrec;
stats_getmeminfo(&smem, &srec);
hashlog_getmeminfo(&hmem, &hrec);
totmem = smem + hmem;
*buffer = '\0';
sprintf(buffer, "STATS=%u;HASHLOG=%u;MEM=%llu|",
srec, hrec, totmem);
return buffer;
}
static char *gethelp(char *params); static char *gethelp(char *params);
struct CMDS { struct CMDS {
const char *name; const char *name;
@ -232,7 +251,8 @@ struct CMDS {
} cmds[] = { } cmds[] = {
{ "summary", getsummary }, { "summary", getsummary },
{ "threads", getthreads }, { "threads", getthreads },
{ "histo", gethistory }, { "histo", gethistory },
{ "meminfo", getmeminfo },
/* keep it the last */ /* keep it the last */
{ "help", gethelp }, { "help", gethelp },
}; };

27
hashlog.cpp

@ -43,7 +43,7 @@ static uint64_t hextouint(char* jobid)
/** /**
* @return time of a job/nonce submission (or last nonce if nonce is 0) * @return time of a job/nonce submission (or last nonce if nonce is 0)
*/ */
extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce) uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce)
{ {
uint32_t ret = 0; uint32_t ret = 0;
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
@ -61,7 +61,7 @@ extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nonce)
/** /**
* Store submitted nonces of a job * Store submitted nonces of a job
*/ */
extern "C" void hashlog_remember_submit(struct work* work, uint32_t nonce) void hashlog_remember_submit(struct work* work, uint32_t nonce)
{ {
uint64_t njobid = hextouint(work->job_id); uint64_t njobid = hextouint(work->job_id);
uint64_t key = (njobid << 32) + nonce; uint64_t key = (njobid << 32) + nonce;
@ -78,7 +78,7 @@ extern "C" void hashlog_remember_submit(struct work* work, uint32_t nonce)
/** /**
* Update job scanned range * Update job scanned range
*/ */
extern "C" void hashlog_remember_scan_range(struct work* work) void hashlog_remember_scan_range(struct work* work)
{ {
uint64_t njobid = hextouint(work->job_id); uint64_t njobid = hextouint(work->job_id);
uint64_t key = (njobid << 32); uint64_t key = (njobid << 32);
@ -120,7 +120,7 @@ extern "C" void hashlog_remember_scan_range(struct work* work)
* Returns the range of a job * Returns the range of a job
* @return uint64_t to|from * @return uint64_t to|from
*/ */
extern "C" uint64_t hashlog_get_scan_range(char* jobid) uint64_t hashlog_get_scan_range(char* jobid)
{ {
uint64_t ret = 0; uint64_t ret = 0;
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
@ -149,7 +149,7 @@ extern "C" uint64_t hashlog_get_scan_range(char* jobid)
* Search last submitted nonce for a job * Search last submitted nonce for a job
* @return max nonce * @return max nonce
*/ */
extern "C" uint32_t hashlog_get_last_sent(char* jobid) uint32_t hashlog_get_last_sent(char* jobid)
{ {
uint32_t nonce = 0; uint32_t nonce = 0;
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
@ -167,7 +167,7 @@ extern "C" uint32_t hashlog_get_last_sent(char* jobid)
/** /**
* Remove entries of a job... * Remove entries of a job...
*/ */
extern "C" void hashlog_purge_job(char* jobid) void hashlog_purge_job(char* jobid)
{ {
int deleted = 0; int deleted = 0;
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);
@ -189,7 +189,7 @@ extern "C" void hashlog_purge_job(char* jobid)
/** /**
* Remove old entries to reduce memory usage * Remove old entries to reduce memory usage
*/ */
extern "C" void hashlog_purge_old(void) void hashlog_purge_old(void)
{ {
int deleted = 0; int deleted = 0;
uint32_t now = (uint32_t) time(NULL); uint32_t now = (uint32_t) time(NULL);
@ -210,15 +210,24 @@ extern "C" void hashlog_purge_old(void)
/** /**
* Reset the submitted nonces cache * Reset the submitted nonces cache
*/ */
extern "C" void hashlog_purge_all(void) void hashlog_purge_all(void)
{ {
tlastshares.clear(); tlastshares.clear();
} }
/**
* API meminfo
*/
void hashlog_getmeminfo(uint64_t *mem, uint32_t *records)
{
(*records) = tlastshares.size();
(*mem) = (*records) * sizeof(hashlog_data);
}
/** /**
* Used to debug ranges... * Used to debug ranges...
*/ */
extern "C" void hashlog_dump_job(char* jobid) void hashlog_dump_job(char* jobid)
{ {
if (opt_debug) { if (opt_debug) {
uint64_t njobid = hextouint(jobid); uint64_t njobid = hextouint(jobid);

2
miner.h

@ -556,12 +556,14 @@ void hashlog_purge_old(void);
void hashlog_purge_job(char* jobid); void hashlog_purge_job(char* jobid);
void hashlog_purge_all(void); void hashlog_purge_all(void);
void hashlog_dump_job(char* jobid); void hashlog_dump_job(char* jobid);
void hashlog_getmeminfo(uint64_t *mem, uint32_t *records);
void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found); void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found);
double stats_get_speed(int thr_id, double def_speed); double stats_get_speed(int thr_id, double def_speed);
int stats_get_history(int thr_id, struct stats_data *data, int max_records); int stats_get_history(int thr_id, struct stats_data *data, int max_records);
void stats_purge_old(void); void stats_purge_old(void);
void stats_purge_all(void); void stats_purge_all(void);
void stats_getmeminfo(uint64_t *mem, uint32_t *records);
struct thread_q; struct thread_q;

18
stats.cpp

@ -25,7 +25,7 @@ extern int device_map[8];
/** /**
* Store speed per thread (todo: compute vardiff ?) * Store speed per thread (todo: compute vardiff ?)
*/ */
extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found) void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found)
{ {
uint64_t gpu = device_map[thr_id]; uint64_t gpu = device_map[thr_id];
uint64_t key = (gpu << 56) + (uid++ % UINT_MAX); uint64_t key = (gpu << 56) + (uid++ % UINT_MAX);
@ -59,7 +59,7 @@ extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hash
* Get the computed average speed * Get the computed average speed
* @param thr_id int (-1 for all threads) * @param thr_id int (-1 for all threads)
*/ */
extern "C" double stats_get_speed(int thr_id, double def_speed) double stats_get_speed(int thr_id, double def_speed)
{ {
uint64_t gpu = device_map[thr_id]; uint64_t gpu = device_map[thr_id];
uint64_t keypfx = (gpu << 56); uint64_t keypfx = (gpu << 56);
@ -91,7 +91,7 @@ extern "C" double stats_get_speed(int thr_id, double def_speed)
return speed; return speed;
} }
extern "C" int stats_get_history(int thr_id, struct stats_data *data, int max_records) int stats_get_history(int thr_id, struct stats_data *data, int max_records)
{ {
uint64_t gpu = device_map[thr_id]; uint64_t gpu = device_map[thr_id];
uint64_t keypfx = (gpu << 56); uint64_t keypfx = (gpu << 56);
@ -114,7 +114,7 @@ extern "C" int stats_get_history(int thr_id, struct stats_data *data, int max_re
/** /**
* Remove old entries to reduce memory usage * Remove old entries to reduce memory usage
*/ */
extern "C" void stats_purge_old(void) void stats_purge_old(void)
{ {
int deleted = 0; int deleted = 0;
uint32_t now = (uint32_t) time(NULL); uint32_t now = (uint32_t) time(NULL);
@ -135,8 +135,16 @@ extern "C" void stats_purge_old(void)
/** /**
* Reset the cache * Reset the cache
*/ */
extern "C" void stats_purge_all(void) void stats_purge_all(void)
{ {
tlastscans.clear(); tlastscans.clear();
} }
/**
* API meminfo
*/
void stats_getmeminfo(uint64_t *mem, uint32_t *records)
{
(*records) = tlastscans.size();
(*mem) = (*records) * sizeof(stats_data);
}

Loading…
Cancel
Save