You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.2 KiB

7 years ago
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
//
// LP_stats.c
// marketmaker
//
#define LP_STATSLOG_FNAME "stats.log"
void LP_tradecommand_log(cJSON *argjson)
{
static FILE *logfp; char *jsonstr;
if ( logfp == 0 )
{
if ( (logfp= fopen(LP_STATSLOG_FNAME,"rb+")) != 0 )
fseek(logfp,0,SEEK_END);
else logfp = fopen(LP_STATSLOG_FNAME,"wb");
}
if ( logfp != 0 )
{
jsonstr = jprint(argjson,0);
fprintf(logfp,"%s\n",jsonstr);
free(jsonstr);
fflush(logfp);
}
}
7 years ago
uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_numridqids;
7 years ago
uint64_t Ridqids[128];
7 years ago
7 years ago
int32_t LP_statslog_parsequote(char *method,cJSON *lineobj)
7 years ago
{
int32_t i,duplicate=0; struct LP_quoteinfo Q; uint64_t ridqid;
memset(&Q,0,sizeof(Q));
if ( LP_quoteparse(&Q,lineobj) < 0 )
{
printf("quoteparse_error.(%s)\n",jprint(lineobj,0));
LP_parse_errors++;
}
else
{
7 years ago
ridqid = (((uint64_t)Q.desttxid.uints[0] << 48) | ((uint64_t)Q.destvout << 32) || ((uint64_t)Q.feetxid.uints[0] << 16) | (uint32_t)Q.feevout);
7 years ago
for (i=0; i<sizeof(Ridqids)/sizeof(*Ridqids); i++)
{
if ( Ridqids[i] == ridqid )
{
duplicate = 1;
LP_duplicates++;
break;
}
}
if ( duplicate == 0 )
{
Ridqids[LP_numridqids % (sizeof(Ridqids)/sizeof(*Ridqids))] = ridqid;
LP_numridqids++;
7 years ago
char str[65]; printf("%10s ridqid.%-16llx -> %d %s/v%d\n",method,(long long)ridqid,(int32_t)(LP_numridqids % (sizeof(Ridqids)/sizeof(*Ridqids))),bits256_str(str,jbits256(lineobj,"desttxid")),jint(lineobj,"destvout"));
7 years ago
}
}
return(duplicate == 0);
}
7 years ago
void LP_statslog_parseline(cJSON *lineobj)
{
7 years ago
char *method;
7 years ago
if ( (method= jstr(lineobj,"method")) != 0 )
{
if ( strcmp(method,"request") == 0 )
LP_requests++;
7 years ago
else if ( strcmp(method,"reserved") == 0 )
LP_reserveds++;
7 years ago
else if ( strcmp(method,"connect") == 0 )
7 years ago
{
7 years ago
LP_statslog_parsequote(method,lineobj);
7 years ago
LP_connects++;
7 years ago
}
7 years ago
else if ( strcmp(method,"connected") == 0 )
7 years ago
{
7 years ago
LP_statslog_parsequote(method,lineobj);
7 years ago
LP_connecteds++;
7 years ago
}
7 years ago
else if ( strcmp(method,"tradestatus") == 0 )
LP_tradestatuses++;
else
{
LP_unknowns++;
7 years ago
printf("parseline unknown method.(%s) (%s)\n",method,jprint(lineobj,0));
7 years ago
}
} else printf("parseline no method.(%s)\n",jprint(lineobj,0));
}
7 years ago
char *LP_statslog_disp(int32_t n)
{
cJSON *retjson;
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"newlines",n);
7 years ago
jaddnum(retjson,"request",LP_requests);
7 years ago
jaddnum(retjson,"reserved",LP_reserveds);
7 years ago
jaddnum(retjson,"connect",LP_connects);
jaddnum(retjson,"connected",LP_connecteds);
7 years ago
jaddnum(retjson,"duplicates",LP_duplicates);
7 years ago
jaddnum(retjson,"parse_errors",LP_parse_errors);
7 years ago
jaddnum(retjson,"uniques",LP_numridqids);
7 years ago
jaddnum(retjson,"tradestatus",LP_tradestatuses);
jaddnum(retjson,"unknown",LP_unknowns);
7 years ago
return(jprint(retjson,1));
}
char *LP_statslog_parse()
{
static long lastpos; FILE *fp; char line[8192]; cJSON *lineobj; int32_t n = 0;
if ( (fp= fopen(LP_STATSLOG_FNAME,"rb")) != 0 )
{
if ( lastpos > 0 )
{
fseek(fp,0,SEEK_END);
if ( ftell(fp) > lastpos )
fseek(fp,lastpos,SEEK_SET);
else
{
fclose(fp);
7 years ago
return(clonestr("{\"result\":\"success\",\"newlines\":0}"));
7 years ago
}
}
while ( fgets(line,sizeof(line),fp) > 0 )
{
lastpos = ftell(fp);
if ( (lineobj= cJSON_Parse(line)) != 0 )
{
n++;
7 years ago
LP_statslog_parseline(lineobj);
//printf("%s\n",jprint(lineobj,0));
7 years ago
free_json(lineobj);
}
}
fclose(fp);
}
return(LP_statslog_disp(n));
}