本文共 2191 字,大约阅读时间需要 7 分钟。
在ceph 源码ceph-master\ceph-master\src\test\CMakeLists.txt 中定义了一个ceph_perf_local的可执行文件,用于测试不同平台对ceph性能的影响#ceph_perf_localadd_executable(ceph_perf_local perf_local.cc perf_helper.cc)if(HAVE_SSE) set(PERF_LOCAL_FLAGS ${SSE3_FLAGS})endif(HAVE_SSE)if(HAVE_NEON) set(PERF_LOCAL_FLAGS ${ARM_NEON_FLAGS})endif(HAVE_NEON)if(PERF_LOCAL_FLAGS) set_target_properties(ceph_perf_local PROPERTIES COMPILE_FLAGS ${PERF_LOCAL_FLAGS})endif()target_link_libraries(ceph_perf_local os global ${UNITTEST_LIBS})从makefile中可以看出ceph_perf_local的源文件有两个,分别是perf_local.cc/perf_helper.cc.其编译好的执行bin的name为ceph_perf_local,从makefile中同样可以看出可以使用x86的sse或者arm的neon 指令来加速这个tool的入口函数如下:int main(int argc, char *argv[]){ vectorargs; argv_to_vec(argc, (const char **)argv, args); auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); common_init_finish(g_ceph_context); Cycles::init(); bind_thread_to_cpu(3); #测试命令可以带一个参数,如果不带参数的话,则测试所有的item项 if (argc == 1) { // No test names specified; run all tests. for (size_t i = 0; i < sizeof(tests)/sizeof(TestInfo); ++i) { run_test(tests[i]); } } else { // Run only the tests that were specified on the command line. for (int i = 1; i < argc; i++) { bool found_test = false; for (size_t j = 0; j < sizeof(tests)/sizeof(TestInfo); ++j) { if (strcmp(argv[i], tests[j].name) == 0) { found_test = true; run_test(tests[j]); break; } } if (!found_test) { int width = printf("%-24s ??", argv[i]); printf("%*s No such test\n", 32-width, ""); } } }}从main函数中可以看出测试的item项在tests 这个数组中TestInfo tests[] = { {"atomic_int_cmp", atomic_int_cmp, "atomic_t::compare_and_swap"}, {"atomic_int_inc", atomic_int_inc, "atomic_t::inc"},}}这里以atomic_int_inc的测试为例double atomic_int_inc(){ int count = 1000000; #定义一个原子变量 std::atomic value = { 11 }; #对原子变量操作前获取时间 uint64_t start = Cycles::rdtsc(); #对这个原子变量自加1000000 for (int i = 0; i < count; i++) { value++; } #原子变量自加完成后,读取时间 uint64_t stop = Cycles::rdtsc(); // printf("Final value: %d\n", value.load()); #计算本次原子变量自加占用的时间 return Cycles::to_seconds(stop - start)/count;}
转载地址:http://pjnmi.baihongyu.com/