63 #define MAX_THREADS 100 105 printf(
"Usage: %s [options]\n", prog_name);
106 printf(
"Test application for stress testing the daemon with multiple processes and threads.\n");
107 printf(
"%s\n", version);
108 printf(
"Options (Default):\n");
109 printf(
" -m number Number of messages per thread to send. (%d)\n", defaults.
nmsgs);
110 printf(
" -p number Number of processes to start. (%d), Max %d.\n", defaults.
nprocs,
MAX_PROCS);
111 printf(
" -t number Number of threads per process. (%d), Max %d.\n", defaults.
nthreads,
MAX_THREADS);
112 printf(
" -d delay Delay in milliseconds to wait between log messages. (%d)\n", defaults.
delay);
113 printf(
" -f delay Random fudge in milliseconds to add to delay. (%d)\n", defaults.
delay_fudge);
123 params->
delay = 1000;
134 while ((c = getopt (argc, argv,
"m:p:t:d:f:")) != -1)
139 params->
nmsgs = atoi(optarg);
142 params->
nprocs = atoi(optarg);
145 fprintf(stderr,
"Too many processes selected.\n");
153 fprintf(stderr,
"Too many threads selected.\n");
158 params->
delay = atoi(optarg);
164 if(optopt ==
'n' || optopt ==
'd' || optopt ==
'f')
166 fprintf(stderr,
"Option -%c requires an argument.\n", optopt);
168 else if(isprint(optopt))
170 fprintf(stderr,
"Unknown option '-%c'.\n", optopt);
174 fprintf(stderr,
"Unknown option character '\\x%x'.\n", optopt);
189 int main(
int argc,
char **argv)
194 if(
read_cli(¶ms, argc, argv) != 0) {
204 signal(SIGINT, SIG_IGN);
206 signal(SIGHUP, SIG_IGN);
208 signal(SIGTERM, SIG_IGN);
210 printf(
"Setup done. Listening. My pid: %d\n", getpid());
227 for(i=0;i<params.
nprocs;i++)
235 fprintf(stderr,
"Could not allocate resources for child process.\n");
241 fprintf(stderr,
"Could not allocate memory for child process' kernel structure.\n");
268 signal(signum, SIG_DFL);
280 kill(
pids[i], SIGINT);
292 return (delay+rand()%fudge)*1000;
305 snprintf(ctid,5,
"%.2x", rand() & 0x0000ffff);
306 snprintf(ctid_name,256,
"Child %s in dlt-test-multi-process", ctid);
310 while(msgs_left-- > 0)
331 snprintf(apid,5,
"MT%02u",
pidcount);
332 snprintf(apid_name,256,
"Apps %s.", apid);
336 thread_data.
params = params;
340 if(pthread_create(&(thread[i]),
NULL, (
void *) &
do_logging, &thread_data) != 0)
342 printf(
"Error creating thread.\n");
349 pthread_join(thread[i],
NULL);
367 pid_t w = waitpid(WAIT_ANY, &status, 0);
#define DLT_UNREGISTER_APP()
void do_forks(s_parameters params)
void do_logging(s_thread_data *data)
time_t mksleep_time(int delay, int fudge)
static char data[kDataSize]
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
int main(int argc, char **argv)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_UNREGISTER_CONTEXT(CONTEXT)
volatile sig_atomic_t in_handler
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
int read_cli(s_parameters *params, int argc, char **argv)
void run_threads(s_parameters params)
void dlt_get_version(char *buf, size_t size)
void init_params(s_parameters *params)
void quit_handler(int signum)
void usage(char *prog_name)