首页 > 其他 > 详细

DPDK latencystats库使用方案

时间:2019-07-23 15:48:37      阅读:285      评论:0      收藏:0      [点我收藏+]

 

初始化

注意务必调用 

rte_metrics_init
    /* init latency stats */
    /* @TODO should we remove this in product env? */
    rte_metrics_init(numa);
    if (rte_latencystats_init(1, NULL)) {
	printf("Could not allocate latency data,\n");
    }

 

update

 

/* 这个函数周期调用,比如1s调用一次,会更新latency数据并打印出之前的统计值 */   

static void print_latency(void) { struct rte_metric_value * metrics; struct rte_metric_value * metrics; struct rte_metric_name * names; int len ; int ret; int i,j; len = 4; /* rte_metrics_get_names(NULL, 0); // 这里仅仅用来获取个数,为后续申请内存使用,若已固定知道则可以忽略。 if (len <= 0) { printf("Get metrics count: %d error\n", len); return; }*/ metrics = malloc(sizeof(struct rte_metric_value) * len); names = malloc(sizeof(struct rte_metric_name) * len); if (metrics == NULL || names == NULL) { printf("Cannot allocate memory\n"); free(metrics); free(names); return; } len = rte_metrics_get_names(names,len); if (len <= 0) { printf("Get metrics name: %d error\n", len); return; } for(j = 0; j < 2; j++) { ret = rte_metrics_get_values(j, metrics, len); if (ret < 0 || ret > len) { printf("Cannot get metrics values\n"); free(metrics); free(names); return; } PAL_LOG("Metrics for port %d:\n", j); for (i = 0; i < len; i++) printf(" %s: %"PRIu64"\n",names[metrics[i].key].name, metrics[i].value); } free(metrics); free(names); rte_latencystats_update(); }

  

DPDK latencystats库使用方案

原文:https://www.cnblogs.com/lovemyspring/p/11232134.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!