1
0
Fork 0

contrib: take from tuned-1.0

This commit is contained in:
Jan Vcelak 2012-03-12 14:58:12 +01:00
parent b0198fc5b7
commit 69eee29cf7
6 changed files with 913 additions and 0 deletions

156
contrib/diskdevstat Executable file
View file

@ -0,0 +1,156 @@
#!/usr/bin/stap
# Copyright (C) 2008, 2009 Red Hat, Inc.
# Authors: Phil Knirsch
#
# 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 Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
global ifavg, iflast, rtime, interval, duration, histogram
function help()
{
print(
"A simple systemtap script to record harddisk activity of processes and display\n"
"statistics for read/write operations.\n\n"
"usage: diskdevstat [update-interval] [total-duration] [display-histogram]\n\n"
" update-interval in seconds, the default is 5\n"
" total-interval in seconds, the default is 86400\n"
" display-histogram anything, unset by default\n"
);
}
probe begin
{
rtime = 0;
interval = 5;
duration = 86400;
histogram = 0;
%( $# > 0 %? interval = strtol(@1,10); %)
%( $# > 1 %? duration = strtol(@2,10); %)
%( $# > 2 %? histogram = 1; %)
if ($# >= 4 || interval <= 0 || duration <= 0) {
help();
exit();
}
}
probe vfs.write
{
if(pid() == 0 || devname == "N/A") {
next;
}
ms = gettimeofday_ms();
if(iflast[0, pid(), devname, execname(), uid()] == 0) {
iflast[0, pid(), devname, execname(), uid()] = ms;
} else {
diff = ms - iflast[0, pid(), devname, execname(), uid()];
iflast[0, pid(), devname, execname(), uid()] = ms;
ifavg[0, pid(), devname, execname(), uid()] <<< diff;
}
}
probe vfs.read
{
if(pid() == 0 || devname == "N/A") {
next;
}
ms = gettimeofday_ms();
if(iflast[1, pid(), devname, execname(), uid()] == 0) {
iflast[1, pid(), devname, execname(), uid()] = ms;
} else {
diff = ms - iflast[1, pid(), devname, execname(), uid()];
iflast[1, pid(), devname, execname(), uid()] = ms;
ifavg[1, pid(), devname, execname(), uid()] <<< diff;
}
}
function print_activity()
{
printf("\033[2J\033[1;1H")
printf("%5s %5s %-7s %9s %9s %9s %9s %9s %9s %9s %9s %-15s\n",
"PID", "UID", "DEV", "WRITE_CNT", "WRITE_MIN", "WRITE_MAX",
"WRITE_AVG", "READ_CNT", "READ_MIN", "READ_MAX", "READ_AVG",
"COMMAND")
foreach ([type, pid, dev, exec, uid] in ifavg-) {
nxmit = @count(ifavg[0, pid, dev, exec, uid])
nrecv = @count(ifavg[1, pid, dev, exec, uid])
write_min = nxmit ? @min(ifavg[0, pid, dev, exec, uid]) : 0
write_max = nxmit ? @max(ifavg[0, pid, dev, exec, uid]) : 0
write_avg = nxmit ? @avg(ifavg[0, pid, dev, exec, uid]) : 0
read_min = nrecv ? @min(ifavg[1, pid, dev, exec, uid]) : 0
read_max = nrecv ? @max(ifavg[1, pid, dev, exec, uid]) : 0
read_avg = nrecv ? @avg(ifavg[1, pid, dev, exec, uid]) : 0
if(type == 0 || nxmit == 0) {
printf("%5d %5d %-7s %9d %5d.%03d %5d.%03d %5d.%03d",
pid, uid, dev, nxmit,
write_min/1000, write_min%1000,
write_max/1000, write_max%1000,
write_avg/1000, write_avg%1000)
printf(" %9d %5d.%03d %5d.%03d %5d.%03d %-15s\n",
nrecv,
read_min/1000, read_min%1000,
read_max/1000, read_max%1000,
read_avg/1000, read_avg%1000,
exec)
}
}
print("\n")
}
function print_histogram()
{
foreach ([type, pid, dev, exec, uid] in ifavg-) {
nxmit = @count(ifavg[0, pid, dev, exec, uid])
nrecv = @count(ifavg[1, pid, dev, exec, uid])
if (type == 0 || nxmit == 0) {
printf("%5d %5d %-7s %-15s\n", pid, uid, dev, exec)
if (nxmit > 0) {
printf(" WRITE histogram\n")
print(@hist_log(ifavg[0, pid, dev, exec, uid]))
}
if (nrecv > 0) {
printf(" READ histogram\n")
print(@hist_log(ifavg[1, pid, dev, exec, uid]))
}
}
}
}
probe timer.s(1)
{
rtime = rtime + 1;
if (rtime % interval == 0) {
print_activity()
}
if (rtime >= duration) {
exit();
}
}
probe end, error
{
if (histogram == 1) {
print_histogram();
}
exit();
}

84
contrib/malloc_trim_ldp.c Normal file
View file

@ -0,0 +1,84 @@
/*
* malloc_trim_ldp: A ld-preload library that can be used to potentially
* save memory (especially for long running larger apps).
*
* Copyright (C) 2008, 2009 Red Hat, Inc.
* Authors: Phil Knirsch
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* To compile:
* gcc -Wall -fPIC -shared -lpthread -o malloc_trim_ldp.o malloc_trim_ldp.c
*
* To install:
* For a single app:
* LD_PRELOAD=./malloc_trim_ldp.o application
*
* Systemwide:
* cp malloc_trim_ldp.o /lib
* echo "/lib/malloc_trim_ldp.o" >> /etc/ld.so.preload
*
* How it works:
* This ld-preload library simply redirects the glibc free() call to a new
* one that simply has a static counter and every 10.000 free() calls will
* call malloc_trim(0) which goes through the heap of an application and
* basically releases pages that aren't in use anymore using madvise().
*
*/
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <pthread.h>
static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
static int malloc_trim_count=0;
static void mymalloc_install (void);
static void mymalloc_uninstall (void);
static void (*old_free_hook) (void *, const void *);
static void myfree(void *ptr, const void *caller)
{
pthread_mutex_lock(&mymutex);
malloc_trim_count++;
if(malloc_trim_count%10000 == 0) {
malloc_trim(0);
}
mymalloc_uninstall();
free(ptr);
mymalloc_install();
pthread_mutex_unlock(&mymutex);
}
static void mymalloc_install (void)
{
old_free_hook = __free_hook;
__free_hook = myfree;
}
static void mymalloc_uninstall (void)
{
__free_hook = old_free_hook;
}
void (*__malloc_initialize_hook) (void) = mymalloc_install;

158
contrib/netdevstat Executable file
View file

@ -0,0 +1,158 @@
#!/usr/bin/stap
# Copyright (C) 2008, 2009 Red Hat, Inc.
# Authors: Phil Knirsch
#
# 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:
#
# Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
global ifavg, iflast, rtime, interval, duration, histogram
function help()
{
print(
"A simple systemtap script to record network activity of processes and display\n"
"statistics for transmit/receive operations.\n\n"
"usage: netdevstat [update-interval] [total-duration] [display-histogram]\n\n"
" update-interval in seconds, the default is 5\n"
" total-interval in seconds, the default is 86400\n"
" display-histogram anything, unset by default\n"
);
}
probe begin
{
rtime = 0;
interval = 5;
duration = 86400;
histogram = 0;
%( $# > 0 %? interval = strtol(@1,10); %)
%( $# > 1 %? duration = strtol(@2,10); %)
%( $# > 2 %? histogram = 1; %)
if ($# >= 4 || interval <= 0 || duration <= 0) {
help();
exit();
}
}
probe netdev.transmit
{
if(pid() == 0) {
next;
}
ms = gettimeofday_ms();
if(iflast[0, pid(), dev_name, execname(), uid()] == 0) {
iflast[0, pid(), dev_name, execname(), uid()] = ms;
} else {
diff = ms - iflast[0, pid(), dev_name, execname(), uid()];
iflast[0, pid(), dev_name, execname(), uid()] = ms;
ifavg[0, pid(), dev_name, execname(), uid()] <<< diff;
}
}
probe netdev.receive
{
if(pid() == 0) {
next;
}
ms = gettimeofday_ms();
if(iflast[1, pid(), dev_name, execname(), uid()] == 0) {
iflast[1, pid(), dev_name, execname(), uid()] = ms;
} else {
diff = ms - iflast[1, pid(), dev_name, execname(), uid()];
iflast[1, pid(), dev_name, execname(), uid()] = ms;
ifavg[1, pid(), dev_name, execname(), uid()] <<< diff;
}
}
function print_activity()
{
printf("\033[2J\033[1;1H")
printf("%5s %5s %-7s %9s %9s %9s %9s %9s %9s %9s %9s %-15s\n",
"PID", "UID", "DEV",
"XMIT_CNT", "XMIT_MIN", "XMIT_MAX", "XMIT_AVG",
"RECV_CNT", "RECV_MIN", "RECV_MAX", "RECV_AVG",
"COMMAND")
foreach ([type, pid, dev, exec, uid] in ifavg-) {
nxmit = @count(ifavg[0, pid, dev, exec, uid])
nrecv = @count(ifavg[1, pid, dev, exec, uid])
xmit_min = nxmit ? @min(ifavg[0, pid, dev, exec, uid]) : 0
xmit_max = nxmit ? @max(ifavg[0, pid, dev, exec, uid]) : 0
xmit_avg = nxmit ? @avg(ifavg[0, pid, dev, exec, uid]) : 0
recv_min = nrecv ? @min(ifavg[1, pid, dev, exec, uid]) : 0
recv_max = nrecv ? @max(ifavg[1, pid, dev, exec, uid]) : 0
recv_avg = nrecv ? @avg(ifavg[1, pid, dev, exec, uid]) : 0
if(type == 0 || nxmit == 0) {
printf("%5d %5d %-7s %9d %5d.%03d %5d.%03d %5d.%03d ",
pid, uid, dev, nxmit,
xmit_min/1000, xmit_min%1000,
xmit_max/1000, xmit_max%1000,
xmit_avg/1000, xmit_avg%1000)
printf("%9d %5d.%03d %5d.%03d %5d.%03d %-15s\n",
nrecv,
recv_min/1000, recv_min%1000,
recv_max/1000, recv_max%1000,
recv_avg/1000, recv_avg%1000,
exec)
}
}
print("\n")
}
function print_histogram()
{
foreach ([type+, pid, dev, exec, uid] in ifavg) {
nxmit = @count(ifavg[0, pid, dev, exec, uid])
nrecv = @count(ifavg[1, pid, dev, exec, uid])
if (type == 0 || nxmit == 0) {
printf("%5d %5d %-7s %-15s\n", pid, uid, dev, exec)
if (nxmit > 0) {
printf(" WRITE histogram\n")
print(@hist_log(ifavg[0, pid, dev, exec, uid]))
}
if (nrecv > 0) {
printf(" READ histogram\n")
print(@hist_log(ifavg[1, pid, dev, exec, uid]))
}
}
}
}
probe timer.s(1)
{
rtime = rtime + 1;
if (rtime % interval == 0) {
print_activity()
}
if (rtime >= duration) {
exit();
}
}
probe end, error
{
if (histogram == 1) {
print_histogram();
}
exit();
}

208
contrib/scomes Executable file
View file

@ -0,0 +1,208 @@
#!/usr/bin/stap
# ===================================================================
# Do this when we have started
global report_period = 0
# For watch_forked variable:
# 0 = watch only main thread
# 1 = watch forked with same execname as well
# 2 = watch all forked processes
global watch_forked = 2
probe begin {
if ($# == 1) {
report_period = $1
}
print("Collecting data...\n")
printf("... for pid %d - %s\n", target(), pid2execname(target()))
}
# ===================================================================
# Define helper function for printing results
function compute_score() {
# new empirical formula that was proposed by Vratislav Podzimek <vpodzime@redhat.com> in his bachelor thesis
return syscalls + (poll_timeout + epoll_timeout + select_timeout + itimer_timeout + nanosleep_timeout + futex_timeout + signal_timeout) * 4 + (reads + writes) / 5000 + (ifxmit + ifrecv) * 25
}
function print_status() {
printf("-----------------------------------\n")
###target_set_report()
printf("Monitored process: %d (%s)\n", target(), pid2execname(target()))
printf("Number of syscalls: %d\n", syscalls)
printf("Kernel/Userspace ticks: %d/%d (%d)\n", kticks, uticks, kticks+uticks)
printf("Read/Written bytes (from/to devices): %d/%d (%d)\n", reads, writes, reads+writes)
printf("Read/Written bytes (from/to N/A device): %d/%d (%d)\n", reads_c, writes_c, reads_c+writes_c)
printf("Transmitted/Recived bytes: %d/%d (%d)\n", ifxmit, ifrecv, ifxmit+ifrecv)
printf("Polling syscalls: %d\n", poll_timeout+epoll_timeout+select_timeout+itimer_timeout+nanosleep_timeout+futex_timeout+signal_timeout)
printf("SCORE: %d\n", compute_score())
}
# ===================================================================
# Define helper function for comparing if this is relevant pid
# and for watching if our watched pid forked
# ... from http://sourceware.org/systemtap/wiki/systemtapstarters
global PIDS = 1 # as target() is already running
function is_watched(p) {
if ( (watch_forked == 0 && p == target()) || (watch_forked == 1 && target_set_pid(p) && pid2execname(target()) == pid2execname(p)) || (watch_forked == 2 && target_set_pid(p)) ) {
#printf("Process %d is relevant to process %d\n", p, target())
return 1 # yes, we are watching this pid
} else {
return 0 # no, we are not watching this pid
}
}
# Add a relevant forked process to the list of watched processes
probe kernel.function("do_fork") {
#printf("Fork of %d (%s) detected\n", pid(), execname())
if (is_watched(pid())) {
#printf("Proces %d forked\n", pid())
PIDS = PIDS + 1
#printf("Currently watching %d pids (1 just added)\n", PIDS)
}
}
# Remove pid from the list of watched pids and print report when
# all relevant processes ends
probe syscall.exit {
if (is_watched(pid())) {
#printf("Removing process %d\n", pid())
PIDS = PIDS - 1
}
#printf("Currently watching %d pids (1 just removed)\n", PIDS)
if (PIDS == 0) {
printf("-----------------------------------\n")
printf("LAST RESULTS:\n")
print_status()
exit()
}
}
# ===================================================================
# Check all syscalls
# ... from syscalls_by_pid.stp
global syscalls
probe syscall.* {
if (is_watched(pid())) {
syscalls++
#printf ("%s(%d) syscall %s\n", execname(), pid(), name)
}
}
# ===================================================================
# Check read/written bytes
# ... from disktop.stp
global reads, writes, reads_c, writes_c
probe vfs.read.return {
if (is_watched(pid()) && $return>0) {
if (devname!="N/A") {
reads += $return
} else {
reads_c += $return
}
}
}
probe vfs.write.return {
if (is_watched(pid()) && $return>0) {
if (devname!="N/A") {
writes += $return
} else {
writes_c += $return
}
}
}
# ===================================================================
# Check kernel and userspace CPU ticks
# ... from thread-times.stp
global kticks, uticks
probe timer.profile {
if (is_watched(pid())) {
if (!user_mode())
kticks++
else
uticks++
}
}
# ===================================================================
# Check polling
# ... from timeout.stp
global poll_timeout, epoll_timeout, select_timeout, itimer_timeout
global nanosleep_timeout, futex_timeout, signal_timeout
global to
probe syscall.poll, syscall.epoll_wait {
if (timeout) to[pid()]=timeout
}
probe syscall.poll.return {
if ($return == 0 && is_watched(pid()) && to[pid()] > 0) {
poll_timeout++
delete to[pid()]
}
}
probe syscall.epoll_wait.return {
if ($return == 0 && is_watched(pid()) && to[pid()] > 0) {
epoll_timeout++
delete to[pid()]
}
}
probe syscall.select.return {
if ($return == 0 && is_watched(pid())) {
select_timeout++
}
}
probe syscall.futex.return {
if ($return == 0 && is_watched(pid()) && errno_str($return) == "ETIMEDOUT") {
futex_timeout++
}
}
probe syscall.nanosleep.return {
if ($return == 0 && is_watched(pid())) {
nanosleep_timeout++
}
}
probe kernel.function("it_real_fn") {
if (is_watched(pid())) {
itimer_timeout++
}
}
probe syscall.rt_sigtimedwait.return {
if (is_watched(pid()) && errno_str($return) == "EAGAIN") {
signal_timeout++
}
}
# ===================================================================
# Check network traffic
# ... from nettop.stp
global ifxmit, ifrecv
probe netdev.transmit {
if (is_watched(pid()) && dev_name!="lo") {
ifxmit += length
}
}
probe netdev.receive {
if (is_watched(pid()) && dev_name!="lo") {
ifrecv += length
}
}
# ===================================================================
# Print report each X seconds
global counter
probe timer.s(1) {
if (report_period != 0) {
counter++
if (counter == report_period) {
print_status()
counter = 0
}
}
}
# ===================================================================
# Print quit message
probe end {
printf("-----------------------------------\n")
printf("LAST RESULTS:\n")
print_status()
printf("-----------------------------------\n")
printf("QUITTING\n")
printf("-----------------------------------\n")
}

209
contrib/varcpuload.c Normal file
View file

@ -0,0 +1,209 @@
/*
* varcpuload: Simple tool to create reproducable artifical sustained load on
* a machine.
*
* Copyright (C) 2008, 2009 Red Hat, Inc.
* Authors: Phil Knirsch
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Usage: varcpuload [-t time] [-n numcpu] [LOAD | MINLOAD MAXLOAD INCREASE]
* LOAD, MINLOAD and MAXLOAD need to be between 1 and 100.
*
* To compile:
* gcc -Wall -Os varcpuload.c -o varcpuload -lpthread
*
* To measure load:
* 1st terminal:
* for i in `seq 1 2 100`; do ./varcpuload -t 55 -n `/usr/bin/getconf _NPROCESSORS_ONLN` $i; done
* or better
* ./varcpuload -t 60 -n `/usr/bin/getconf _NPROCESSORS_ONLN` 1 100 2; done
* 2nd terminal:
* rm -f results; for i in `seq 1 2 100`; do powertop -d -t 60 >> results; done
*
* make sure the machine is otherwise idle, so start the machine initlevel 3 or even 1
* and stop every unecessary service.
*
*/
#include <getopt.h>
#include <sys/time.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#define handle_error_en(en, msg) \
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
#define ARRSIZE 512
int sleeptime = 0;
int duration = 60;
int load = 100;
void usage() {
fprintf(stderr, "Usage: varload [-t time] [-n numcpu] [LOAD | MINLOAD MAXLOAD INCREASE]\n");
fprintf(stderr, "LOAD, MINLOAD and MAXLOAD need to be between 1 and 100.\n");
}
int worker(void) {
int i, j;
float array[ARRSIZE][ARRSIZE];
for (i = 0; i < ARRSIZE; i++) {
for (j = 0; j < ARRSIZE; j++) {
array[i][j] = (float)(i + j) / (float)(i + 1);
}
}
return (int)array[1][1];
}
int timeDiff(struct timeval *tv1, struct timeval *tv2) {
return (tv2->tv_sec - tv1->tv_sec) * 1000000 + tv2->tv_usec - tv1->tv_usec;
}
int getWorkerTime() {
int cnt, i;
struct timeval tv1, tv2;
cnt = 0;
gettimeofday(&tv1, NULL);
gettimeofday(&tv2, NULL);
// Warmup of 1 sec
while (1000000 > timeDiff(&tv1, &tv2)) {
i = worker();
usleep(1);
gettimeofday(&tv2, NULL);
}
gettimeofday(&tv1, NULL);
gettimeofday(&tv2, NULL);
// Meassure for 4 sec
while (4*1000000 > timeDiff(&tv1, &tv2)) {
i = worker();
usleep(0);
gettimeofday(&tv2, NULL);
cnt++;
}
return timeDiff(&tv1, &tv2)/cnt;
}
static void * runWorker(void *arg) {
int i;
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
gettimeofday(&tv2, NULL);
while (duration > timeDiff(&tv1, &tv2)) {
i = worker();
usleep(sleeptime);
gettimeofday(&tv2, NULL);
}
return NULL;
}
int main(int argc, char *argv[]) {
int wtime, numcpu, opt, s, i;
int minload, maxload, loadinc;
pthread_attr_t attr;
pthread_t *tid;
void *res;
numcpu = 1;
while ((opt = getopt(argc, argv, "t:n:")) != -1) {
switch (opt) {
case 't':
duration = atoi(optarg);
break;
case 'n':
numcpu = atoi(optarg);
break;
default: /* '?' */
usage();
exit(EXIT_FAILURE);
}
}
loadinc = 1;
switch (argc - optind) {
case 0:
minload = 100;
maxload = 100;
break;
case 1:
minload = atoi(argv[optind]);
maxload = minload;
break;
case 3:
minload = atoi(argv[optind]);
maxload = atoi(argv[optind + 1]);
loadinc = atoi(argv[optind + 2]);
break;
default: /* '?' */
usage();
exit(EXIT_FAILURE);
}
if (minload < 1 || maxload < 1 || minload > 100 || maxload > 100) {
usage();
exit(EXIT_FAILURE);
}
wtime = getWorkerTime();
duration *= 1000000;
for (load = minload; load <= maxload; load += loadinc) {
sleeptime = wtime * 100 / load - wtime;
printf("Starting %d sec run with\n", duration / 1000000);
printf("Load: %d\n", load);
printf("Worker time: %d\n", wtime);
printf("Sleep time: %d\n", sleeptime);
printf("Nr. of CPUs to run on: %d\n", numcpu);
s = pthread_attr_init(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_init");
tid = malloc(sizeof(pthread_t) * numcpu);
if (tid == NULL)
handle_error("malloc");
for (i = 0; i<numcpu; i++) {
s = pthread_create(&tid[i], &attr, &runWorker, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
}
s = pthread_attr_destroy(&attr);
if (s != 0)
handle_error_en(s, "pthread_attr_destroy");
for (i = 0; i < numcpu; i++) {
s = pthread_join(tid[i], &res);
if (s != 0)
handle_error_en(s, "pthread_join");
}
free(tid);
}
exit(EXIT_SUCCESS);
}

98
contrib/varnetload Executable file
View file

@ -0,0 +1,98 @@
#!/usr/bin/python
#
# varnetload: A python script to create reproducable sustained network traffic
#
# Usage: varnetload [-d delay in milliseconds] [-t runtime in seconds] [-u URL]
#
# Howto use it:
# - In order to effectively use it you need to have a http server in your local
# LAN where you can put files.
# - Upload a large HTML (or any other kind of file) to the http server.
# - Use the -u option of the script to point to that URL
# - Play with the delay option to vary the load put on your network. Typical
# useful values range from 0 to 500.
#
# Copyright (C) 2009 Red Hat, Inc.
# Authors: Phil Knirsch
#
# 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:
#
# Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import time, getopt, sys
from urllib2 import *
def usage():
print("Usage: varnetload [-d delay in milliseconds] [-t runtime in seconds] [-u URL]")
delay = 1000.0
rtime = 60.0
url = "http://myhost.mydomain/index.html"
try:
opts, args = getopt.getopt(sys.argv[1:], "d:t:u:")
except getopt.error, e:
print("Error parsing command-line arguments: %s" % e)
usage()
sys.exit(1)
for (opt, val) in opts:
if opt == '-d':
delay = float(val)
elif opt == '-t':
rtime = float(val)
elif opt == '-u':
url = val
else:
print("Unknown option: %s" % opt)
usage()
sys.exit(1)
endtime = time.time() + rtime
delay = float(delay)/1000.0
try:
count = 0
while(time.time() < endtime):
if (delay < 0.01):
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
count += 9
urlopen(url).read(409600)
time.sleep(delay)
count += 1
except URLError, e:
print("Downloading failed: %s" % e.reason)
sys.exit(2)
print("Finished varnetload. Received %d pages in %d seconds" % (count, rtime))