future-promise增加对失败的统计。
This commit is contained in:
@@ -22,7 +22,9 @@ struct future_promise_instance
|
||||
|
||||
struct _future_promise_debug
|
||||
{
|
||||
int field_id;
|
||||
int fsid_latency;
|
||||
int fsid_failed;
|
||||
long long succ_times;
|
||||
struct timespec create_time;
|
||||
};
|
||||
struct future
|
||||
@@ -40,7 +42,7 @@ struct promise
|
||||
void * ctx;
|
||||
int has_timeout;
|
||||
promise_ctx_destroy_cb * cb_ctx_destroy;
|
||||
struct _future_promise_debug __debug;
|
||||
struct _future_promise_debug debug;
|
||||
};
|
||||
static struct future_promise_instance g_FP_instance;
|
||||
static int g_is_FP_init=0;
|
||||
@@ -95,23 +97,33 @@ struct field_get_set_args
|
||||
{
|
||||
MESA_htable_handle htable;
|
||||
screen_stat_handle_t fs_handle;
|
||||
int fsid_latency;
|
||||
int fsid_failed;
|
||||
};
|
||||
static long field_get_set_cb(void * data, const uchar * key, uint size, void * user_arg)
|
||||
{
|
||||
struct field_get_set_args* args=(struct field_get_set_args*)user_arg;
|
||||
int *field_id=NULL, ret=0;
|
||||
const char* fail_str="_fail";
|
||||
char buff[size+strlen(fail_str)+1];
|
||||
if(data==NULL)
|
||||
{
|
||||
field_id=(int*)malloc(sizeof(int));
|
||||
*field_id=FS_register(args->fs_handle, FS_STYLE_HISTOGRAM, FS_CALC_SPEED, (const char * )key);
|
||||
field_id=(int*)malloc(sizeof(int)*2);
|
||||
field_id[0]=FS_register(args->fs_handle, FS_STYLE_HISTOGRAM, FS_CALC_SPEED, (const char * )key);
|
||||
args->fsid_failed=field_id[0];
|
||||
snprintf(buff,sizeof(buff),"%s%s",(char*)key,fail_str);
|
||||
field_id[1]=FS_register(args->fs_handle, FS_STYLE_FIELD, FS_CALC_SPEED,buff);
|
||||
args->fsid_latency=field_id[1];
|
||||
ret = MESA_htable_add(args->htable, key, size, (void*)field_id);
|
||||
assert(ret==0);
|
||||
assert(ret==0);
|
||||
}
|
||||
else
|
||||
{
|
||||
field_id=(int*)data;
|
||||
args->fsid_failed=field_id[0];
|
||||
args->fsid_latency=field_id[1];
|
||||
}
|
||||
return *field_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
|
||||
@@ -122,12 +134,13 @@ struct future * future_create(const char* symbol, future_success_cb * cb_success
|
||||
p->f.cb_failed = cb_failed;
|
||||
strncpy(p->f.symbol,symbol,sizeof(p->f.symbol));
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC,&p->__debug.create_time);
|
||||
clock_gettime(CLOCK_MONOTONIC,&p->debug.create_time);
|
||||
void * no_use = NULL;
|
||||
long cb_ret=0;
|
||||
struct field_get_set_args args{.htable = g_FP_instance.name_table, .fs_handle = g_FP_instance.fs_handle};
|
||||
no_use=MESA_htable_search_cb(g_FP_instance.name_table, (const unsigned char*)symbol, strlen(symbol), field_get_set_cb, &args, &cb_ret);
|
||||
p->__debug.field_id=(int)cb_ret;
|
||||
p->debug.fsid_latency=args.fsid_latency;
|
||||
p->debug.fsid_failed=args.fsid_failed;
|
||||
FS_operate(g_FP_instance.fs_handle,g_FP_instance.fsid_f_num, 0, FS_OP_ADD, 1);
|
||||
return &p->f;
|
||||
}
|
||||
@@ -145,15 +158,30 @@ void future_destroy(struct future * f)
|
||||
{
|
||||
p->cb_ctx_destroy(p);
|
||||
}
|
||||
struct timespec end;
|
||||
clock_gettime(CLOCK_MONOTONIC,&end);
|
||||
long long jiffies=(end.tv_sec-p->__debug.create_time.tv_sec)*1000000000+end.tv_nsec-p->__debug.create_time.tv_nsec;
|
||||
FS_operate(g_FP_instance.fs_handle, p->__debug.field_id, 0, FS_OP_SET, jiffies);
|
||||
FS_operate(g_FP_instance.fs_handle,g_FP_instance.fsid_f_num, 0, FS_OP_SUB, 1);
|
||||
memset(p, 0, sizeof(struct promise));
|
||||
free(p);
|
||||
}
|
||||
|
||||
static void fp_stat_latency(struct _future_promise_debug* debug, int is_success)
|
||||
{
|
||||
struct timespec end;
|
||||
long long jiffies=0;
|
||||
clock_gettime(CLOCK_MONOTONIC,&end);
|
||||
if(is_success==1)
|
||||
{
|
||||
debug->succ_times++;
|
||||
}
|
||||
else
|
||||
{
|
||||
FS_operate(g_FP_instance.fs_handle, debug->fsid_failed, 0, FS_OP_ADD, 1);
|
||||
}
|
||||
if(debug->succ_times<=1)
|
||||
{
|
||||
jiffies=(end.tv_sec-debug->create_time.tv_sec)*1000000000+end.tv_nsec-debug->create_time.tv_nsec;
|
||||
FS_operate(g_FP_instance.fs_handle, debug->fsid_latency, 0, FS_OP_SET, jiffies);
|
||||
}
|
||||
return;
|
||||
}
|
||||
void promise_failed(struct promise * p, enum e_future_error error, const char * what)
|
||||
{
|
||||
p->f.cb_failed(error, what, p->f.user);
|
||||
|
||||
Reference in New Issue
Block a user