void heap_cpu() { int a = 0; void* p = 0; int i = 0; int to = 0; unsigned int old = getnowtime(); struct heap_s* heap = heap_new(100000, sizeof(int), compare_int, swap_int, NULL); old = getnowtime(); printf("开始添加堆元素:%d\n", old); for(; i < 1000000; ++i) { a = rand() % 10000; heap_insert(heap, &a); } old = getnowtime(); printf("添加完毕,开始pop:%d\n", old); while( p =heap_pop(heap)) { to++; //int temp = *(int*)p; //printf("%d\n", temp); ; } old = getnowtime(); printf("pop完毕:%d, to:%d\n", old, to); }
void test_timer_cpu() { unsigned int old = getnowtime(); int id = -1; int i = 0; struct timeaction_mgr_s* time_mgr = 0; printf("开始构造:%d\n", old); time_mgr = timeaction_mgr_new(10000000); id = timeaction_mgr_add(time_mgr, my_handler1, 3000, NULL); old = getnowtime(); printf("开始添加:%d\n", old); for(; i < 1000000; ++i) { id = timeaction_mgr_add(time_mgr, my_handler, rand() % 2000, NULL); } old = getnowtime(); //timeaction_mgr_del(time_mgr, id); printf("开始调度:%d\n", old); while(timeaction_mgr_schedule(time_mgr)) { ; } old = getnowtime(); //timeaction_mgr_del(time_mgr, id); printf("调度结束:%d\n", old); }
void typepool_cpu() { struct type_pool_s* tp = type_pool_new(40000, sizeof(int)); int i = 0; unsigned int old = getnowtime(); printf("开始分配:%d\n", old); while( i < 80001) { char* p = type_pool_claim(tp); type_pool_reclaim(tp, p); i++; ; } i = 0; while( i < 80000) { char* p = type_pool_claim(tp); i++; ; } printf("分配完毕:%d\n", old); }
int main() { setup(); unsigned long previous_time = 0; static int k = 0; uint8_t temp; struct timeval tv; struct timezone tz; write_reg(ARDUCHIP_MODE, 0x01); //Switch to CAM while(1) { temp = read_reg(ARDUCHIP_TRIG); if(!(temp & VSYNC_MASK)) //New Frame is coming { write_reg(ARDUCHIP_MODE, 0x00); //Switch to MCU resetXY(); write_reg(ARDUCHIP_MODE, 0x01); //Switch to CAM while(!(read_reg(ARDUCHIP_TRIG)&0x01)); //Wait for VSYNC is gone } else if(temp & SHUTTER_MASK) { gettimeofday (&tv , &tz); previous_time = tv.tv_sec; //printf("previous_time is %d.\n",previous_time); while(read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK) { gettimeofday (&tv , &tz); //printf("put time is %d.\n",tv.tv_sec); if((tv.tv_sec - previous_time) >= 2) { Playback(); delayms(1000); } } gettimeofday (&tv , &tz); if((tv.tv_sec - previous_time) < 2) { //printf(" get time is %d.\n",tv.tv_sec); memset(filePath,0,28); strcat(filePath,"/home/pi/"); getnowtime(); strcat(filePath,nowtime); strcat(filePath,".bmp"); //Open the new file fp = fopen(filePath,"w+"); if (fp == NULL) { printf("open file failed\n"); return 0; } //Generate file name write_reg(ARDUCHIP_MODE, 0x00); //Switch to MCU, freeze the screen GrabImage(filePath); } } } }
static void do_cmdlog_stop(int cause) { /* cmdlog lock has already been held */ cmdlog.stats.stop_cause = cause; cmdlog.stats.enddate = getnowdate(); cmdlog.stats.endtime = getnowtime(); cmdlog.on_logging = false; }
struct cmd_log_stats *cmdlog_stats() { struct cmd_log_stats *stats = &cmdlog.stats; if (cmdlog.on_logging) { stats->enddate = getnowdate(); stats->endtime = getnowtime(); } return stats; }
int cmdlog_start(char *file_path, bool *already_started) { char fname[CMDLOG_FILENAME_LENGTH]; int ret = 0; int fd = -1; *already_started = false; pthread_mutex_lock(&cmdlog.lock); do { if (cmdlog.on_logging) { *already_started = true; break; } /* prepare command logging buffer */ if (cmdlog.buffer.data == NULL) { if ((cmdlog.buffer.data = malloc(CMDLOG_BUFFER_SIZE)) == NULL) { mc_logger->log(EXTENSION_LOG_WARNING, NULL, "Can't allocate command log buffer\n"); ret = -1; break; } } cmdlog.buffer.head = 0; cmdlog.buffer.tail = 0; cmdlog.buffer.last = 0; /* prepare comand logging stats */ memset(&cmdlog.stats, 0, sizeof(struct cmd_log_stats)); cmdlog.stats.bgndate = getnowdate(); cmdlog.stats.bgntime = getnowtime(); sprintf(cmdlog.stats.dirpath, "%s", (file_path != NULL ? file_path : "command_log")); /* open log file */ sprintf(fname, CMDLOG_FILENAME_FORMAT, cmdlog.stats.dirpath, mc_port, cmdlog.stats.bgndate, cmdlog.stats.bgntime, cmdlog.stats.file_count); if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) { mc_logger->log(EXTENSION_LOG_WARNING, NULL, "Can't open command log file: %s\n", fname); ret = -1; break; } else { close(fd); } /* enable command logging */ cmdlog.on_logging = true; cmdlog.stats.stop_cause = CMDLOG_RUNNING; /* start the flush thread to write command log to disk */ if (pthread_attr_init(&cmdlog.flush.attr) != 0 || pthread_attr_setdetachstate(&cmdlog.flush.attr, PTHREAD_CREATE_DETACHED) != 0 || (ret = pthread_create(&cmdlog.flush.tid, &cmdlog.flush.attr, cmdlog_flush_thread, NULL)) != 0) { mc_logger->log(EXTENSION_LOG_WARNING, NULL, "Can't create command log flush thread: %s\n", strerror(ret)); cmdlog.on_logging = false; // disable it */ if (remove(fname) != 0) { mc_logger->log(EXTENSION_LOG_WARNING, NULL, "Can't remove command log file: %s\n", fname); } cmdlog.stats.stop_cause = CMDLOG_NOT_STARTED; ret = -1; break; } } while(0); pthread_mutex_unlock(&cmdlog.lock); return ret; }