future性能监控编译通过。

This commit is contained in:
zhengchao
2018-09-03 21:04:37 +08:00
parent 60ab97d8e3
commit cba6d6f56c

View File

@@ -2,10 +2,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <assert.h>
#include <tfe_future.h> #include <tfe_future.h>
#include <tfe_utils.h> #include <tfe_utils.h>
#include <field_stat2.h> #include <MESA/MESA_htable.h>
#include <MESA/field_stat2.h>
const char* FP_HISTOGRAM_BINS="10,50,100,500"; const char* FP_HISTOGRAM_BINS="10,50,100,500";
@@ -47,19 +50,24 @@ void future_promise_library_init(void)
{ {
return; return;
} }
int value=0;
memset(&g_FP_instance,0,sizeof(g_FP_instance)); memset(&g_FP_instance,0,sizeof(g_FP_instance));
MESA_htable_handle htable = MESA_htable_born(); MESA_htable_handle htable = MESA_htable_born();
MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL, 0); value=0;
MESA_htable_set_opt(htable, MHO_THREAD_SAFE, 1); MESA_htable_set_opt(htable, MHO_SCREEN_PRINT_CTRL,&value,sizeof(value));
MESA_htable_set_opt(htable, MHO_MUTEX_NUM, 16); value=1;
MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, 1024); MESA_htable_set_opt(htable, MHO_THREAD_SAFE, &value,sizeof(value));;
value=16;
MESA_htable_set_opt(htable, MHO_MUTEX_NUM, &value,sizeof(value));;
value=1024;
MESA_htable_set_opt(htable, MHO_HASH_SLOT_SIZE, &value,sizeof(value));;
MESA_htable_mature(htable); MESA_htable_mature(htable);
g_FP_instance.name_table=htable; g_FP_instance.name_table=htable;
screen_stat_handle_t fs=NULL; screen_stat_handle_t fs=NULL;
const char* stat_path="./future.status"; const char* stat_path="./future.status";
const char* app_name="FP"; const char* app_name="FP";
int value=0;
fs=FS_create_handle(); fs=FS_create_handle();
FS_set_para(fs, APP_NAME, app_name, strlen(app_name)+1); FS_set_para(fs, APP_NAME, app_name, strlen(app_name)+1);
value=0; value=0;
@@ -91,18 +99,19 @@ struct field_get_set_args
static long field_get_set_cb(void * data, const uchar * key, uint size, void * user_arg) 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; struct field_get_set_args* args=(struct field_get_set_args*)user_arg;
int field_id=0, ret=0; int *field_id=NULL, ret=0;
if(data==NULL) if(data==NULL)
{ {
field_id=FS_register(args->fs_handle, FS_STYLE_HISTOGRAM, FS_CALC_SPEED, (const char * )key); field_id=(int*)malloc(sizeof(int));
*field_id=FS_register(args->fs_handle, FS_STYLE_HISTOGRAM, FS_CALC_SPEED, (const char * )key);
ret = MESA_htable_add(args->htable, key, size, (void*)field_id); ret = MESA_htable_add(args->htable, key, size, (void*)field_id);
assert(ret==0); assert(ret==0);
} }
else else
{ {
field_id=(int)data; field_id=(int*)data;
} }
return field_id; return *field_id;
} }
struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user) struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
@@ -117,8 +126,8 @@ struct future * future_create(const char* symbol, future_success_cb * cb_success
void * no_use = NULL; void * no_use = NULL;
long cb_ret=0; long cb_ret=0;
struct field_get_set_args args{.htable = g_FP_instance.name_table, .fs_handle = g_FP_instance.fs_handle}; 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, symbol, strlen(symbol), field_get_set_cb, &args, &cb_ret); 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.field_id=(int)cb_ret;
FS_operate(g_FP_instance.fs_handle,g_FP_instance.fsid_f_num, 0, FS_OP_ADD, 1); FS_operate(g_FP_instance.fs_handle,g_FP_instance.fsid_f_num, 0, FS_OP_ADD, 1);
return &p->f; return &p->f;
} }
@@ -138,10 +147,10 @@ void future_destroy(struct future * f)
} }
struct timespec end; struct timespec end;
clock_gettime(CLOCK_MONOTONIC,&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; 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, 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); FS_operate(g_FP_instance.fs_handle,g_FP_instance.fsid_f_num, 0, FS_OP_SUB, 1);
memset(p, 0, sizeof(struct p)); memset(p, 0, sizeof(struct promise));
free(p); free(p);
} }