├── README ├── doc ├── stress.png ├── stress.xcf └── UPDATE-CHECK ├── test ├── check_usage_return_code ├── Makefile.am └── check_version_return_code ├── src ├── Makefile.am └── stress.c ├── Makefile.am ├── AUTHORS ├── man ├── create-man.sh ├── stress.txt └── stress.1 ├── configure.ac ├── CONTRIBUTING.md ├── README.md ├── TODO ├── autogen.sh ├── .github └── workflows │ └── build.yml ├── NEWS ├── ChangeLog └── COPYING /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /doc/stress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/resurrecting-open-source-projects/stress/HEAD/doc/stress.png -------------------------------------------------------------------------------- /doc/stress.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/resurrecting-open-source-projects/stress/HEAD/doc/stress.xcf -------------------------------------------------------------------------------- /test/check_usage_return_code: -------------------------------------------------------------------------------- 1 | # Test that the --help option is accepted and that stress returns 0. 2 | 3 | ../src/stress --help 4 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | MAINTAINERCLEANFILES = Makefile.in 2 | 3 | TESTS = check_version_return_code check_usage_return_code 4 | EXTRA_DIST = $(TESTS) 5 | -------------------------------------------------------------------------------- /test/check_version_return_code: -------------------------------------------------------------------------------- 1 | # Test that the --version option is accepted and that stress returns 0 2 | 3 | set -e 4 | set -x 5 | 6 | ../src/stress --version 7 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 2 | 3 | bin_PROGRAMS = stress 4 | stress_SOURCES = stress.c 5 | stress_MANS = stress.1 6 | stress_LDADD = -lm 7 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src test 2 | 3 | man_MANS = man/stress.1 4 | 5 | EXTRA_DIST= autogen.sh CONTRIBUTING.md man/stress.1 doc/stress.png README.md 6 | 7 | distclean-local: 8 | rm -rf autom4te.cache 9 | rm -f aclocal.m4 compile config.* configure depcomp INSTALL install-sh \ 10 | Makefile.in missing src/Makefile.in test-driver test/Makefile.in 11 | -------------------------------------------------------------------------------- /doc/UPDATE-CHECK: -------------------------------------------------------------------------------- 1 | When updating (if needed): 2 | 3 | - Update rights 4 | - Update changeLog 5 | - Check for spelling errors in ChangeLog, manpage and README. 6 | - Update man/create-man.sh (DATE, version) 7 | - Generate a new manpage. 8 | - Check final manpage with man command. 9 | - Updated or check README 10 | - configure.ac (VERSION) 11 | - Test in Debian Sid 12 | - Release bootstrapped tarballs with make dist. 13 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | MAINTAINERS 2 | 3 | Amos Waterland 4 | 5 | PATCHES 6 | 7 | Richard Norton 8 | Robert Paulsen 9 | Wes Hofmann 10 | Manoj Iyer 11 | Klaus Kaiser 12 | Tobias Jahn 13 | 14 | IDEAS 15 | 16 | Andrew Shewmaker 17 | Joseph Johnston 18 | Don Giuliano 19 | -------------------------------------------------------------------------------- /man/create-man.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2015-2020 Joao Eriberto Mota Filho 4 | # Create a manpage using txt2man command. Version 2.0, 2020-06-19. 5 | # This file is part of txt2man package for Debian. 6 | # This script can be used under BSD-3-Clause license. 7 | 8 | #-------------------------------------------------------- 9 | # Don't change the following lines 10 | TEST=$(txt2man -h 2> /dev/null) 11 | [ "$TEST" ] || { echo -e "\nYou need to install txt2man, from https://github.com/mvertes/txt2man.\n"; exit 1; } 12 | 13 | function create-man { 14 | txt2man -d "$T2M_DATE" -t $T2M_NAME -r $T2M_NAME-$T2M_VERSION -s $T2M_LEVEL -v "$T2M_DESC" $T2M_NAME.txt > $T2M_NAME.$T2M_LEVEL 15 | } 16 | #-------------------------------------------------------- 17 | 18 | # Put here all data for your first manpage (in T2M lines) 19 | T2M_DATE="21 Jan 2023" 20 | T2M_NAME=stress 21 | T2M_VERSION=1.0.7 22 | T2M_LEVEL=1 23 | T2M_DESC="tool to impose load on and stress test systems" 24 | create-man 25 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.69]) 2 | AC_INIT([stress], [1.0.7], [https://github.com/resurrecting-open-source-projects/stress/issues]) 3 | AC_CONFIG_SRCDIR([src/stress.c]) 4 | AC_CONFIG_HEADERS([config.h]) 5 | AM_INIT_AUTOMAKE 6 | 7 | # Checks for programs. 8 | AC_PROG_CC 9 | AC_PROG_INSTALL 10 | AC_PROG_MAKE_SET 11 | 12 | # Checks for header files. 13 | AC_CHECK_HEADERS([stdlib.h string.h unistd.h sys/prctl.h]) 14 | 15 | # Checks for library functions. 16 | AC_FUNC_FORK 17 | AC_FUNC_MALLOC 18 | AC_CHECK_FUNCS([alarm sqrt strerror]) 19 | 20 | # Special functions 21 | AC_ARG_ENABLE([static], 22 | AS_HELP_STRING([--enable-static], 23 | [build static library @<:@default=no@:>@]), 24 | [static=$enableval], 25 | [static=no]) 26 | 27 | if test "$static" = yes; then 28 | # if we're using gcc, add `-static' to LDFLAGS 29 | if test -n "$GCC" || test "$ac_cv_c_compiler_gnu" = "yes"; then 30 | STATIC_LD="-static" 31 | LDFLAGS="$LDFLAGS -static" 32 | fi 33 | fi 34 | 35 | AC_CONFIG_FILES([Makefile 36 | src/Makefile 37 | test/Makefile]) 38 | AC_OUTPUT 39 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## HOW TO CONTRIBUTE TO STRESS DEVELOPMENT 2 | 3 | stress is available at https://github.com/resurrecting-open-source-projects/stress 4 | 5 | If you are interested in contribute to stress development, please, follow the 6 | following steps: 7 | 8 | 1. Send a patch that fix an issue or that implement a new feature. 9 | Preferably, you can do a 'pull request'[1] in GitHub. 10 | 11 | [1] https://help.github.com/articles/about-pull-requests 12 | 13 | 2. Ask for join to the stress project in GitHub, if you want to work 14 | officially. Note that this second step is not compulsory. However, 15 | to accept you in project, is needed a minimum previous collaboration. 16 | 17 | 18 | To find issues and bugs to fix, you can check these addresses: 19 | 20 | - https://github.com/resurrecting-open-source-projects/stress/issues 21 | - https://bugs.debian.org/cgi-bin/pkgreport.cgi?src=stress 22 | - https://bugs.launchpad.net/ubuntu/+source/stress/+bugs 23 | - https://bugs.archlinux.org/?project=5&string=stress 24 | - https://packages.gentoo.org/packages/app-benchmarks/stress/bugs 25 | - https://apps.fedoraproject.org/packages/stress/bugs 26 | 27 | -- Eriberto, Fri, 01 Oct 2021 18:00:21 -0300 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stress 2 | 3 | #### stress - tool to impose load on and stress test a computer system 4 | 5 | ## What is stress? 6 | 7 | stress is a tool that imposes a configurable amount of CPU, memory, I/O, 8 | or disk stress on a POSIX-compliant operating system and reports any errors 9 | it detects. 10 | 11 | stress is not a benchmark. It is a tool used by system administrators to 12 | evaluate how well their systems will scale, by kernel programmers to evaluate 13 | perceived performance characteristics, and by systems programmers to expose 14 | the classes of bugs which only or more frequently manifest themselves when 15 | the system is under heavy load. 16 | 17 | ## Help this project ## 18 | 19 | stress needs your help. **If you are a programmer** and want to help a nice 20 | project, this is your opportunity. 21 | 22 | The original stress went unmaintained; the source of the last version, 1.0.4, 23 | was [imported from Debian](https://snapshot.debian.org/package/stress/). 24 | After, patches from Debian and other changes were applied to create the 1.0.5 25 | release. The details of each release are registered in the [ChangeLog](ChangeLog) 26 | file. Now, stress is maintained by volunteers under [Resurrecting Open Source 27 | Projects](https://github.com/resurrecting-open-source-projects). 28 | 29 | If you are interested in helping stress, read the [CONTRIBUTING.md](CONTRIBUTING.md) file. 30 | 31 | ## Building 32 | 33 | From a Unix command line, building is simple: 34 | 35 | ``` 36 | ./autogen.sh 37 | ./configure 38 | make 39 | make install 40 | ``` 41 | 42 | ## Author ## 43 | 44 | stress was originally developed by Amos Waterland , 45 | under the GPL-2+ license. 46 | 47 | The original download sites were http://people.seas.harvard.edu/~apw/stress 48 | and http://weather.ou.edu/~apw/projects/stress/ 49 | 50 | Currently, source code is maintained by volunteers. Newer versions are 51 | available at https://github.com/resurrecting-open-source-projects/stress 52 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | `stress' TODO -- development roadmap 2 | Copyright (C) 2005 Amos Waterland. 3 | See the end for copying conditions. 4 | 5 | Please send `stress' bug reports, questions, and suggestions to 6 | . 7 | 8 | Build easily without autoconf 9 | 10 | * Define VERSION, among other things. 11 | 12 | Use a concept instead of an option 13 | 14 | * Instead of explicit options like --vm-bytes, get rid of all --vm 15 | options but one: --vm-pattern=webserver,database,raytracer etc. 16 | 17 | Barrier instead of backoff 18 | 19 | * If you fork a sufficiently high number of children, the system will 20 | become so overloaded that new children do not ever get a chance to 21 | even start. It is arguable whether stress should bother to deal 22 | with this at all, but at present it does so by giving each child a 23 | backoff timer. Each child immediately goes to sleep upon entry, 24 | and wakes up only after the backoff factor has expired. This 25 | allows the kernel to fork an absurd number of processes. If we 26 | decide this is a behavior we wish to preserve, we should move to a 27 | model where each child just waits for a signal from the parent, 28 | which it can send to its whole process group effeciently once it 29 | finishes forking all the requested children. This would allow us 30 | to get rid of the `--backoff' option and reduce the associated code 31 | complexity. 32 | 33 | ---------------------------------------------------------------------- 34 | Copyright information: 35 | 36 | Copyright (C) 2005 Amos Waterland 37 | 38 | Permission is granted to anyone to make or distribute verbatim copies 39 | of this document as received, in any medium, provided that the 40 | copyright notice and this permission notice are preserved, 41 | thus giving the recipient permission to redistribute in turn. 42 | 43 | Permission is granted to distribute modified versions 44 | of this document, or of portions of it, 45 | under the above conditions, provided also that they 46 | carry prominent notices stating who last changed them. 47 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # autogen.sh with clean option 4 | # Copyright 2016-2021 Joao Eriberto Mota Filho 5 | # 6 | # This file is under BSD-3-Clause license. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the authors nor the names of its contributors 17 | # may be used to endorse or promote products derived from this software 18 | # without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | # SUCH DAMAGE. 31 | 32 | 33 | # Use clean option 34 | if [ "$1" = "clean" -a ! -e Makefile ] 35 | then 36 | echo "Vanishing the code" 37 | rm -rf aclocal.m4 autom4te.cache compile config.* configure depcomp \ 38 | doc/Makefile.in INSTALL install-sh Makefile.in missing \ 39 | src/Makefile.in test-driver test/Makefile.in 40 | exit 0 41 | fi 42 | 43 | # Do not use clean option 44 | if [ "$1" = "clean" -a -e Makefile ] 45 | then 46 | echo "I can not clean. Use '$ make distclean'." 47 | exit 0 48 | fi 49 | 50 | # Do autoreconf 51 | autoreconf -i \ 52 | && { echo " "; \ 53 | echo "Done. You can use the 'clean' option to vanish the source code."; \ 54 | echo "Example of use: $ ./autogen clean"; \ 55 | } \ 56 | || { echo "We have a problem..."; exit 1; } 57 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: full-check 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | 7 | build-macOS: 8 | runs-on: macos-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: build 12 | run: | 13 | brew install autoconf automake libtool 14 | ./autogen.sh 15 | ./configure 16 | make 17 | make clean 18 | make 19 | sudo make install 20 | - name: run_program 21 | run: | 22 | stress 23 | stress --vm 2 -t 2 | grep "2 vm" -C2 24 | - name: uninstall_distclean 25 | run: | 26 | sudo make uninstall 27 | make distclean 28 | 29 | build-linux: 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@v2 33 | - name: first_build 34 | run: | 35 | ./autogen.sh 36 | ./configure 37 | make 38 | make clean 39 | make 40 | sudo make install 41 | sudo make uninstall 42 | make distclean 43 | - name: second_build 44 | run: | 45 | ./autogen.sh 46 | ./configure 47 | make 48 | sudo make install 49 | - name: run_program 50 | run: | 51 | stress 52 | stress --vm 2 -t 1 | grep "2 vm" -C2 53 | - name: pre-clean 54 | run: | 55 | sudo make uninstall 56 | make distclean 57 | - name: test_make_dist 58 | run: | 59 | ./autogen.sh 60 | ./configure 61 | make dist 62 | mkdir test_dist 63 | mv stress-*.tar.gz test_dist 64 | cd test_dist 65 | pwd 66 | tar -xvf stress-*.tar.gz 67 | rm -f stress-*.tar.gz 68 | cd stress-* 69 | ./autogen.sh 70 | ./configure 71 | make 72 | ls 73 | sudo make install 74 | sudo make uninstall 75 | make distclean 76 | cd ../.. 77 | rm -rf test_dist 78 | - name: test_make_dist-bzip2 79 | run: | 80 | ./autogen.sh 81 | ./configure 82 | make dist-bzip2 83 | mkdir test_dist 84 | mv stress-*.tar.bz2 test_dist 85 | cd test_dist 86 | pwd 87 | tar -xvf stress-*.tar.bz2 88 | rm -f stress-*.tar.bz2 89 | cd stress-* 90 | ./autogen.sh 91 | ./configure 92 | make 93 | ls 94 | sudo make install 95 | sudo make uninstall 96 | make distclean 97 | -------------------------------------------------------------------------------- /man/stress.txt: -------------------------------------------------------------------------------- 1 | NAME 2 | stress - tool to impose load on and stress test a computer system 3 | 4 | SYNOPSIS 5 | stress [OPTIONS] 6 | 7 | DESCRIPTION 8 | stress is a tool that imposes a configurable amount of CPU, memory, I/O, 9 | or disk stress on a POSIX-compliant operating system and reports any errors 10 | it detects. 11 | 12 | stress is not a benchmark. It is a tool used by system administrators to 13 | evaluate how well their systems will scale, by kernel programmers to evaluate 14 | perceived performance characteristics, and by systems programmers to expose 15 | the classes of bugs which only or more frequently manifest themselves when 16 | the system is under heavy load. 17 | 18 | OPTIONS 19 | -?, --help Show this help statement. 20 | --version Show version statement. 21 | -v, --verbose Be verbose. 22 | -q, --quiet Be quiet. 23 | -n, --dry-run Show what would have been done. 24 | -t, --timeout Timeout after N seconds. This option is ignored by -n. 25 | --backoff Wait for factor of microseconds before starting work. 26 | -c, --cpu Spawn N workers spinning on sqrt(). 27 | -i, --io Spawn N workers spinning on sync(). 28 | -m, --vm Spawn N workers spinning on malloc()/free(). 29 | --vm-bytes Malloc B bytes per vm worker (default is 256MB). 30 | --vm-stride Touch a byte every B bytes (default is 4096). 31 | --vm-hang Sleep N secs before free (default none, 0 is inf). 32 | --vm-keep Redirty memory instead of freeing and reallocating. 33 | -d, --hdd Spawn N workers spinning on write()/unlink(). 34 | --hdd-bytes Write B bytes per hdd worker (default is 1GB). The file 35 | will be created with mkstemp() in the current directory. 36 | 37 | Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size). 38 | 39 | EXAMPLES 40 | The simple case is that you just want to bring the system load average up to an 41 | arbitrary value. The following forks 13 processes, each of which spins in a 42 | tight loop calculating the sqrt() of a random number acquired with rand(). 43 | 44 | stress -c 13 45 | 46 | Long options are supported, as well as is making the output less verbose. The 47 | following forks 1024 processes, and only reports error messages if any. 48 | 49 | stress --quiet --cpu 1k 50 | 51 | To see how your system performs when it is I/O bound, use the -i switch. The 52 | following forks 4 processes, each of which spins in a tight loop calling 53 | sync(), which is a system call that flushes memory buffers to disk. 54 | 55 | stress -i 4 56 | 57 | Multiple hogs may be combined on the same command line. The following does 58 | everything the preceding examples did in one command, but also turns up the 59 | verbosity level as well as showing how to cause the command to self-terminate 60 | after 1 minute. 61 | 62 | stress -c 13 -i 4 --verbose --timeout 1m 63 | 64 | You can write a file of arbitrary length to disk. The file is created with 65 | mkstemp() in the current directory. 66 | 67 | stress -d 1 --hdd-bytes 13 68 | 69 | Large file support is enabled. 70 | 71 | stress -d 1 --hdd-bytes 3G 72 | 73 | AUTHOR 74 | stress was originally developed by Amos Waterland and 75 | is maintained by some volunteers. 76 | 77 | Currently, source code and newer versions are available at 78 | https://github.com/resurrecting-open-source-projects/stress 79 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | `stress' NEWS -- history of user-visible changes. 2 | Copyright (C) 2001-2010 Amos Waterland. 3 | See the end for copying conditions. 4 | 5 | Please send `stress' bug reports, questions, and suggestions to 6 | . 7 | 8 | 2010-02-17 Version 1.0.3 9 | 10 | * Fix manpage problem reported by Mark Lumsden. Remove --no-clean 11 | option. 12 | 13 | 2009-12-02 Version 1.0.2 14 | 15 | * Fix AIX compile. Apply patch from Wilken Gottwalt to make tee 16 | behave properly. 17 | 18 | 2009-08-11 Version 1.0.1 19 | 20 | * Minor automake cleanups. Apply patch from Dileepa Prabhakar to 21 | randomize slow writing. 22 | 23 | 2007-12-16 Version 1.0.0 24 | 25 | * Try to detect memory corruption. 26 | 27 | 2005-06-30 Version 0.18.8 28 | 29 | * Apply patch from Richard Norton to fix problem in date calculation. 30 | 31 | 2005-06-30 Version 0.18.6 32 | 33 | * Apply modified patch from Bob Paulsen to stride through memory in 34 | increments other than unity, and to hang after allocating memory in 35 | an time other than infinity. 36 | 37 | 2005-04-08 Version 0.18.4 38 | 39 | * A bug has been fixed in which timeout under extremely heavy load 40 | could wrap to a negative value. There are some usage statement 41 | fixes and improved Debian packaging. 42 | 43 | 2004-11-18 Version 0.18.2 44 | 45 | * Rewrite the usage statement so as to be explicit about disk and memory 46 | stress. Improve the Debian packaging. 47 | 48 | 2003-08-04 Version 0.18.1 49 | 50 | * The parent now reaps workers immediately and exits with an error if 51 | any of the workers encounter a problem. This allows the tool to be 52 | used as an automated stress test. 53 | 54 | 2003-06-27 Version 0.17.2 55 | 56 | * Minor portability changes: now runs on OpenBSD. 57 | 58 | 2003-05-25 Version 0.17 59 | 60 | * This release is identical to 0.17pre20, and is a complete rewrite 61 | relative to the 0.16 release. 62 | 63 | 2003-05-08 Version 0.17pre20 64 | 65 | * Strict error checking on options, and an updated Texinfo manual. 66 | 67 | 2003-05-08 Version 0.17pre19 68 | 69 | * Major internal code cleanup. Uses round-robin dispatch of worker 70 | processes. 71 | 72 | 2003-05-06 Version 0.17pre18 73 | 74 | * This release adds rewritten timeout logic, fixes bugs which caused 75 | some errors to not be correctly propagated up the call stack, slightly 76 | simplifies the interface, and adds a configure option to produce a 77 | statically-linked binary. 78 | 79 | 2003-01-07 Version 0.17pre14 80 | 81 | * Many small bugfixes and usability enhancements. 82 | 83 | 2002-12-10 Version 0.17pre10 84 | 85 | * New --backoff, --no-retry, and --timeout switches, a texinfo manual, 86 | regression tests, and many minor bugfixes. 87 | 88 | 2002-12-08 Version 0.17pre8 89 | 90 | * This version fixes minor bugs, adds a texinfo manual, and adds tests 91 | for `make check'. 92 | 93 | 2002-12-06 Version 0.17pre7 94 | 95 | * A complete rewrite. Each option is now handled by a fork, so 96 | multiple hogs may be specifed on the same command line. Load average 97 | may be brought up to arbitrary value, and all available memory and 98 | disk space may be consumed. The GNU autotools are used, and testing 99 | has been done on Solaris and GNU/Linux. 100 | 101 | ---------------------------------------------------------------------- 102 | Copyright information: 103 | 104 | Copyright (C) 2001-2010 Amos Waterland 105 | 106 | Permission is granted to anyone to make or distribute verbatim copies 107 | of this document as received, in any medium, provided that the 108 | copyright notice and this permission notice are preserved, 109 | thus giving the recipient permission to redistribute in turn. 110 | 111 | Permission is granted to distribute modified versions 112 | of this document, or of portions of it, 113 | under the above conditions, provided also that they 114 | carry prominent notices stating who last changed them. 115 | -------------------------------------------------------------------------------- /man/stress.1: -------------------------------------------------------------------------------- 1 | .\" Text automatically generated by txt2man 2 | .TH stress 1 "21 Jan 2023" "stress-1.0.7" "tool to impose load on and stress test systems" 3 | .SH NAME 4 | \fBstress \fP- tool to impose load on and stress test a computer system 5 | \fB 6 | .SH SYNOPSIS 7 | .nf 8 | .fam C 9 | \fBstress\fP [\fIOPTIONS\fP] 10 | 11 | .fam T 12 | .fi 13 | .fam T 14 | .fi 15 | .SH DESCRIPTION 16 | \fBstress\fP is a tool that imposes a configurable amount of CPU, memory, I/O, 17 | or disk \fBstress\fP on a POSIX-compliant operating system and reports any errors 18 | it detects. 19 | .PP 20 | \fBstress\fP is not a benchmark. It is a tool used by system administrators to 21 | evaluate how well their systems will scale, by kernel programmers to evaluate 22 | perceived performance characteristics, and by systems programmers to expose 23 | the classes of bugs which only or more frequently manifest themselves when 24 | the system is under heavy load. 25 | .SH OPTIONS 26 | .TP 27 | .B 28 | -?, \fB--help\fP 29 | Show this help statement. 30 | .TP 31 | .B 32 | \fB--version\fP 33 | Show version statement. 34 | .TP 35 | .B 36 | \fB-v\fP, \fB--verbose\fP 37 | Be verbose. 38 | .TP 39 | .B 40 | \fB-q\fP, \fB--quiet\fP 41 | Be quiet. 42 | .TP 43 | .B 44 | \fB-n\fP, \fB--dry-run\fP 45 | Show what would have been done. 46 | .TP 47 | .B 48 | \fB-t\fP, \fB--timeout\fP 49 | Timeout after N seconds. This option is ignored by \fB-n\fP. 50 | .TP 51 | .B 52 | \fB--backoff\fP 53 | Wait for factor of microseconds before starting work. 54 | .TP 55 | .B 56 | \fB-c\fP, \fB--cpu\fP 57 | Spawn N workers spinning on \fBsqrt\fP(). 58 | .TP 59 | .B 60 | \fB-i\fP, \fB--io\fP 61 | Spawn N workers spinning on \fBsync\fP(). 62 | .TP 63 | .B 64 | \fB-m\fP, \fB--vm\fP 65 | Spawn N workers spinning on \fBmalloc\fP()/free(). 66 | .TP 67 | .B 68 | \fB--vm-bytes\fP 69 | Malloc B bytes per vm worker (default is 256MB). 70 | .TP 71 | .B 72 | \fB--vm-stride\fP 73 | Touch a byte every B bytes (default is 4096). 74 | .TP 75 | .B 76 | \fB--vm-hang\fP 77 | Sleep N secs before free (default none, 0 is inf). 78 | .TP 79 | .B 80 | \fB--vm-keep\fP 81 | Redirty memory instead of freeing and reallocating. 82 | .TP 83 | .B 84 | \fB-d\fP, \fB--hdd\fP 85 | Spawn N workers spinning on \fBwrite\fP()/unlink(). 86 | .TP 87 | .B 88 | \fB--hdd-bytes\fP 89 | Write B bytes per hdd worker (default is 1GB). The file 90 | will be created with \fBmkstemp\fP() in the current directory. 91 | .PP 92 | Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size). 93 | .SH EXAMPLES 94 | The simple case is that you just want to bring the system load average up to an 95 | arbitrary value. The following forks 13 processes, each of which spins in a 96 | tight loop calculating the \fBsqrt\fP() of a random number acquired with \fBrand\fP(). 97 | .PP 98 | .nf 99 | .fam C 100 | stress -c 13 101 | 102 | .fam T 103 | .fi 104 | Long options are supported, as well as is making the output less verbose. The 105 | following forks 1024 processes, and only reports error messages if any. 106 | .PP 107 | .nf 108 | .fam C 109 | stress --quiet --cpu 1k 110 | 111 | .fam T 112 | .fi 113 | To see how your system performs when it is I/O bound, use the \fB-i\fP switch. The 114 | following forks 4 processes, each of which spins in a tight loop calling 115 | \fBsync\fP(), which is a system call that flushes memory buffers to disk. 116 | .PP 117 | .nf 118 | .fam C 119 | stress -i 4 120 | 121 | .fam T 122 | .fi 123 | Multiple hogs may be combined on the same command line. The following does 124 | everything the preceding examples did in one command, but also turns up the 125 | verbosity level as well as showing how to cause the command to self-terminate 126 | after 1 minute. 127 | .PP 128 | .nf 129 | .fam C 130 | stress -c 13 -i 4 --verbose --timeout 1m 131 | 132 | .fam T 133 | .fi 134 | You can write a file of arbitrary length to disk. The file is created with 135 | \fBmkstemp\fP() in the current directory. 136 | .PP 137 | .nf 138 | .fam C 139 | stress -d 1 --hdd-bytes 13 140 | 141 | Large file support is enabled. 142 | 143 | stress -d 1 --hdd-bytes 3G 144 | 145 | .fam T 146 | .fi 147 | .SH AUTHOR 148 | \fBstress\fP was originally developed by Amos Waterland and 149 | is maintained by some volunteers. 150 | .PP 151 | Currently, source code and newer versions are available at 152 | https://github.com/resurrecting-open-source-projects/\fBstress\fP 153 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2023-01-21 Joao Eriberto Mota Filho 2 | Version 1.0.7 3 | 4 | [ Vratislav Bendel ] 5 | * Check for sys/prctl.h availability, because non-Linux 6 | architectures don't provide . 7 | 8 | [ Joao Eriberto Mota Filho ] 9 | * Improved GitHub CI: 10 | - Added CI test for macOS. 11 | - Added a check for stress command. 12 | - Added a test for 'make dist-bzip2'. 13 | * Moved manpage from doc/ to man/. 14 | 15 | 2023-01-17 Joao Eriberto Mota Filho 16 | Version 1.0.6 17 | 18 | [ Vratislav Bendel ] 19 | * Register parent termination signal in child processes. 20 | 21 | [ Joao Eriberto Mota Filho ] 22 | * Added 'make dist' check in CI test. 23 | * Added rights for Vratislav Bendel. 24 | * Re-organized src/stress.c via astyle command. 25 | * Updated GPL-2 license text for src/stress.c. 26 | 27 | 2021-10-01 Joao Eriberto Mota Filho 28 | Version 1.0.5 29 | 30 | * Added CI test for GitHub. 31 | * Migrated manpage system to txt2man. 32 | * Modernized system install. 33 | * Set right permissions to source code. 34 | * Updated README and added a CONTRIBUTING file. 35 | * Other minor changes and improvements. 36 | 37 | 2010-03-19 Amos Waterland 38 | Version 1.0.4 39 | 40 | * configure.in, doc/version.texi: Up to version 1.0.4. 41 | 42 | * src/stress.c: Fix unlink error reported by Farkas Levente. 43 | 44 | 2010-03-17 Amos Waterland 45 | 46 | * src/stress.c: Make the error message on unlink fail more clear. 47 | 48 | 2010-02-18 Amos Waterland 49 | Version 1.0.3 50 | 51 | * NEWS, doc/version.texi: Fix NEWS. 52 | 53 | * configure.in, src/stress.c: Up to version 1.0.3. Remove no-clean 54 | option. 55 | 56 | 2009-12-03 Amos Waterland 57 | Version 1.0.2 58 | 59 | * NEWS, configure.in, doc/version.texi: Up to version 1.0.2. 60 | 61 | * src/Makefile.am: Remove Wall and Werror flags so we can build 62 | on AIX with xlc. 63 | 64 | * src/stress.c: Apply patch from Wilken Gottwalt to make tee 65 | behave properly. 66 | 67 | 2009-08-12 Amos Waterland 68 | Version 1.0.1 69 | 70 | * NEWS: Update the NEWS file. 71 | 72 | * etc/deb/Makefile, etc/deb/debian/changelog, etc/deb/debian/control, 73 | etc/deb/debian/rules: More changes for packaging. 74 | 75 | * etc/deb/Makefile, etc/deb/debian/changelog, etc/deb/debian/control, 76 | etc/deb/debian/rules: Changes for the purpose of packaging. 77 | 78 | * doc/version.texi: Increase version. 79 | 80 | * NEWS, configure.in: Up to version 1.0.1 81 | 82 | * src/stress.c: Apply patch from Dileepa Prabhakar to randomize 83 | slow writing. 84 | 85 | * Makefile.am, src/Makefile.am: Small cleanups for automake. 86 | 87 | * src/stress.c: Initialize pointer. 88 | 89 | 2008-05-30 Amos Waterland 90 | 91 | * FAQ, README: Add FAQ and modify README. 92 | 93 | 2007-12-17 Amos Waterland 94 | Version 1.0.0 95 | 96 | * NEWS, README, configure.in, doc/version.texi: Up to version 1.0.0. 97 | 98 | 2007-12-15 Amos Waterland 99 | 100 | * src/stress.c: Add check for memory corruption. 101 | 102 | 2007-01-25 Amos Waterland 103 | 104 | * etc/deb/debian/control: Change priority from optional to extra. 105 | 106 | 2007-01-23 Amos Waterland 107 | 108 | * TODO: Add build standalone. 109 | 110 | * TODO: Add note about option directions. 111 | 112 | * doc/version.texi, etc/deb/Makefile, etc/deb/debian/changelog: 113 | Up to version 0.18.9 114 | 115 | 2007-01-18 Amos Waterland 116 | 117 | * configure.in, etc/deb/Makefile, etc/deb/debian/changelog, 118 | etc/deb/debian/control, etc/deb/debian/rules: Up to version 0.18.9. 119 | 120 | * doc/Makefile.am: Make a better apropos message for manpage. 121 | 122 | 2005-12-08 Amos Waterland 123 | 124 | * NEWS, doc/version.texi: Add entry for 0.18.8 release. 125 | 126 | * configure.in: Up version to 0.18.8. 127 | 128 | * src/stress.c: Apply patch from Richard Norton to fix calculation 129 | of timeouts with year suffixes. 130 | 131 | * AUTHORS: Add Richard Norton to list of patch contributors. 132 | 133 | 2005-08-09 Amos Waterland 134 | 135 | * etc/deb/Makefile, etc/deb/debian/changelog, etc/deb/debian/control: 136 | Fixes for version 0.18.6. 137 | 138 | 2005-07-03 Amos Waterland 139 | 140 | * src/stress.c: Apply modified patch from Bob Paulsen to add the 141 | option to keep memory instead of freeing and reallocating it. 142 | 143 | 2005-06-30 Amos Waterland 144 | Version 0.18.6 145 | 146 | * NEWS: Add note for version 0.18.6. 147 | 148 | 2005-06-27 Amos Waterland 149 | 150 | * configure.in: Up to version 0.18.6. 151 | 152 | * src/stress.c: Use less whitespace for help statement indents. 153 | Fix help statement for --vm-hang option. 154 | 155 | * configure.in: Increment to version 0.18.5. 156 | 157 | * AUTHORS: Add Bob Paulsen. 158 | 159 | * src/stress.c: Add option to stride through memory in increments 160 | other than unity. Modify option to hang after allocating memory 161 | to support values other than infinity. 162 | 163 | 2005-06-04 Amos Waterland 164 | 165 | * src/stress.c: Make message about using up time before all workers 166 | dispatched a warning instead of a debug. 167 | 168 | 2005-05-29 Amos Waterland 169 | 170 | * TODO: Explain about removing the --backoff option. 171 | 172 | * TODO: Initial check-in. 173 | 174 | 2005-04-08 Amos Waterland 175 | Version 0.18.4 176 | 177 | * NEWS: Add entry for version 0.18.4 178 | 179 | 2005-03-10 Amos Waterland 180 | 181 | * etc/deb/debian/changelog: Update to version 0.18.4-1. 182 | 183 | * etc/deb/Makefile: Update to version 0.18.4. 184 | 185 | * bootstrap: Do not specify version of autoconf. 186 | 187 | * configure.in: Increment to version 0.18.4. 188 | 189 | * doc/stress.texi: Move from the GFDL to the GPL. 190 | 191 | * etc/deb/debian/control: Do not include sentence about autotools 192 | and C. 193 | 194 | 2005-02-26 Amos Waterland 195 | 196 | * etc/deb/debian/rules: Follow Gaudenz Steinlin's suggestion of 197 | removing commented-out rules. 198 | 199 | * etc/deb/debian/copyright: Follow Gaudenz Steinlin's suggestion 200 | of combining upstream author and debianizer. 201 | 202 | * etc/deb/debian/control: Change standards version to 3.6.1.1. 203 | 204 | * etc/deb/debian/changelog: Follow Gaudenz Steinlin's suggestion 205 | of making initial upload have only one revision. 206 | 207 | * etc/deb/Makefile: Update version to 0.18.3. 208 | 209 | * bootstrap: We rely upon autoconf2.50. 210 | 211 | * etc/deb/debian/control: Update standards version to 3.6.1.0. 212 | 213 | 2005-02-10 Amos Waterland 214 | 215 | * src/stress.c: Add 2005 to copyright statement. 216 | 217 | * src/stress.c: Change the --vm-hang usage statement to be symmetric 218 | with that of --hdd-noclean. 219 | 220 | * src/stress.c: Clarify --vm-hang usage explanation. 221 | 222 | 2005-01-14 Amos Waterland 223 | 224 | * configure.in: Increment version to 0.18.3. 225 | 226 | * src/stress.c: Indentation fixes. 227 | 228 | * src/stress.c: Fix bug in which timeout under heavy load can wrap 229 | to a negative value. Also, print index of each worker type as it 230 | is forked. 231 | 232 | 2005-01-12 Amos Waterland 233 | 234 | * src/stress.c: Make suffix explanation in usage statement more 235 | clear. 236 | 237 | 2004-12-21 Amos Waterland 238 | 239 | * src/stress.c: Change email address. Update copyright years. 240 | 241 | * doc/stress.texi, AUTHORS, NEWS, README: Change email address. 242 | 243 | * doc/version.texi: Update to version 0.18.2 244 | 245 | * src/stress.c: Do not print line number in debug messages. 246 | Print more debugging messages during vm and hdd work. 247 | 248 | 2004-11-18 Amos Waterland 249 | Version 0.18.2 250 | 251 | * etc/rpm/Makefile, etc/rpm/SPECS/stress.spec: Increment version 252 | to 0.18.2. 253 | 254 | * bootstrap: Temporarily create a ChangeLog file to make automake 255 | happy. 256 | 257 | * NEWS: Add entry for version 0.18.2. 258 | 259 | 2004-09-02 Amos Waterland 260 | 261 | * etc/deb/debian/changelog: Add entry for 0.18.2. 262 | 263 | * etc/deb/debian/control: Change version of debhelper required. 264 | 265 | * Makefile.am: Add ChangeLog to EXTRA_DIST. 266 | 267 | * etc/deb/Makefile: Increment version to 0.18.2 268 | 269 | * Makefile.am: Use automatic generation scheme for ChangeLog. 270 | 271 | * ChangeLog: Removing in favor of automatic generation scheme. 272 | 273 | * configure.in: Increment version number to 0.18.2. 274 | 275 | 2004-07-21 Amos Waterland 276 | 277 | * Makefile.am: Use cvs log to generate input to rcs2log. 278 | 279 | * src/stress.c: Reword most of the usage statement. 280 | 281 | * NEWS: Add release history by pulling from Freshmeat records. 282 | 283 | 2003-11-25 Amos Waterland 284 | 285 | * ChangeLog, src/stress.c: Include b in list of valid suffixes. 286 | 287 | 2003-08-04 Amos Waterland 288 | Version 0.18.1 289 | 290 | * ChangeLog: Add entries. 291 | 292 | * etc/deb/Makefile: Update version number. 293 | 294 | * etc/deb/debian/changelog: Updated package version. 295 | 296 | * etc/deb/debian/files: Removed file. 297 | 298 | 2003-07-31 Amos Waterland 299 | 300 | * etc/rpm/Makefile, etc/rpm/SPECS/stress.spec: Change to 0.18.1. 301 | 302 | * configure.in: Up version number. 303 | 304 | * src/stress.c: Cast return of getpid in message printing to 305 | long long. 306 | 307 | * configure.in: Up version number. 308 | 309 | * src/stress.c: Make parent reap all children as soon as any of 310 | them have an error condition. 311 | 312 | * src/stress.c: Make warn and fail messages appear in all caps, 313 | print pid in all messages other than info class. 314 | 315 | * src/stress.c: Make copyright in header include 2003. 316 | 317 | * src/stress.c: Make all the rest of the syscalls print output of 318 | strerror() if they fail. 319 | 320 | * src/stress.c: Make all syscalls in hoghdd() print the output 321 | of strerror() upon failure. Change meaning of do_hdd_clean to 322 | be intuitive. 323 | 324 | 2003-07-14 Amos Waterland 325 | 326 | * etc/deb/Makefile: Change clean rule. 327 | 328 | * etc/deb/Makefile: Remove CVS dir. 329 | 330 | * etc/deb/Makefile: Change tarball name. 331 | 332 | * etc/deb/debian/control, etc/deb/debian/copyright, 333 | etc/deb/debian/docs, etc/deb/debian/files, etc/deb/debian/info, 334 | etc/deb/debian/rules, etc/deb/Makefile, etc/deb/debian/changelog: 335 | Initial check-in. 336 | 337 | 2003-07-08 Amos Waterland 338 | 339 | * etc/rpm/SPECS/stress.spec: Up release. 340 | 341 | * etc/rpm/SPECS/stress.spec, etc/rpm/Makefile: Changes. 342 | 343 | 2003-07-07 Amos Waterland 344 | 345 | * etc/rpm/SPECS/stress.spec, etc/rpm/Makefile, etc/rpm/stress.spec: 346 | Change organization. 347 | 348 | * etc/rpm/stress.spec: Initial check-in. 349 | 350 | 2003-06-17 Amos Waterland 351 | 352 | * configure.in: Up version. 353 | 354 | * ChangeLog: Add entry. 355 | 356 | * configure.in: Up version. 357 | 358 | * src/stress.c: Use sscanf instead of atoll for portability. 359 | Original patch contributed by David Ranch . 360 | 361 | 2003-05-25 Amos Waterland 362 | Version 0.17 363 | 364 | * configure.in: Up version. 365 | 366 | 2003-05-08 Amos Waterland 367 | Version 0.17pre20 368 | 369 | * doc/Makefile.am, doc/version.texi: Minor change. 370 | 371 | * AUTHORS, README: Removed help2man hooks. 372 | 373 | * doc/version.texi: Change. 374 | 375 | * doc/stress.texi: Updates. 376 | 377 | * configure.in: Up. 378 | 379 | * ChangeLog: Minor. 380 | 381 | * src/stress.c: Make worker return messages consistent. Print value 382 | of signal if worker killed abnormally. 383 | 384 | * src/stress.c, ChangeLog: Make arguments check for invalid values. 385 | 386 | * ChangeLog, doc/version.texi: Minor changes. 387 | 388 | 2003-05-07 Amos Waterland 389 | 390 | * test/Makefile.am: Removed test. 391 | 392 | * test/check_hogcpu: Minor change. 393 | 394 | * ChangeLog: Note. 395 | 396 | * src/stress.c: Major reworking. Removed many options. Moved to 397 | round-robin dispatcher model. 398 | 399 | * configure.in: Up version. 400 | 401 | 2003-05-06 Amos Waterland 402 | Version 0.17pre18 403 | 404 | * src/stress.c: (atoll_b) Use shift instead of multiply for speed. 405 | Original patch contributed by Wes Hofmann . 406 | 407 | * ChangeLog, configure.in: Up version number. 408 | 409 | * src/stress.c: Changed usage statement. 410 | 411 | * doc/Makefile.am, doc/version.texi: Minor change. 412 | 413 | * test/Makefile.am: Removed hoghdd test. 414 | 415 | * configure.in: Up version number 416 | 417 | * src/stress.c: Major rework. 418 | 419 | 2003-04-12 Amos Waterland 420 | 421 | * configure.in: Upped version. 422 | 423 | * configure.in, doc/stress.texi, doc/version.texi: Minor changes. 424 | 425 | 2003-03-28 Amos Waterland 426 | 427 | * configure.in: Cleanup again as per glibc. 428 | 429 | * doc/version.texi, configure.in: Cleaned up the --enable-static 430 | option. 431 | 432 | * configure.in: Added --enable-static-link. 433 | 434 | * src/Makefile.am: Added -Werror. 435 | 436 | 2003-01-16 Amos Waterland 437 | 438 | * configure.in: Minor change. 439 | 440 | 2002-12-17 Amos Waterland 441 | 442 | * README: Minor changes. 443 | 444 | 2002-12-14 Amos Waterland 445 | 446 | * README, configure.in: Minor changes. 447 | 448 | * src/stress.c: Added --vm-hang. 449 | 450 | 2002-12-13 Amos Waterland 451 | 452 | * AUTHORS, ChangeLog, doc/version.texi, configure.in: Minor changes. 453 | 454 | * src/stress.c: Remove hard coding of 'stress' in usage, 455 | version statements. Original patch contributed by Manoj Iyer 456 | . 457 | 458 | 2002-12-11 Amos Waterland 459 | 460 | * README, doc/version.texi: Minor changes. 461 | 462 | * src/stress.c: Minor bugfix. 463 | 464 | * configure.in: Minor changes. This is pre12 shipped to rcp. 465 | 466 | * doc/Makefile.am, doc/stress.texi, doc/stress.1, Makefile.am, 467 | configure.in, src/stress.c, test/Makefile.am, test/check_atoll_s, 468 | test/check_hogcpu, test/check_hoghdd: Minor changes. 469 | 470 | * src/stress.c: Added alarm for vm,hdd dispatchers. Added kill 471 | of process group at end of main. 472 | 473 | * src/stress.c: Removed the hog prefix from switches. 474 | 475 | * test/check_hogcpu: Minor changes. 476 | 477 | * src/stress.c: Removed bogus timeout > backoff stuff. 478 | 479 | * test/check_hogcpu: Less forks. 480 | 481 | * src/stress.c: Added timeout > backoff check. 482 | 483 | * src/stress.c: stress.c 484 | 485 | * test/check_hogcpu: Added a sleep. 486 | 487 | * doc/Makefile.am: Minor changes. 488 | 489 | * doc/Makefile.am, doc/stress.1, doc/version.texi: Re-added file. 490 | 491 | * src/stress.c: Removed kill of process group. 492 | 493 | * test/Makefile.am, test/check_hogcpu, test/check_hoghdd: Minor 494 | changes. 495 | 496 | 2002-12-10 Amos Waterland 497 | Version 0.17pre10 498 | 499 | * test/Makefile.am, test/check_hoghdd: Added file. 500 | 501 | * doc/Makefile.am: Minor changes. 502 | 503 | * COPYING, Makefile.am, src/Makefile.am, test/Makefile.am, 504 | doc/Makefile.am: Added MAINTAINERCLEANFILES variable. 505 | 506 | * test/Makefile.in, doc/texinfo.tex, src/Makefile.in, doc/fdl.texi, 507 | doc/mdate-sh, doc/stress.1, doc/stress.texi, doc/Makefile.am, 508 | doc/Makefile.in, install-sh, missing, mkinstalldirs, Makefile.in, 509 | aclocal.m4, configure: Removed files. 510 | 511 | * src/stress.c: Added backoff capability. 512 | 513 | * configure, configure.in, doc/Makefile.am, doc/Makefile.in: 514 | Minor changes. 515 | 516 | * doc/stress.texi, doc/version.texi: Added quotes of options in 517 | examples section. 518 | 519 | * src/stress.c: Implemented ignore of non-critical errors. Has the 520 | kill each process leader timeout implementation. 521 | 522 | 2002-12-08 Amos Waterland 523 | Version 0.17pre8 524 | 525 | * AUTHORS, ChangeLog, doc/stress.1, src/stress.c: Changed email 526 | address. 527 | 528 | * test/check_usage_return_code, test/check_version_return_code, 529 | test/Makefile.am, test/Makefile.in, doc/Makefile.in, doc/mdate-sh, 530 | doc/stress.texi, src/Makefile.in, src/stress.c, Makefile.in, 531 | aclocal.m4, configure, configure.in, doc/Makefile.am: Minor changes. 532 | 533 | * doc/version.texi, doc/fdl.texi, doc/stress.texi, doc/texinfo.tex: 534 | Initial add. 535 | 536 | * README: Minor wording change. 537 | 538 | * src/stress.c: Initial import after a complete rewrite. 539 | Contains ideas from Don Giuliano and Tobias Jahn 540 | . 541 | 542 | * COPYING, ChangeLog, INSTALL, Makefile.am, NEWS, README, bootstrap, 543 | configure.in, doc/Makefile.am, doc/stress.1, install-sh, missing, 544 | mkinstalldirs, src/Makefile.am, test/Makefile.am, test/check_atoll_s, 545 | test/check_usage_return_code, test/check_version_return_code: 546 | Initial import. 547 | 548 | * COPYING, ChangeLog, INSTALL, Makefile.am, NEWS, README, 549 | bootstrap, configure.in, doc/Makefile.am, doc/stress.1, 550 | install-sh, missing, mkinstalldirs, src/Makefile.am, src/stress.c, 551 | test/Makefile.am, test/check_atoll_s, test/check_usage_return_code, 552 | test/check_version_return_code: New file. 553 | 554 | * AUTHORS: Initial import. 555 | 556 | * AUTHORS: New file. 557 | 558 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /src/stress.c: -------------------------------------------------------------------------------- 1 | /* A program to put stress on a POSIX system (stress). 2 | * 3 | * Copyright 2001-2010 Amos Waterland 4 | * Copyright 2021-2023 Joao Eriberto Mota Filho 5 | * Copyright 2023 Vratislav Bendel 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "config.h" 34 | 35 | #ifdef HAVE_SYS_PRCTL_H 36 | #include 37 | #endif 38 | 39 | /* By default, print all messages of severity info and above. */ 40 | static int global_debug = 2; 41 | 42 | /* Name of this program */ 43 | static char *global_progname = PACKAGE; 44 | 45 | /* Implemention of runtime-selectable severity message printing. */ 46 | #define dbg(OUT, STR, ARGS...) if (global_debug >= 3) \ 47 | fprintf (stdout, "%s: dbug: [%lli] ", \ 48 | global_progname, (long long)getpid()), \ 49 | fprintf(OUT, STR, ##ARGS), fflush(OUT) 50 | #define out(OUT, STR, ARGS...) if (global_debug >= 2) \ 51 | fprintf (stdout, "%s: info: [%lli] ", \ 52 | global_progname, (long long)getpid()), \ 53 | fprintf(OUT, STR, ##ARGS), fflush(OUT) 54 | #define wrn(OUT, STR, ARGS...) if (global_debug >= 1) \ 55 | fprintf (stderr, "%s: WARN: [%lli] (%d) ", \ 56 | global_progname, (long long)getpid(), __LINE__), \ 57 | fprintf(OUT, STR, ##ARGS), fflush(OUT) 58 | #define err(OUT, STR, ARGS...) if (global_debug >= 0) \ 59 | fprintf (stderr, "%s: FAIL: [%lli] (%d) ", \ 60 | global_progname, (long long)getpid(), __LINE__), \ 61 | fprintf(OUT, STR, ##ARGS), fflush(OUT) 62 | 63 | /* Implementation of check for option argument correctness. */ 64 | #define assert_arg(A) \ 65 | if (++i == argc || ((arg = argv[i])[0] == '-' && \ 66 | !isdigit ((int)arg[1]) )) \ 67 | { \ 68 | err (stderr, "missing argument to option '%s'\n", A); \ 69 | exit (1); \ 70 | } 71 | 72 | /* Prototypes for utility functions. */ 73 | int usage (int status); 74 | int version (int status); 75 | long long atoll_s (const char *nptr); 76 | long long atoll_b (const char *nptr); 77 | void worker_init(void); 78 | 79 | /* Prototypes for worker functions. */ 80 | int hogcpu (void); 81 | int hogio (void); 82 | int hogvm (long long bytes, long long stride, long long hang, int keep); 83 | int hoghdd (long long bytes); 84 | 85 | int 86 | main (int argc, char **argv) 87 | { 88 | int i, pid, children = 0, retval = 0; 89 | long starttime, stoptime, runtime, forks; 90 | 91 | /* Variables that indicate which options have been selected. */ 92 | int do_dryrun = 0; 93 | long long do_backoff = 3000; 94 | long long do_timeout = 0; 95 | long long do_cpu = 0; 96 | long long do_io = 0; 97 | long long do_vm = 0; 98 | long long do_vm_bytes = 256 * 1024 * 1024; 99 | long long do_vm_stride = 4096; 100 | long long do_vm_hang = -1; 101 | int do_vm_keep = 0; 102 | long long do_hdd = 0; 103 | long long do_hdd_bytes = 1024 * 1024 * 1024; 104 | 105 | /* Record our start time. */ 106 | if ((starttime = time (NULL)) == -1) 107 | { 108 | err (stderr, "failed to acquire current time: %s\n", strerror (errno)); 109 | exit (1); 110 | } 111 | 112 | /* SuSv3 does not define any error conditions for this function. */ 113 | global_progname = basename (argv[0]); 114 | 115 | /* For portability, parse command line options without getopt_long. */ 116 | for (i = 1; i < argc; i++) 117 | { 118 | char *arg = argv[i]; 119 | 120 | if (strcmp (arg, "--help") == 0 || strcmp (arg, "-?") == 0) 121 | { 122 | usage (0); 123 | } 124 | else if (strcmp (arg, "--version") == 0) 125 | { 126 | version (0); 127 | } 128 | else if (strcmp (arg, "--verbose") == 0 || strcmp (arg, "-v") == 0) 129 | { 130 | global_debug = 3; 131 | } 132 | else if (strcmp (arg, "--quiet") == 0 || strcmp (arg, "-q") == 0) 133 | { 134 | global_debug = 0; 135 | } 136 | else if (strcmp (arg, "--dry-run") == 0 || strcmp (arg, "-n") == 0) 137 | { 138 | do_dryrun = 1; 139 | } 140 | else if (strcmp (arg, "--backoff") == 0) 141 | { 142 | assert_arg ("--backoff"); 143 | if (sscanf (arg, "%lli", &do_backoff) != 1) 144 | { 145 | err (stderr, "invalid number: %s\n", arg); 146 | exit (1); 147 | } 148 | if (do_backoff < 0) 149 | { 150 | err (stderr, "invalid backoff factor: %lli\n", do_backoff); 151 | exit (1); 152 | } 153 | dbg (stdout, "setting backoff coeffient to %llius\n", do_backoff); 154 | } 155 | else if (strcmp (arg, "--timeout") == 0 || strcmp (arg, "-t") == 0) 156 | { 157 | assert_arg ("--timeout"); 158 | do_timeout = atoll_s (arg); 159 | if (do_timeout <= 0) 160 | { 161 | err (stderr, "invalid timeout value: %llis\n", do_timeout); 162 | exit (1); 163 | } 164 | } 165 | else if (strcmp (arg, "--cpu") == 0 || strcmp (arg, "-c") == 0) 166 | { 167 | assert_arg ("--cpu"); 168 | do_cpu = atoll_b (arg); 169 | if (do_cpu <= 0) 170 | { 171 | err (stderr, "invalid number of cpu hogs: %lli\n", do_cpu); 172 | exit (1); 173 | } 174 | } 175 | else if (strcmp (arg, "--io") == 0 || strcmp (arg, "-i") == 0) 176 | { 177 | assert_arg ("--io"); 178 | do_io = atoll_b (arg); 179 | if (do_io <= 0) 180 | { 181 | err (stderr, "invalid number of io hogs: %lli\n", do_io); 182 | exit (1); 183 | } 184 | } 185 | else if (strcmp (arg, "--vm") == 0 || strcmp (arg, "-m") == 0) 186 | { 187 | assert_arg ("--vm"); 188 | do_vm = atoll_b (arg); 189 | if (do_vm <= 0) 190 | { 191 | err (stderr, "invalid number of vm hogs: %lli\n", do_vm); 192 | exit (1); 193 | } 194 | } 195 | else if (strcmp (arg, "--vm-bytes") == 0) 196 | { 197 | assert_arg ("--vm-bytes"); 198 | do_vm_bytes = atoll_b (arg); 199 | if (do_vm_bytes <= 0) 200 | { 201 | err (stderr, "invalid vm byte value: %lli\n", do_vm_bytes); 202 | exit (1); 203 | } 204 | } 205 | else if (strcmp (arg, "--vm-stride") == 0) 206 | { 207 | assert_arg ("--vm-stride"); 208 | do_vm_stride = atoll_b (arg); 209 | if (do_vm_stride <= 0) 210 | { 211 | err (stderr, "invalid stride value: %lli\n", do_vm_stride); 212 | exit (1); 213 | } 214 | } 215 | else if (strcmp (arg, "--vm-hang") == 0) 216 | { 217 | assert_arg ("--vm-hang"); 218 | do_vm_hang = atoll_b (arg); 219 | if (do_vm_hang < 0) 220 | { 221 | err (stderr, "invalid value: %lli\n", do_vm_hang); 222 | exit (1); 223 | } 224 | } 225 | else if (strcmp (arg, "--vm-keep") == 0) 226 | { 227 | do_vm_keep = 1; 228 | } 229 | else if (strcmp (arg, "--hdd") == 0 || strcmp (arg, "-d") == 0) 230 | { 231 | assert_arg ("--hdd"); 232 | do_hdd = atoll_b (arg); 233 | if (do_hdd <= 0) 234 | { 235 | err (stderr, "invalid number of hdd hogs: %lli\n", do_hdd); 236 | exit (1); 237 | } 238 | } 239 | else if (strcmp (arg, "--hdd-bytes") == 0) 240 | { 241 | assert_arg ("--hdd-bytes"); 242 | do_hdd_bytes = atoll_b (arg); 243 | if (do_hdd_bytes <= 0) 244 | { 245 | err (stderr, "invalid hdd byte value: %lli\n", do_hdd_bytes); 246 | exit (1); 247 | } 248 | } 249 | else 250 | { 251 | err (stderr, "unrecognized option: %s\n", arg); 252 | exit (1); 253 | } 254 | } 255 | 256 | /* Print startup message if we have work to do, bail otherwise. */ 257 | if (do_cpu + do_io + do_vm + do_hdd) 258 | { 259 | out (stdout, "dispatching hogs: %lli cpu, %lli io, %lli vm, %lli hdd\n", 260 | do_cpu, do_io, do_vm, do_hdd); 261 | } 262 | else 263 | usage (0); 264 | 265 | /* Round robin dispatch our worker processes. */ 266 | while ((forks = (do_cpu + do_io + do_vm + do_hdd))) 267 | { 268 | long long backoff, timeout = 0; 269 | 270 | /* Calculate the backoff value so we get good fork throughput. */ 271 | backoff = do_backoff * forks; 272 | dbg (stdout, "using backoff sleep of %llius\n", backoff); 273 | 274 | /* If we are supposed to respect a timeout, calculate it. */ 275 | if (do_timeout) 276 | { 277 | long long currenttime; 278 | 279 | /* Acquire current time. */ 280 | if ((currenttime = time (NULL)) == -1) 281 | { 282 | perror ("error acquiring current time"); 283 | exit (1); 284 | } 285 | 286 | /* Calculate timeout based on current time. */ 287 | timeout = do_timeout - (currenttime - starttime); 288 | 289 | if (timeout > 0) 290 | { 291 | dbg (stdout, "setting timeout to %llis\n", timeout); 292 | } 293 | else 294 | { 295 | wrn (stderr, "used up time before all workers dispatched\n"); 296 | break; 297 | } 298 | } 299 | 300 | if (do_cpu) 301 | { 302 | switch (pid = fork ()) 303 | { 304 | case 0: /* child */ 305 | worker_init(); 306 | alarm (timeout); 307 | usleep (backoff); 308 | if (do_dryrun) 309 | exit (0); 310 | exit (hogcpu ()); 311 | case -1: /* error */ 312 | err (stderr, "fork failed: %s\n", strerror (errno)); 313 | break; 314 | default: /* parent */ 315 | dbg (stdout, "--> hogcpu worker %lli [%i] forked\n", 316 | do_cpu, pid); 317 | ++children; 318 | } 319 | --do_cpu; 320 | } 321 | 322 | if (do_io) 323 | { 324 | switch (pid = fork ()) 325 | { 326 | case 0: /* child */ 327 | worker_init(); 328 | alarm (timeout); 329 | usleep (backoff); 330 | if (do_dryrun) 331 | exit (0); 332 | exit (hogio ()); 333 | case -1: /* error */ 334 | err (stderr, "fork failed: %s\n", strerror (errno)); 335 | break; 336 | default: /* parent */ 337 | dbg (stdout, "--> hogio worker %lli [%i] forked\n", do_io, pid); 338 | ++children; 339 | } 340 | --do_io; 341 | } 342 | 343 | if (do_vm) 344 | { 345 | switch (pid = fork ()) 346 | { 347 | case 0: /* child */ 348 | worker_init(); 349 | alarm (timeout); 350 | usleep (backoff); 351 | if (do_dryrun) 352 | exit (0); 353 | exit (hogvm (do_vm_bytes, do_vm_stride, do_vm_hang, do_vm_keep)); 354 | case -1: /* error */ 355 | err (stderr, "fork failed: %s\n", strerror (errno)); 356 | break; 357 | default: /* parent */ 358 | dbg (stdout, "--> hogvm worker %lli [%i] forked\n", do_vm, pid); 359 | ++children; 360 | } 361 | --do_vm; 362 | } 363 | 364 | if (do_hdd) 365 | { 366 | switch (pid = fork ()) 367 | { 368 | case 0: /* child */ 369 | worker_init(); 370 | alarm (timeout); 371 | usleep (backoff); 372 | if (do_dryrun) 373 | exit (0); 374 | exit (hoghdd (do_hdd_bytes)); 375 | case -1: /* error */ 376 | err (stderr, "fork failed: %s\n", strerror (errno)); 377 | break; 378 | default: /* parent */ 379 | dbg (stdout, "--> hoghdd worker %lli [%i] forked\n", 380 | do_hdd, pid); 381 | ++children; 382 | } 383 | --do_hdd; 384 | } 385 | } 386 | 387 | /* Wait for our children to exit. */ 388 | while (children) 389 | { 390 | int status, ret; 391 | 392 | if ((pid = wait (&status)) > 0) 393 | { 394 | --children; 395 | 396 | if (WIFEXITED (status)) 397 | { 398 | if ((ret = WEXITSTATUS (status)) == 0) 399 | { 400 | dbg (stdout, "<-- worker %i returned normally\n", pid); 401 | } 402 | else 403 | { 404 | err (stderr, "<-- worker %i returned error %i\n", pid, ret); 405 | ++retval; 406 | wrn (stderr, "now reaping child worker processes\n"); 407 | if (signal (SIGUSR1, SIG_IGN) == SIG_ERR) 408 | err (stderr, "handler error: %s\n", strerror (errno)); 409 | if (kill (-1 * getpid (), SIGUSR1) == -1) 410 | err (stderr, "kill error: %s\n", strerror (errno)); 411 | } 412 | } 413 | else if (WIFSIGNALED (status)) 414 | { 415 | if ((ret = WTERMSIG (status)) == SIGALRM) 416 | { 417 | dbg (stdout, "<-- worker %i signalled normally\n", pid); 418 | } 419 | else if ((ret = WTERMSIG (status)) == SIGUSR1) 420 | { 421 | dbg (stdout, "<-- worker %i reaped\n", pid); 422 | } 423 | else 424 | { 425 | err (stderr, "<-- worker %i got signal %i\n", pid, ret); 426 | ++retval; 427 | wrn (stderr, "now reaping child worker processes\n"); 428 | if (signal (SIGUSR1, SIG_IGN) == SIG_ERR) 429 | err (stderr, "handler error: %s\n", strerror (errno)); 430 | if (kill (-1 * getpid (), SIGUSR1) == -1) 431 | err (stderr, "kill error: %s\n", strerror (errno)); 432 | } 433 | } 434 | else 435 | { 436 | err (stderr, "<-- worker %i exited abnormally\n", pid); 437 | ++retval; 438 | } 439 | } 440 | else 441 | { 442 | err (stderr, "error waiting for worker: %s\n", strerror (errno)); 443 | ++retval; 444 | break; 445 | } 446 | } 447 | 448 | /* Record our stop time. */ 449 | if ((stoptime = time (NULL)) == -1) 450 | { 451 | err (stderr, "failed to acquire current time\n"); 452 | exit (1); 453 | } 454 | 455 | /* Calculate our runtime. */ 456 | runtime = stoptime - starttime; 457 | 458 | /* Print final status message. */ 459 | if (retval) 460 | { 461 | err (stderr, "failed run completed in %lis\n", runtime); 462 | } 463 | else 464 | { 465 | out (stdout, "successful run completed in %lis\n", runtime); 466 | } 467 | 468 | exit (retval); 469 | } 470 | 471 | void worker_init(void) 472 | { 473 | #ifdef HAVE_SYS_PRCTL_H 474 | if (prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) 475 | exit(0); 476 | #endif 477 | } 478 | 479 | int 480 | hogcpu (void) 481 | { 482 | while (1) 483 | sqrt (rand ()); 484 | 485 | return 0; 486 | } 487 | 488 | int 489 | hogio () 490 | { 491 | while (1) 492 | sync (); 493 | 494 | return 0; 495 | } 496 | 497 | int 498 | hogvm (long long bytes, long long stride, long long hang, int keep) 499 | { 500 | long long i; 501 | char *ptr = 0; 502 | char c; 503 | int do_malloc = 1; 504 | 505 | while (1) 506 | { 507 | if (do_malloc) 508 | { 509 | dbg (stdout, "allocating %lli bytes ...\n", bytes); 510 | if (!(ptr = (char *) malloc (bytes * sizeof (char)))) 511 | { 512 | err (stderr, "hogvm malloc failed: %s\n", strerror (errno)); 513 | return 1; 514 | } 515 | if (keep) 516 | do_malloc = 0; 517 | } 518 | 519 | dbg (stdout, "touching bytes in strides of %lli bytes ...\n", stride); 520 | for (i = 0; i < bytes; i += stride) 521 | ptr[i] = 'Z'; /* Ensure that COW happens. */ 522 | 523 | if (hang == 0) 524 | { 525 | dbg (stdout, "sleeping forever with allocated memory\n"); 526 | while (1) 527 | sleep (1024); 528 | } 529 | else if (hang > 0) 530 | { 531 | dbg (stdout, "sleeping for %llis with allocated memory\n", hang); 532 | sleep (hang); 533 | } 534 | 535 | for (i = 0; i < bytes; i += stride) 536 | { 537 | c = ptr[i]; 538 | if (c != 'Z') 539 | { 540 | err (stderr, "memory corruption at: %p\n", ptr + i); 541 | return 1; 542 | } 543 | } 544 | 545 | if (do_malloc) 546 | { 547 | free (ptr); 548 | dbg (stdout, "freed %lli bytes\n", bytes); 549 | } 550 | } 551 | 552 | return 0; 553 | } 554 | 555 | int 556 | hoghdd (long long bytes) 557 | { 558 | long long i, j; 559 | int fd; 560 | int chunk = (1024 * 1024) - 1; /* Minimize slow writing. */ 561 | char buff[chunk]; 562 | 563 | /* Initialize buffer with some random ASCII data. */ 564 | dbg (stdout, "seeding %d byte buffer with random data\n", chunk); 565 | for (i = 0; i < chunk - 1; i++) 566 | { 567 | j = rand (); 568 | j = (j < 0) ? -j : j; 569 | j %= 95; 570 | j += 32; 571 | buff[i] = j; 572 | } 573 | buff[i] = '\n'; 574 | 575 | while (1) 576 | { 577 | char name[] = "./stress.XXXXXX"; 578 | 579 | if ((fd = mkstemp (name)) == -1) 580 | { 581 | err (stderr, "mkstemp failed: %s\n", strerror (errno)); 582 | return 1; 583 | } 584 | 585 | dbg (stdout, "opened %s for writing %lli bytes\n", name, bytes); 586 | 587 | dbg (stdout, "unlinking %s\n", name); 588 | if (unlink (name) == -1) 589 | { 590 | err (stderr, "unlink of %s failed: %s\n", name, strerror (errno)); 591 | return 1; 592 | } 593 | 594 | dbg (stdout, "fast writing to %s\n", name); 595 | for (j = 0; bytes == 0 || j + chunk < bytes; j += chunk) 596 | { 597 | if (write (fd, buff, chunk) == -1) 598 | { 599 | err (stderr, "write failed: %s\n", strerror (errno)); 600 | return 1; 601 | } 602 | } 603 | 604 | dbg (stdout, "slow writing to %s\n", name); 605 | for (; bytes == 0 || j < bytes - 1; j++) 606 | { 607 | if (write (fd, &buff[j % chunk], 1) == -1) 608 | { 609 | err (stderr, "write failed: %s\n", strerror (errno)); 610 | return 1; 611 | } 612 | } 613 | if (write (fd, "\n", 1) == -1) 614 | { 615 | err (stderr, "write failed: %s\n", strerror (errno)); 616 | return 1; 617 | } 618 | ++j; 619 | 620 | dbg (stdout, "closing %s after %lli bytes\n", name, j); 621 | close (fd); 622 | } 623 | 624 | return 0; 625 | } 626 | 627 | /* Convert a string representation of a number with an optional size suffix 628 | * to a long long. 629 | */ 630 | long long 631 | atoll_b (const char *nptr) 632 | { 633 | int pos; 634 | char suffix; 635 | long long factor = 0; 636 | long long value; 637 | 638 | if ((pos = strlen (nptr) - 1) < 0) 639 | { 640 | err (stderr, "invalid string\n"); 641 | exit (1); 642 | } 643 | 644 | switch (suffix = nptr[pos]) 645 | { 646 | case 'b': 647 | case 'B': 648 | factor = 0; 649 | break; 650 | case 'k': 651 | case 'K': 652 | factor = 10; 653 | break; 654 | case 'm': 655 | case 'M': 656 | factor = 20; 657 | break; 658 | case 'g': 659 | case 'G': 660 | factor = 30; 661 | break; 662 | default: 663 | if (suffix < '0' || suffix > '9') 664 | { 665 | err (stderr, "unrecognized suffix: %c\n", suffix); 666 | exit (1); 667 | } 668 | } 669 | 670 | if (sscanf (nptr, "%lli", &value) != 1) 671 | { 672 | err (stderr, "invalid number: %s\n", nptr); 673 | exit (1); 674 | } 675 | 676 | value = value << factor; 677 | 678 | return value; 679 | } 680 | 681 | /* Convert a string representation of a number with an optional time suffix 682 | * to a long long. 683 | */ 684 | long long 685 | atoll_s (const char *nptr) 686 | { 687 | int pos; 688 | char suffix; 689 | long long factor = 1; 690 | long long value; 691 | 692 | if ((pos = strlen (nptr) - 1) < 0) 693 | { 694 | err (stderr, "invalid string\n"); 695 | exit (1); 696 | } 697 | 698 | switch (suffix = nptr[pos]) 699 | { 700 | case 's': 701 | case 'S': 702 | factor = 1; 703 | break; 704 | case 'm': 705 | case 'M': 706 | factor = 60; 707 | break; 708 | case 'h': 709 | case 'H': 710 | factor = 60 * 60; 711 | break; 712 | case 'd': 713 | case 'D': 714 | factor = 60 * 60 * 24; 715 | break; 716 | case 'y': 717 | case 'Y': 718 | factor = 60 * 60 * 24 * 365; 719 | break; 720 | default: 721 | if (suffix < '0' || suffix > '9') 722 | { 723 | err (stderr, "unrecognized suffix: %c\n", suffix); 724 | exit (1); 725 | } 726 | } 727 | 728 | if (sscanf (nptr, "%lli", &value) != 1) 729 | { 730 | err (stderr, "invalid number: %s\n", nptr); 731 | exit (1); 732 | } 733 | 734 | value = value * factor; 735 | 736 | return value; 737 | } 738 | 739 | int 740 | version (int status) 741 | { 742 | char *mesg = "%s %s\n"; 743 | 744 | fprintf (stdout, mesg, global_progname, VERSION); 745 | 746 | if (status <= 0) 747 | exit (-1 * status); 748 | 749 | return 0; 750 | } 751 | 752 | int 753 | usage (int status) 754 | { 755 | char *mesg = 756 | "`%s' imposes certain types of compute stress on your system\n\n" 757 | "Usage: %s [OPTION [ARG]] ...\n" 758 | " -?, --help show this help statement\n" 759 | " --version show version statement\n" 760 | " -v, --verbose be verbose\n" 761 | " -q, --quiet be quiet\n" 762 | " -n, --dry-run show what would have been done\n" 763 | " -t, --timeout N timeout after N seconds\n" 764 | " --backoff N wait factor of N microseconds before work starts\n" 765 | " -c, --cpu N spawn N workers spinning on sqrt()\n" 766 | " -i, --io N spawn N workers spinning on sync()\n" 767 | " -m, --vm N spawn N workers spinning on malloc()/free()\n" 768 | " --vm-bytes B malloc B bytes per vm worker (default is 256MB)\n" 769 | " --vm-stride B touch a byte every B bytes (default is 4096)\n" 770 | " --vm-hang N sleep N secs before free (default none, 0 is inf)\n" 771 | " --vm-keep redirty memory instead of freeing and reallocating\n" 772 | " -d, --hdd N spawn N workers spinning on write()/unlink()\n" 773 | " --hdd-bytes B write B bytes per hdd worker (default is 1GB)\n\n" 774 | "Example: %s --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s\n\n" 775 | "Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size).\n"; 776 | 777 | fprintf (stdout, mesg, global_progname, global_progname, global_progname); 778 | 779 | if (status <= 0) 780 | exit (-1 * status); 781 | 782 | return 0; 783 | } 784 | --------------------------------------------------------------------------------