• DPDK latencystats库使用方案


    初始化

    注意务必调用 

    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,
    ");
        }
    

    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 ", 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 "); free(metrics); free(names); return; } len = rte_metrics_get_names(names,len); if (len <= 0) { printf("Get metrics name: %d error ", 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 "); free(metrics); free(names); return; } PAL_LOG("Metrics for port %d: ", j); for (i = 0; i < len; i++) printf(" %s: %"PRIu64" ",names[metrics[i].key].name, metrics[i].value); } free(metrics); free(names); rte_latencystats_update(); }

      

  • 相关阅读:
    Centos7安装Python3的方法
    word2vec原理(二) 基于Hierarchical Softmax的模型
    word2vec原理(一) CBOW与Skip-Gram模型基础
    爬虫的危害有多大
    python线程池实现
    进程和线程、协程的区别
    程序的编译与解释之间的区别
    【python3】如何建立爬虫代理ip池
    可能是史上最全的机器学习和Python(包括数学)速查表
    python 元类
  • 原文地址:https://www.cnblogs.com/lovemyspring/p/11232134.html
Copyright © 2020-2023  润新知