/* A program to put stress on a POSIX system (stress).
*
* Copyright (C) 2001,2002,2003,2004,2005,2006,2007
* Amos Waterland <apw@rossby.metr.ou.edu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/wait.h>
/* By default, print all messages of severity info and above. */
static int global_debug = 2;
/* Name of this program */
static char *global_progname = PACKAGE;
/* Implemention of runtime-selectable severity message printing. */
#define dbg if (global_debug >= 3) \
fprintf (stdout, "%s: dbug: [%lli] ", \
global_progname, (long long)getpid()), fprintf
#define out if (global_debug >= 2) \
fprintf (stdout, "%s: info: [%lli] ", \
global_progname, (long long)getpid()), fprintf
#define wrn if (global_debug >= 1) \
fprintf (stderr, "%s: WARN: [%lli] (%d) ", \
global_progname, (long long)getpid(), __LINE__), fprintf
#define err if (global_debug >= 0) \
fprintf (stderr, "%s: FAIL: [%lli] (%d) ", \
global_progname, (long long)getpid(), __LINE__), fprintf
/* Implementation of check for option argument correctness. */
#define assert_arg(A) \
if (++i == argc || ((arg = argv[i])[0] == '-' && \
!isdigit ((int)arg[1]) )) \
{ \
err (stderr, "missing argument to option '%s'\n", A); \
exit (1); \
}
/* Prototypes for utility functions. */
int usage (int status);
int version (int status);
long long atoll_s (const char *nptr);
long long atoll_b (const char *nptr);
/* Prototypes for worker functions. */
int hogcpu (void);
int hogio (void);
int hogvm (long long bytes, long long stride, long long hang, int keep);
int hoghdd (long long bytes, int clean);
int
main (int argc, char **argv)
{
int i, pid, children = 0, retval = 0;
long starttime, stoptime, runtime, forks;
/* Variables that indicate which options have been selected. */
int do_dryrun = 0;
long long do_backoff = 3000;
long long do_timeout = 0;
long long do_cpu = 0;
long long do_io = 0;
long long do_vm = 0;
long long do_vm_bytes = 256 * 1024 * 1024;
long long do_vm_stride = 4096;
long long do_vm_hang = -1;
int do_vm_keep = 0;
long long do_hdd = 0;
int do_hdd_clean = 2;
long long do_hdd_bytes = 1024 * 1024 * 1024;
/* Record our start time. */
if ((starttime = time (NULL)) == -1)
{
err (stderr, "failed to acquire current time: %s\n", strerror (errno));
exit (1);
}
/* SuSv3 does not define any error conditions for this function. */
global_progname = basename (argv[0]);
/* For portability, parse command line options without getopt_long. */
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
if (strcmp (arg, "--help") == 0 || strcmp (arg, "-?") == 0)
{
usage (0);
}
else if (strcmp (arg, "--version") == 0)
{
version (0);
}
else if (strcmp (arg, "--verbose") == 0 || strcmp (arg, "-v") == 0)
{
global_debug = 3;
}
else if (strcmp (arg, "--quiet") == 0 || strcmp (arg, "-q") == 0)
{
global_debug = 0;
}
else if (strcmp (arg, "--dry-run") == 0 || strcmp (arg, "-n") == 0)
{
do_dryrun = 1;
}
else if (strcmp (arg, "--backoff") == 0)
{
assert_arg ("--backoff");
if (sscanf (arg, "%lli", &do_backoff) != 1)
{
err (stderr, "invalid number: %s\n", arg);
exit (1);
}
if (do_backoff < 0)
{
err (stderr, "invalid backoff factor: %lli\n", do_backoff);
exit (1);
}
dbg (stdout, "setting backoff coeffient to %llius\n", do_backoff);
}
else if (strcmp (arg, "--timeout") == 0 || strcmp (arg, "-t") == 0)
{
assert_arg ("--timeout");
do_timeout = atoll_s (arg);
if (do_timeout <= 0)
{
err (stderr, "invalid timeout value: %llis\n", do_timeout);
exit (1);
}
}
else if (strcmp (arg, "--cpu") == 0 || strcmp (arg, "-c") == 0)
{
assert_arg ("--cpu");
do_cpu = atoll_b (arg);
if (do_cpu <= 0)
{
err (stderr, "invalid number of cpu hogs: %lli\n", do_cpu);
exit (1);
}
}
else if (strcmp (arg, "--io") == 0 || strcmp (arg, "-i") == 0)
{
assert_arg ("--io");
do_io = atoll_b (arg);
if (do_io <= 0)
{
err (stderr, "invalid number of io hogs: %lli\n", do_io);
exit (1);
}
}
else if (strcmp (arg, "--vm") == 0 || strcmp (arg, "-m") == 0)
{
assert_arg ("--vm");
do_vm = atoll_b (arg);
if (do_vm <= 0)
{
err (stderr, "invalid number of vm hogs: %lli\n", do_vm);
exit (1);
}
}
else if (strcmp (arg, "--vm-bytes") == 0)
{
assert_arg ("--vm-bytes");
do_vm_bytes = atoll_b (arg);
if (do_vm_bytes <= 0)
{
err (stderr, "invalid vm byte value: %lli\n", do_vm_bytes);
exit (1);
}
}
else if (strcmp (arg, "--vm-stride") == 0)
{
assert_arg ("--vm-stride");
do_vm_stride = atoll_b (arg);
if (do_vm_stride <= 0)
{
err (stderr, "invalid stride value: %lli\n", do_vm_stride);
exit (1);
}
}
else if (strcmp (arg, "--vm-hang") == 0)
{
assert_arg ("--vm-hang");
do_vm_hang = atoll_b (arg);
if (do_vm_hang < 0)
{
err (stderr, "invalid value: %lli\n", do_vm_hang);
exit (1);
}
}
else if (strcmp (arg, "--vm-keep") == 0)
{
do_vm_keep = 1;
}
else if (strcmp (arg, "--hdd") == 0 || strcmp (arg, "-d") == 0)
{
assert_arg ("--hdd");
do_hdd = atoll_b (arg);
if (do_hdd <= 0)
{
err (stderr, "invalid number of hdd hogs: %lli\n", do_hdd);
exit (1);
}
}
else if (strcmp (arg, "--hdd-noclean") == 0)
{
do_hdd_clean = 0;
}
else if (strcmp (arg, "--hdd-bytes") == 0)
{
assert_arg ("--hdd-bytes");
do_hdd_bytes = atoll_b (arg);
if (do_hdd_bytes <= 0)
{
err (stderr, "invalid hdd byte value: %lli\n", do_hdd_bytes);
exit (1);
}
}
else
{
err (stderr, "unrecognized option: %s\n", arg);
exit (1);
}
}
/* Print startup message if we have work to do, bail otherwise. */
if (do_cpu + do_io + do_vm + do_hdd)
{
out (stdout, "dispatching hogs: %lli cpu, %lli io, %lli vm, %lli hdd\n",
do_cpu, do_io, do_vm, do_hdd)
没有合适的资源?快使用搜索试试~ 我知道了~
linux压力测试工具stress
5星 · 超过95%的资源 需积分: 44 373 下载量 43 浏览量
2013-03-30
21:02:14
上传
评论 8
收藏 199KB GZ 举报
温馨提示
共32个文件
in:5个
am:4个
texi:2个
linux压力测试工具源码包,适用于嵌入式系统linux系统压力测试和稳定性测试
资源推荐
资源详情
资源评论
收起资源包目录
stress_1.0.1.orig.tar.gz (32个子文件)
stress-1.0.1
test
Makefile.am 116B
Makefile.in 11KB
check_usage_return_code 91B
check_version_return_code 111B
depcomp 17KB
aclocal.m4 32KB
TODO 2KB
Makefile.am 367B
configure.in 967B
src
Makefile.am 177B
Makefile.in 12KB
stress.c 21KB
README 922B
Makefile.in 18KB
INSTALL 8KB
missing 11KB
install-sh 13KB
AUTHORS 395B
doc
stress.texi 5KB
mdate-sh 5KB
stress.info 5KB
Makefile.am 318B
texinfo.tex 284KB
Makefile.in 19KB
stress.html 10KB
version.texi 94B
stress.1 2KB
stamp-vti 94B
configure 151KB
NEWS 3KB
ChangeLog 13KB
COPYING 34KB
共 32 条
- 1
nansn
- 粉丝: 5
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页