26 #include <core/threading/thread.h> 27 #include <utils/system/signal.h> 28 #include <utils/system/argparser.h> 29 #include <utils/logging/liblogger.h> 30 #include <utils/logging/console.h> 31 #include <utils/logging/file.h> 32 #include <core/exceptions/system.h> 45 class LibLoggerQAThread :
public Thread 48 LibLoggerQAThread(
unsigned int thread_num,
unsigned int sleep_time_usec)
49 :
Thread(
"LibLoggerQAThread")
51 this->sleep_time_usec = sleep_time_usec;
52 this->thread_num = thread_num;
62 if ( (thread_num % 4) == 0 ) {
63 LibLogger::log_debug(
"LibLoggerQA",
"%u: %u (debug)", thread_num, ++i);
64 }
else if ( (thread_num % 3) == 0 ) {
65 LibLogger::log_info(
"LibLoggerQA",
"%u: %u (info)", thread_num, ++i);
66 }
else if ( (thread_num % 2) == 0 ) {
67 LibLogger::log_warn(
"LibLoggerQA",
"%u: %u (warn)", thread_num, ++i);
69 LibLogger::log_error(
"LibLoggerQA",
"%u: %u (error)", thread_num, ++i);
71 usleep(sleep_time_usec);
75 unsigned int sleep_time_usec;
76 unsigned int thread_num;
86 unsigned int sleep_time_usec = 0;
87 unsigned int num_threads = 3;
89 if ( (tmp = argp->
arg(
"s")) != NULL ) {
90 sleep_time_usec = atoi(tmp);
92 if ( (tmp = argp->
arg(
"n")) != NULL ) {
93 num_threads = atoi(tmp);
94 if ( num_threads < 0 ) {
100 for (
unsigned int i = 0; i < num_threads; ++i ) {
101 threads.push_back(
new LibLoggerQAThread(i, sleep_time_usec) );
107 for ( tit = threads.begin(); tit != threads.end(); ++tit ) {
114 virtual void handle_signal(
int signum)
116 printf(
"Signal received, cancelling threads\n");
117 for ( tit = threads.begin(); tit != threads.end(); ++tit ) {
120 printf(
"Threads cancelled\n");
125 for ( tit = threads.begin(); tit != threads.end(); ++tit ) {
128 for ( tit = threads.begin(); tit != threads.end(); ++tit ) {
134 list<Thread *> threads;
135 list<Thread *>::iterator tit;
140 main(
int argc,
char **argv)
145 cout <<
"Usage: " << argv[0] <<
"[-s n] [-n n]" << endl
146 <<
" -s n Sleep time for thres in usec" << endl
147 <<
" -h this help message" << endl
148 <<
" -n n number of threads" << endl;
152 LibLoggerQAMain m(argp);
153 SignalManager::register_handler(SIGINT, &m);
154 SignalManager::ignore(SIGPIPE);
157 LibLogger::add_logger(
new FileLogger(
"qa_utils_liblogger.log"));
162 LibLogger::finalize();
const char * arg(const char *argn)
Get argument value.
Interface for logging to a specified file.
Interface for logging to stderr.
Fawkes library namespace.
Interface for signal handling.
Parse command line arguments.
Thread class encapsulation of pthreads.
bool has_arg(const char *argn)
Check if argument has been supplied.