void katuyou(FILE *fp_out) { FILE *fp; char cur_path[FILENAME_MAX]; char juman_path[FILENAME_MAX]; char katuyoufile_path[FILENAME_MAX]; getpath(cur_path, juman_path); while (1) { if ((fp = pathfopen(KATUYOUFILE, "r", "", katuyoufile_path)) != NULL) break; if ((fp = pathfopen(KATUYOUFILE, "r", cur_path, katuyoufile_path)) != NULL) break; if ((fp = pathfopen(KATUYOUFILE, "r", juman_path, katuyoufile_path)) != NULL) break; if ((fp = pathfopen(KATUYOUFILE, "r", "../dic/", katuyoufile_path)) /* for compilation */ != NULL) break; error(OpenError, "can't open", katuyoufile_path, ".", EOA); } if (fp_out != NULL) { print_current_time(fp_out); fprintf(fp_out, "%s parsing... ", katuyoufile_path); } initialize_type_form(); read_type_form(fp); if (fp_out != NULL) fputs("done.\n\n", fp_out); fclose(fp); }
static void testdelay_exit(void) { printk(KERN_ALERT ".................\n"); print_current_time(0); printk(KERN_ALERT "testdelay is exited!\n"); printk(KERN_ALERT "..................\n"); }
static void my_tasklet_func(unsigned long data){ printk(KERN_ALERT"==============\n"); print_current_time(0); printk(KERN_ALERT"my tasklet function is called!...\n"); printk(KERN_ALERT"parameter data is %ld\n", data); printk(KERN_ALERT"==============\n"); }
static int testtasklet_init(void){ printk(KERN_ALERT"interrupt top half\n"); print_current_time(0); tasklet_schedule(&mytasklet); return 0; }
void print_fun(FILE *out, ChordServer *srv, char *fun_name, chordID *id) { fprintf(out, "%s: ", fun_name); print_chordID(out, &srv->node.id); fprintf(out, " > "); print_chordID(out, id); print_current_time(out, " @ ", ""); }
void ClockPrintTask_Start() { while (TimeSeconds() < 4) { print_current_time(); DelaySeconds(1); } robprintfbusy((const unsigned char *)"ClockPrintTask Exit\n"); Exit(); }
void print_send(FILE *out, ChordServer *srv, char *send_type, chordID *id, in6_addr *addr, ushort port) { //int i = TYPE_LEN - strlen(send_type); //fprintf(out, "[%s]", send_type); //if (i > 0) for (; i; i--) fprintf(out, " "); fprintf(out, "("); print_chordID(out, id); fprintf(out, ") "); print_node(out, &srv->node); if (addr == NULL) fprintf(out, " -----> <,>"); else fprintf(out, " -----> <%s, %d>", v6addr_to_str(addr), port); print_current_time(out, " Time:", ""); }
/* running in print live mode */ void running_print_live() { int print_num = 1, re_p_hdr = 0; collect_record(); /* print header */ print_header(); /* set struct module fields */ init_module_fields(); /* skip first record */ if (collect_record_stat() == 0) { do_debug(LOG_INFO, "collect_record_stat warn\n"); } sleep(conf.print_interval); /* print live record */ while (1) { collect_record(); if (!((print_num) % DEFAULT_PRINT_NUM) || re_p_hdr) { /* get the header will print every DEFAULT_PRINT_NUM */ print_header(); re_p_hdr = 0; print_num = 1; } if (!collect_record_stat()) { re_p_hdr = 1; continue; } /* print current time */ print_current_time(); print_record(); print_num++; /* sleep every interval */ sleep(conf.print_interval); } }
/* running in print live mode */ void running_print_live() {//实时隔一会打印一行数据。 int print_num = 1, re_p_hdr = 0; collect_record(); /* print header */ print_header(); /* set struct module fields */ init_module_fields(); /* skip first record */ if (collect_record_stat() == 0) { do_debug(LOG_INFO, "collect_record_stat warn\n"); } sleep(conf.print_interval); /* print live record */ while (1) { collect_record();//调用各个模块的回调函数,获取一次当前的数据,字符串形式保存在mod->record中。 if (!((print_num) % DEFAULT_PRINT_NUM) || re_p_hdr) { /* get the header will print every DEFAULT_PRINT_NUM */ print_header(); re_p_hdr = 0; print_num = 1; } if (!collect_record_stat()) {//解析mod->record里面的数据,放入st_array中,以备打印 re_p_hdr = 1; continue; } /* print current time */ print_current_time(); print_record();//打印st_array里面的数据 print_num++; /* sleep every interval */ sleep(conf.print_interval);//睡会。 } }
void *Task_2( void *argument ) { int status; /* send SIGUSR1 to Init which is waiting on SIGUSR1 */ print_current_time( "Task_2: ", "" ); puts( "Task_1: pthread_kill - SIGUSR1 to Init" ); status = pthread_kill( Init_id, SIGUSR1 ); assert( !status ); pthread_exit( NULL ); /* switch to Init */ return NULL; /* just so the compiler thinks we returned something */ }
void *Task_1_through_3( void *argument ) { unsigned int seconds; int i; int status; for ( i=0 ; i<5 ; i++ ) { print_current_time( "Task1: ", "" ); status = pthread_kill( Init_id, SIGUSR1 ); rtems_test_assert( !status ); seconds = sleep( 1 ); rtems_test_assert( !seconds ); } puts( "*** END OF POSIX TEST 2 ***" ); rtems_test_exit( 0 ); return NULL; /* just so the compiler thinks we returned something */ }
void print_process(FILE *out, ChordServer *srv, char *process_type, chordID *id, in6_addr *addr, ushort port) { #define TYPE_LEN 16 //int i = TYPE_LEN - strlen(process_type); //fprintf(out, "[%s]", process_type); //if (i > 0) for (; i; i--) fprintf(out, " "); fprintf(out, "("); if (id) print_chordID(out, id); else fprintf(out, "null"); fprintf(out, ") "); print_node(out, &srv->node); if (addr == NULL) fprintf(out, " <----- <,>"); else fprintf(out, " <----- <%s, %d>", v6addr_to_str(addr), port); print_current_time(out, " Time:", ""); }
int main(int argc, char **argv) { init_needle(argc > 1 ? argv[1] : "GCAACGAGTGTCTTTG"); #ifdef DNA_DEBUG printf("Looking for %s\n", needle); #endif struct timeval start_time; print_current_time(&start_time); printf(" START\n"); bufindex_t input_size = 3000000000L; size_t page_size = sysconf(_SC_PAGESIZE); ASSERT_NOT(page_size & (page_size - 1), "Page is not a power of 2"); size_t mask = page_size - 1; size_t mem_size = (input_size | mask) + 1; buflen_t buf_size = page_size << 14; #ifdef DNA_DEBUG printf("Buf size = %u\n", buf_size);; #endif init_threads(); ALGO_PREPARE #ifdef DNA_DEBUG long io_time, waiting_time; struct timeval tx, ty, tz; print_current_time(&tx); printf(" Start reading data\n"); #endif int fd = 0; if (argc > 2 && (fd = open(argv[2], O_RDONLY)) == -1) ERROR_OCCURRED("open"); char *mapped_file = mmap(NULL, mem_size, PROT_READ, MAP_SHARED, fd, 0); if (fd > 0 && close(fd) == -1) ERROR_OCCURRED("close"); char *buf; bufindex_t start; buflen_t bytes_read; buflen_t len = buf_size + needle_len - 1; for (start = 0, buf = mapped_file; start < input_size; start += buf_size, buf += buf_size) { bytes_read = (start + len < input_size) ? len : input_size - start; job_t *job = malloc(sizeof(job_t)); job->buf = buf; job->len = bytes_read; job->offset = start; submit_job(job); } #ifdef DNA_DEBUG print_current_time(&ty); printf(" End submitting jobs\n"); io_time = calc_elapsed_time(&tx, &ty); #endif wait_jobs_completed(); munmap(mapped_file, mem_size); #ifdef DNA_DEBUG gettimeofday(&tz, NULL); waiting_time = calc_elapsed_time(&ty, &tz); #endif destroy_threads(); ALGO_FREE struct timeval end_time; print_current_time(&end_time); printf(" FINISH\n"); #ifdef DNA_DEBUG print_elapsed_time(&start_time, &end_time); printf("I/O: %ld\n", io_time); printf("Waiting: %ld\n", waiting_time); #endif return 0; }
void main_task ( uint_32 initial_data ) { DATE_STRUCT time_rtc; TIME_STRUCT time_mqx; if (_lwevent_create(&lwevent,0) != MQX_OK) { printf("\nMake event failed"); _task_block(); } printf ("\fStart time (MQX synchronized to RTC time during bsp init):\n\n"); /* initialize time */ time_rtc.YEAR = 2010; time_rtc.MONTH = 10; time_rtc.DAY = 15; time_rtc.HOUR = 10; time_rtc.MINUTE = 8; time_rtc.SECOND = 0; time_rtc.MILLISEC = 0; _time_from_date (&time_rtc, &time_mqx); _time_set( &time_mqx); if( _rtc_sync_with_mqx(FALSE) != MQX_OK ) { printf("\nError synchronize time!\n"); _task_block(); } _time_get (&time_mqx); _time_to_date (&time_mqx, &time_rtc); print_mqx_time(&time_rtc, &time_mqx); print_current_time(); /* except MPC5125 */ #ifndef BSP_TWRMPC5125 install_interrupt(); /* enable stopwatch */ install_stopwatch(); /* enable alarm */ install_alarm(); _lwevent_wait_ticks(&lwevent,LWE_ALARM,FALSE,0); _lwevent_clear(&lwevent,LWE_ALARM); printf ("\nALARM!\n"); print_current_time(); /* end of alarm */ printf ("Continue wasting time (2 minutes max) ...\n"); _lwevent_wait_ticks(&lwevent,LWE_STOPWATCH,FALSE,0); _lwevent_clear(&lwevent,LWE_STOPWATCH); printf ("\nSTOPWATCH!\n"); print_current_time(); printf ("\nClearing RTC:\n"); _rtc_init (RTC_INIT_FLAG_CLEAR | RTC_INIT_FLAG_ENABLE); print_current_time(); install_alarm(); _lwevent_wait_ticks(&lwevent,LWE_ALARM,FALSE,0); _lwevent_clear(&lwevent,LWE_ALARM); printf ("ALARM!\n"); print_current_time(); #else /* BSP_TWRMPC5125 */ printf ("Waste 10 seconds here\n"); _time_delay(10000); _rtc_get_time_mqxd (&time_rtc); print_rtc_time(&time_rtc, &time_mqx); #endif printf ("Synchronize RTC to MQX time again:\n"); _rtc_sync_with_mqx (FALSE); _rtc_get_time_mqxd (&time_rtc); _time_from_date (&time_rtc, &time_mqx); print_rtc_time(&time_rtc, &time_mqx); #if PSP_HAS_IRTC == 1 irtc_test(); #endif /* PSP_HAS_IRTC == 1 */ /* Test tamper event functionality on MCF51EMxx device */ #if PSP_MQX_CPU_IS_MCF51EM test_tamper(); #else printf ("Finish, press/hold reset to repeat.\n"); _task_block() ; #endif }
long get_http_speed(int test_respond_size, const char * server_address, int port, const char * file_name, struct sockaddr_in address) { // 记录请求开始时间 int response_speed = -1; struct timeval time_start; gettimeofday(&time_start, NULL); // Open up a socket int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { DLog("Unable to open socket\n"); return -1; } if (connect(sockfd, (struct sockaddr*) &address, sizeof(address)) < 0) { DLog("Unable to connect to host\n"); return -1; } DLog("Connected with host: %s\n", inet_ntoa(address.sin_addr)); // Define buffer size const int buffer_size = 8096; /*******************************************************/ /* Begin sending GET request */ /*******************************************************/ char buffer[buffer_size]; sprintf(buffer, "GET %s HTTP/1.1\r\n", file_name); write_socket(sockfd, buffer, strlen(buffer)); sprintf(buffer, "Host: %s:%d\r\n", server_address, port); write_socket(sockfd, buffer, strlen(buffer)); sprintf(buffer, "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36\r\n"); write_socket(sockfd, buffer, strlen(buffer)); sprintf(buffer, "Connection: close\r\n"); write_socket(sockfd, buffer, strlen(buffer)); // Signal end of headers with empty line sprintf(buffer, "\r\n"); write_socket(sockfd, buffer, strlen(buffer)); /*******************************************************/ /* Begin reading response */ /*******************************************************/ // Read first line and print to console int len = read_line(sockfd, buffer, sizeof(buffer)); if (len <= 0) { DLog("No response received from server\n"); goto out; } else { print_current_time(); } char version[16]; char response_code[16]; char response_reason[256]; int i, j; // Read version for(i = 0; i < sizeof(version) - 1 && !isspace(buffer[i]); i++) { version[i] = buffer[i]; } version[i] = '\0'; // Skip over spaces for (; isspace(buffer[i]) && i < sizeof(buffer); i++); // Read response code for (j = 0; i < sizeof(buffer) && j < sizeof(response_code) - 1 && !isspace(buffer[i]); i++, j++) { response_code[j] = buffer[i]; } response_code[j] = '\0'; // Skip over spaces for (; isspace(buffer[i]) && i < sizeof(buffer); i++); // Read response reason for (j = 0; i < sizeof(buffer) && j < sizeof(response_reason) - 1 && buffer[i] != '\n'; i++, j++) { response_reason[j] = buffer[i]; } response_reason[j] = '\0'; // DLog("Version: %s\n", version); // DLog("Response Code: %s\n", response_code); // DLog("Response Reason: %s\n", response_reason); struct HeaderReturnStuct header_return = read_headers(sockfd); if (strcmp(response_code, "200") != 0) { if (strcmp(response_code, "301") == 0) { DLog("%s Error: %s \n", response_code, response_reason); } else { DLog("%s Error: %s\n", response_code, response_reason); } goto out; } if (header_return.header_err_flag) { DLog("Error reading headers\n"); goto out; } // Sometimes, server doesn't return content-length // if (header_return.content_length <= 0) { // DLog("No content received from server\n"); // goto out; // } // lenght in Byte long response_length = read_socket(sockfd, buffer, buffer_size, test_respond_size); if (response_length <= 0) { goto out; } else { // Calculate the interval time from start to end, and get the internet speed struct timeval time_end; gettimeofday(&time_end, NULL); long miliStartSecond = (time_start.tv_sec)*1000 + (long)time_start.tv_usec/1000; long miliEndSecond = (time_end.tv_sec)*1000 + (long)time_end.tv_usec/1000; response_speed = response_length/((miliEndSecond - miliStartSecond)/1000.f); // "B/s" DLog("millisecond interval: %ld , target size: %d B, response length: %ld B, response speed: %d KB/S\n", miliEndSecond - miliStartSecond, test_respond_size, response_length, response_speed/1024); } out: // Close the connection down shutdown(sockfd, SHUT_RDWR); close(sockfd); sockfd = -1; return response_speed; }
void *POSIX_Init( void *argument ) { int status; int passes; int schedpolicy; int priority; struct sched_param schedparam; char buffer[ 80 ]; pthread_mutexattr_t attr; time_t start; time_t now; TEST_BEGIN(); /* set the time of day, and print our buffer in multiple ways */ set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); /* get id of this thread */ Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); /* try to use this thread as a sporadic server */ puts( "Init: pthread_getschedparam - SUCCESSFUL" ); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - current priority = %d", priority ); print_current_time( "Init: ", buffer ); schedparam.sched_ss_repl_period.tv_sec = 0; schedparam.sched_ss_repl_period.tv_nsec = 500000000; /* 1/2 second */ schedparam.sched_ss_init_budget.tv_sec = 0; schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */ schedparam.sched_priority = sched_get_priority_max(SCHED_SPORADIC); schedparam.sched_ss_low_priority = sched_get_priority_max(SCHED_SPORADIC) - 2; puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" ); status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); rtems_test_assert( !status ); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); /* go into a loop consuming CPU time to watch our priority change */ for ( passes=0 ; passes <= 3 ; ) { status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); if ( priority != schedparam.sched_priority ) { priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); passes++; } } /* now see if this works if we are holding a priority ceiling mutex */ empty_line(); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); schedparam.sched_ss_repl_period.tv_sec = 0; schedparam.sched_ss_repl_period.tv_nsec = 500000000; /* 1/2 second */ schedparam.sched_ss_init_budget.tv_sec = 0; schedparam.sched_ss_init_budget.tv_nsec = 250000000; /* 1/4 second */ HIGH_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ); MEDIUM_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 2; LOW_PRIORITY = sched_get_priority_max( SCHED_SPORADIC ) - 4; schedparam.sched_priority = HIGH_PRIORITY; schedparam.sched_ss_low_priority = LOW_PRIORITY; puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" ); status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam ); rtems_test_assert( !status ); puts( "Init: Initializing mutex attributes for priority ceiling" ); status = pthread_mutexattr_init( &attr ); rtems_test_assert( !status ); status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT ); rtems_test_assert( !status ); puts( "Init: Creating a mutex" ); status = pthread_mutex_init( &Mutex_id, &attr ); if ( status ) printf( "status = %d\n", status ); rtems_test_assert( !status ); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); /* go into a loop consuming CPU time to watch our priority NOT lower */ start = time( &start ); puts( "Init: pthread_mutex_lock acquire the lock" ); status = pthread_mutex_lock( &Mutex_id ); if ( status ) printf( "status = %d %s\n", status, strerror(status) ); rtems_test_assert( !status ); for ( ; ; ) { status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); if ( schedparam.sched_priority == LOW_PRIORITY ) { puts( "ERROR - Init's priority lowered while holding mutex" ); rtems_test_exit(0); } now = time( &now ); if ( now - start > 3 ) break; priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); break; } /* with this unlock we should be able to go to low priority */ puts( "Init: unlock mutex" ); status = pthread_mutex_unlock( &Mutex_id ); if ( status ) printf( "status = %d\n", status ); rtems_test_assert( !status ); status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); for ( ; ; ) { status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); if ( schedparam.sched_priority == LOW_PRIORITY ) break; } status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam ); rtems_test_assert( !status ); priority = schedparam.sched_priority; sprintf( buffer, " - new priority = %d", priority ); print_current_time( "Init: ", buffer ); TEST_END(); rtems_test_exit( 0 ); return NULL; /* just so the compiler thinks we returned something */ }
static void testtasklet_exit(void){ printk(KERN_ALERT"************\n"); print_current_time(0); printk(KERN_ALERT"testtasklet is exited!\n"); printk(KERN_ALERT"************\n"); }