/* $Id: lb.c 795 2013-04-22 05:12:27Z aqua $
*
* lookbusy -- a tool for producing synthetic CPU, memory consumption and
* disk loads on a host.
*
* Copyright (c) 2006, Devin Carraway <lookbusy@devin.com>.
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/* and, redundantly ... */
static const char *copyright =
"Copyright (c) 2006-2008, by Devin Carraway <lookbusy@devin.com>\n"
"$Id: lb.c 795 2013-04-22 05:12:27Z aqua $\n"
"\n"
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
"";
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define VERSION "1.4"
#define PACKAGE "lookbusy"
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#define _GNU_SOURCE
#include <getopt.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <inttypes.h>
#include <ctype.h>
#include <regex.h>
#include <stdarg.h>
#include <math.h>
#ifndef HAVE_STRTOL
#define strtol(x,e,b) atol(x)
#endif
#ifndef HAVE_STRTOLL
#define strtoll(x,e,b) atol(x)
#endif
#ifdef HAVE_SYSCONF
#define LB_PAGE_SIZE sysconf(_SC_PAGESIZE)
#else
#define LB_PAGE_SIZE 4096
#endif
#ifdef _FILE_OFFSET_BITS
#if _FILE_OFFSET_BITS == 64
#define HAVE_LFS 1
#endif
#else
#define HAVE_LFS (sizeof(off_t) >= 8)
#endif
#define PI 3.14159265358979323846
enum cpu_util_mode {
UTIL_MODE_FIXED = 0,
UTIL_MODE_CURVE
};
enum cpu_util_mode c_cpu_util_mode = UTIL_MODE_FIXED;
static int utc = 0;
static int c_cpu_curve_period = 86400; /* seconds */
static int c_cpu_curve_peak = 60 * 60 * 13; /* 1PM local time */
static int c_cpu_util_l = 50, c_cpu_util_h = 50; /* percent */
static size_t c_mem_util = 0; /* bytes */
static long c_mem_stir_sleep = 1000; /* 1000 usec / 1 ms */
static off_t c_disk_util = 0; /* MB */
static char **c_disk_churn_paths;
static size_t c_disk_churn_paths_n;
static size_t c_disk_churn_block_size = 32 * 1024; /* bytes */
static size_t c_disk_churn_step_size = 4 * 1024; /* bytes */
static long c_disk_churn_sleep = 100; /* ms */
static int ncpus = -1; /* autodetect */
static int verbosity = 1;
static char *mem_stir_buffer;
static pid_t *cpu_pids;
static size_t n_cpu_pids;
static pid_t *disk_pids;
static size_t n_disk_pids;
static pid_t mem_pid;
typedef void (*spinner_fn)(long long, long long, long long, void*, void *);
static int say(int level, const char *fmt, ...)
{
va_list ap;
int r;
if (level > verbosity) return 0;
va_start(ap, fmt);
r = vprintf(fmt, ap);
va_end(ap);
return r;
}
static int err(const char *fmt, ...)
{
va_list ap;
int r;
va_start(ap, fmt);
r = vfprintf(stderr, fmt, ap);
va_end(ap);
return r;
}
static int parse_timespan(const char *str, int *r)
{
regex_t ex;
int e;
static const char *pattern =
"^[[:space:]]*([0-9]+)([dhms]?)[[:space:]]*$";
if ((e = regcomp(&ex,pattern, REG_EXTENDED)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
err("regcomp(%s): %s\n", pattern, errbuf);
return -1;
}
regmatch_t matches[3];
if ((e = regexec(&ex, str, 3, matches, 0)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
if (e != REG_NOMATCH)
err("regexec: Couldn't match '%s' in '%s': %s\n",
pattern, str, errbuf);
return -1;
}
*r = (int)strtol(str + matches[1].rm_so, NULL, 10) *
(matches[2].rm_so == -1 ? 1 :
*(str + matches[2].rm_so) == 'd' ? 86400 :
*(str + matches[2].rm_so) == 'h' ? 3600 :
*(str + matches[2].rm_so) == 'm' ? 60 : 1);
return 0;
}
static int parse_large_size(const char *str, off_t *r)
{
regex_t ex;
int e;
static const char *pattern = HAVE_LFS ?
"^[[:space:]]*([0-9]+)(b|kb?|mb?|gb?|tb?)?[[:space:]]*$" :
"^[[:space:]]*([0-9]+)(b|kb?|mb?|gb?)?[[:space:]]*$";
if ((e = regcomp(&ex,pattern, REG_EXTENDED | REG_ICASE)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
err("regcomp(%s): %s\n", pattern, errbuf);
return -1;
}
regmatch_t matches[3];
if ((e = regexec(&ex, str, 3, matches, 0)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
if (e != REG_NOMATCH)
err("regexec: Couldn't match '%s' in '%s': %s\n",
pattern, str, errbuf);
return -1;
}
*r = (off_t)strtoll(str + matches[1].rm_so, NULL, 10) *
(matches[2].rm_so == -1 ? 1 :
tolower(*(str + matches[2].rm_so)) == 't' ? (off_t)1 << 40 :
tolower(*(str + matches[2].rm_so)) == 'g' ? (off_t)1 << 30 :
tolower(*(str + matches[2].rm_so)) == 'm' ? (off_t)1 << 20 :
tolower(*(str + matches[2].rm_so)) == 'k' ? (off_t)1 << 10 : 1);
return 0;
}
static int parse_size(const char *str, size_t *r)
{
regex_t ex;
int e;
static const char *pattern =
"^[[:space:]]*([0-9]+)(b|kb?|mb?|gb?)?[[:space:]]*$";
if ((e = regcomp(&ex,pattern, REG_EXTENDED | REG_ICASE)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
err("regcomp(%s): %s\n", pattern, errbuf);
return -1;
}
regmatch_t matches[3];
if ((e = regexec(&ex, str, 3, matches, 0)) != 0) {
char errbuf[128];
regerror(e, &ex, errbuf, sizeof(errbuf)-1);
errbuf[sizeof(errbuf)-1] = '\0';
if (e != REG_NOMATCH)
err("regexec: Couldn't match '%s' in '%s': %s\n",
pattern, str, errbuf);
return -1;
}
*r = (size_t)strtoll(str + matches[1].rm_so, NULL, 10) *
(matches[2].rm_so == -1 ? 1 :
tolower(*(str + matches[2].rm_so)) == 'g' ? 1024 * 1024 * 1024 :
tolower(*(str + matches[2].rm_so)) == 'm' ? 1024 * 1024 :
tolower(*(str + matches[2].rm_so)) == 'k' ? 1024 : 1);
return 0;
}
static int parse_int_range(const char *str, int *start, int *end)
{
regex_t ex;
int e;
static const char *pattern =
"^[[:space:]]*([0-9]+)[[:space:]]*(-([0-9]+))?[[:space:]]*$";
if ((e = regcomp(&ex,pattern, REG_EXTEN
没有合适的资源?快使用搜索试试~ 我知道了~
lookbusy-1.4.tar.gz
需积分: 48 41 下载量 171 浏览量
2020-04-28
18:13:21
上传
评论
收藏 343KB GZ 举报
温馨提示
共54个文件
svn-base:20个
1:3个
2:2个
Linux 中用lookbusy模拟系统负载,可以模拟linux cpu 的使用率,是压力测试的大帮手。
资源推荐
资源详情
资源评论
收起资源包目录
lookbusy-1.4.tar.gz (54个子文件)
lookbusy-1.4
Makefile.am 96B
BUGS 507B
config.h.in~ 4KB
Makefile.in 24KB
configure 184KB
config.h.in 4KB
lookbusy.1 8KB
.lb.c.swp 60KB
configure.ac 913B
ChangeLog 1KB
autom4te.cache
traces.2 36KB
output.0 185KB
traces.0 36KB
output.2 180KB
requests 10KB
traces.1 33KB
output.1 185KB
head
COPYING 18KB
depcomp 18KB
install-sh 13KB
missing 11KB
web
logo.svg 3KB
index.html 2KB
logo.png 7KB
INSTALL 15KB
autogen.sh 91B
lb.c 34KB
.svn
pristine
5b
5b809fd6e1d9e28e0803c7516d7ae30d834835b0.svn-base 913B
b9
b919d2ea21d8f38326393200f09e7e4dba4042ce.svn-base 1KB
78
78263ff03782549de14f7cea16550016ab2f0ef4.svn-base 1KB
99
99f6d12924315ffbc0f8a3d963efc7a337e7509d.svn-base 34KB
9951bcfaeb37d2b350f461f4db91de429ae3c738.svn-base 91B
90
90f8a0a4a479b19fd9eb49f6f58a3da246fc9d0d.svn-base 903B
95
95b2e3127240fbe2c9bf3e0c38ee707861ca1ae4.svn-base 34KB
92
92aa138e0ac9986cbc2e3b11219e8632d8db201a.svn-base 507B
fb
fba4be3b9d109cce64eb35017e1a84f44d889de9.svn-base 7KB
8e
8e91f5dd736e990060a9bb6938c7974f0e94169a.svn-base 34KB
a7
a733c425735b89a2e3d0478ccc8b912a8b1f38d5.svn-base 2KB
4d
4ddb3a130684a1620f91c70f3073c1f92e203fa4.svn-base 53B
4d1d37f306ed270cda5b2741fac3abf0a7b012e5.svn-base 18KB
11
11097f19817fdd53fecc0fb12225497b1c00e1ba.svn-base 196B
59
59a65b389e256273c52240ab08c7c5e620a8f1c9.svn-base 3KB
f0
f0861ae690b647934dc41be85431ad807dbc3df1.svn-base 913B
9a
9aeba98b9658687c415d114132466ad6b9e84ed3.svn-base 1KB
33
33665051f1e02cddf90f8142430d5541516e672f.svn-base 2KB
c8
c8ccaffc53f69e9c9117e4e893917c8f34f9e729.svn-base 96B
40
40851ca1183ccb852335788bc3469aa836d52b7c.svn-base 8KB
wc.db 41KB
format 3B
tmp
props
prop-base
text-base
entries 3B
README 2KB
aclocal.m4 35KB
AUTHORS 53B
NEWS 196B
共 54 条
- 1
资源评论
zb.Leung
- 粉丝: 2836
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功