linux下内存测试mbw,内存测试工具mbw分析
/*mbw.c源码格函数解析*/
/*allocate a test array and fill it with data * so as to force Linux to _really_ allocate it*/
long *make_array(unsigned long longasize)
{
unsignedlong longt;
unsignedint long_size=sizeof(long);long *a;//calloc是一个ISO C函数函数名: calloc函数原型:void *calloc(size_t n, size_t size);功 能: 在内存的动态存储区中分配n个长度为size的连续空间,函数返回一个指向分配起始地址的指针;如果分配不成功,返回NULL。
a=calloc(asize, long_size);if(NULL==a) {
perror("Error allocating memory");
exit(1);
}/*make sure both arrays are allocated, fill with pattern*/
for(t=0; t
a[t]=0xaa;
}returna;
}=============================
/*actual benchmark*/
/*asize: number of type ‘long‘ elements in test arrays //测试数组中long型元素个数
* long_size: sizeof(long) cached //long型内存大小,即占几个字节
* type: 0=use memcpy, 1=use dumb copy loop (whatever GCC thinks best)
*
* return value: elapsed time in seconds*/
double worker(unsigned long long asize, long *a, long *b, int type, unsigned long longblock_size)
{
unsignedlong longt;struct timeval starttime, endtime; //timeval结构体定义在time.h中,具体解析http://blog.csdn.net/yusiguyuan/article/details/21781839
doublete;
unsignedint long_size=sizeof(long);/*array size in bytes*/unsignedlong long array_bytes=asize*long_size;if(type==1) { /*memcpy test*/
/*timer starts*/gettimeofday(&starttime, NULL);//记录开始时间
memcpy(b, a, array_bytes);//拷贝array_bytes大小 内存
/*timer stops*/gettimeofday(&endtime, NULL);//记录结束时间
} else if(type==2) { /*memcpy block test*/gettimeofday(&starttime, NULL);for(t=0; t
b=mempcpy(b, a, block_size);//void *memccpy(void *dest, const void *src, int c, size_t n);在两块不重叠的内存地址间复制内容,直至复制了n字节或遇到内容为c的字节
}if(t>array_bytes) {
b=mempcpy(b, a, t-array_bytes);
}
gettimeofday(&endtime, NULL);
}else { /*dumb test*/ // gettimeofday(&starttime, NULL);for(t=0; t
b[t]=a[t];
}
gettimeofday(&endtime, NULL);
}
te=((double)(endtime.tv_sec*1000000-starttime.tv_sec*1000000+endtime.tv_usec-starttime.tv_usec))/1000000;returnte;
}/*------------------------------------------------------*/
/*pretty print worker‘s output in human-readable terms*/
/*te: elapsed time in seconds
* mt: amount of transferred data in MiB
* type: see ‘worker‘ above
*
* return value: -*/
void printout(double te, double mt, inttype)
{switch(type) {case 0:
printf("Method: MEMCPY\t");break;case 1:
printf("Method: DUMB\t");break;case 2:
printf("Method: MCBLOCK\t");break;
}
printf("Elapsed: %.5f\t", te);
printf("MiB: %.5f\t", mt);
printf("Copy: %.3f MiB/s\n", mt/te);return;
}/*------------------------------------------------------*/
int main(int argc, char **argv)
{
unsignedint long_size=0;double te, te_sum; /*time elapsed*/unsignedlong long asize=0; /*array size (elements in array)*/
inti;long *a, *b; /*the two arrays to be copied from/to*/
int o; /*getopt options*/unsignedlongtestno;/*options*/
/*how many runs to average?*/
int nr_loops=DEFAULT_NR_LOOPS;/*fixed memcpy block size for -t2*/unsignedlong long block_size=DEFAULT_BLOCK_SIZE;/*show average, -a*/
int showavg=1;/*what tests to run (-t x)*/
inttests[MAX_TESTS];double mt=0; /*MiBytes transferred == array size in MiB*/
int quiet=0; /*suppress extra messages*/tests[0]=0;
tests[1]=0;
tests[2]=0;while((o=getopt(argc, argv, "haqn:t:b:")) !=EOF) {switch(o) {case ‘h‘:
usage();
exit(1);break;case ‘a‘: /*suppress printing average*/showavg=0;break;case ‘n‘: /*no. loops*/nr_loops=strtoul(optarg, (char **)NULL, 10);break;case ‘t‘: /*test to run*/testno=strtoul(optarg, (char **)NULL, 10);if(0>testno) {
printf("Error: test number must be between 0 and %d\n", MAX_TESTS);
exit(1);
}
tests[testno]=1;break;case ‘b‘: /*block size in bytes*/block_size=strtoull(optarg, (char **)NULL, 10);if(0>=block_size) {
printf("Error: what block size do you mean?\n");
exit(1);
}break;case ‘q‘: /*quiet*/quiet=1;break;default:break;
}
}/*default is to run all tests if no specific tests were requested*/
if( (tests[0]+tests[1]+tests[2]) == 0) {
tests[0]=1;
tests[1]=1;
tests[2]=1;
}if(optind
mt=strtoul(argv[optind++], (char **)NULL, 10);
}else{
printf("Error: no array size given!\n");
exit(1);
}if(0>=mt) {
printf("Error: array size wrong!\n");
exit(1);
}/*------------------------------------------------------*/long_size=sizeof(long); /*the size of long on this platform*/asize=1024*1024/long_size*mt; /*how many longs then in one array?*/
if(asize*long_size
printf("Error: array size larger than block size (%llu bytes)!\n", block_size);
exit(1);
}if(!quiet) {
printf("Long uses %d bytes.", long_size);
printf("Allocating 2*%lld elements = %lld bytes of memory.\n", asize, 2*asize*long_size);if(tests[2]) {
printf("Using %lld bytes as blocks for memcpy block copy test.\n", block_size);
}
}
a=make_array(asize);
b=make_array(asize);/*------------------------------------------------------*/
if(!quiet) {
printf("Getting down to business... Doing %d runs per test.\n", nr_loops);
}/*run all tests requested, the proper number of times*/
for(testno=0; testno
te_sum=0;if(tests[testno]) {for (i=0; i
te=worker(asize, a, b, testno, block_size);
te_sum+=te;
printf("%d\t", i);
printout(te, mt, testno);
}if(showavg) {
printf("AVG\t");
printout(te_sum/nr_loops, mt, testno);
}
}
}free(a);free(b);return 0;
}
linux下内存测试mbw,内存测试工具mbw分析相关推荐
- linux下的CPU、内存、IO、网络的压力测试
linux下的CPU.内存.IO.网络的压力测试 要远程测试其实很简单了,把结果放到一个微服务里直接在web里查看就可以了,或者同步到其他服务器上 一.对CPU进行简单测试: 1.通过bc命令计算特别 ...
- Linux 下几款程序内存泄漏检查工具
Linux 下几款程序内存泄漏检查工具 chenyoubing | 发布于 2016-07-23 10:08:09 | 阅读量 93 | 无 写这篇博客的原因呢是因为自己在编写基于Nginx磁盘缓存管 ...
- linux 看内存和硬盘型号,Linux下查看CPU、内存和硬盘型号及相关信息命令
Linux下查看CPU.内存和硬盘信息命令 在Linux的桌面版本中,查看这些东西的确很方便,有图形化的工具可使用.可是在Linux服务器版上,或者远程ssh链接的时候,就没有图形化的界面能够操做了. ...
- linux下jmap 内存命令,Linux下jmap命令查看内存使用
Linux下jmap命令查看内存使用 jmap -heap 1234 (1234为进程号) jmap是JDK自带的一个工具,非常小巧方便,其支持参数如下: -heap 打印heap空间的概要,这里可以 ...
- linux下几种文件系统的测试比较
在linux下对部分文件系统进行测试 一. 我的实验平台 我使用的是vmware workstation7.1.4.16648 虚拟机 安装的操作系统信息 [root@node2 ~]# uname ...
- Linux下实用的查看内存和多核CPU状态命令
Linux下实用的查看内存和多核CPU状态命令 ]作者:zale0_0 来源:博客园 发布时间:2012-02-08 14:49 阅读:12 次 原文链接 [收藏] 查看多核CPU命令 mpstat ...
- linux文件系统选哪种,linux下几种文件系统的测试比较
在linux下对部分文件系统进行测试 一. 我的实验平台 我使用的是vmware workstation7.1.4.16648虚拟机 安装的操作系统信息 [root@node2 ~]# uname - ...
- linux下对进程按照内存使用情况进行排序
linux下对进程按照内存使用情况进行排序的命令为:ps aux --sort -rss 详细解说参见 http://alvinalexander.com/linux/unix-linux-proce ...
- linux系统2g内存,linux下分配大于2g内存的问题(c++)
linux下分配大于2g内存的问题(c++) 答案:5 信息版本:手机版 解决时间 2020-07-26 16:35 已解决 2020-07-25 20:51 机器是64位系统linux,但好像最大 ...
- linux c语言工具,Linux下C语言编程环境的工具.doc
Linux下C语言编程环境的工具 Linux下C语言编程环境的工具 Linux下C语言编程环境的工具 要想在Linux下进行C语言编程,首先得搭建好一个编程环境.这里分别说明一下几个非常有用的软件包. ...
最新文章
- python鸢尾花数据集聚类_R语言鸢尾花iris数据集的层次聚类分析
- vue的diff 算法
- 属性页中的ON_UPDATE_COMMAND_UI
- Java写文件导致io过高_161108、Java IO流读写文件的几个注意点
- UML建模:学习笔记(1)
- ibm服务器修改ide,IBM刀片服务器配置IDE RAID的方法
- 项目管理十大知识领域之项目风险管理
- 东西向流量/南北向流量
- input标签的type属性汇总
- SM74HC595D电路级联教程
- html和js制作个人所得税表格,H5编写个税计算器(JS代码编写).doc
- rstp 小米网络摄像头_小米哪个家庭摄像头好用?
- 计算机专业装win几,低配电脑装win10还是win7系统比较合适
- 261、Java基础38 - 接口与继承【对象转型】 2019.11.18
- MySQL的地理位置类型
- Qualcomm 音频学习(Bring up)
- 使用MSHTML解析HTML代码
- html圆角边框背景颜色,CSS之圆角边框渐变的实现
- 房价必然增长的十个原因
- java寂静岭 攻略,《寂静岭5》完全图文攻略
热门文章
- 计算机维修与维护笔记,笔记本电脑维护选购知识大全
- Android吃透inflate方法(二)
- 电脑无法进入bios
- Pseudo-Q: Generating Pseudo Language Queries for Visual Grounding, 2022 CVPR
- python 切片器_excel和python中的切片器列表
- echarts年龄饼图_ECharts中饼图的操作
- oracle bpm 集成erp,我们已经执行了ERP系统,为什么还要使用BPM系统?
- 正在开启,一名金融猎头的二十年 | 专访伯乐百万金融顾问 Leslie Xu
- 鼠标双击DataGridView单元格变成ComboBox
- 软考中级软件设计师基础整理(1.计算机组成与体系结构)