void do_minidisplay(globalstate *gstate) { int real_delay; struct system_info si; /* save the real delay and substitute 1 second */ real_delay = gstate->delay; gstate->delay = 1; /* wait 1 second for a command */ time_mark(&(gstate->now)); do_command(gstate); /* do a mini update that only updates the cpustates */ get_system_info(&si); u_cpustates(si.cpustates); /* restore the delay time */ gstate->delay = real_delay; /* done */ i_endscreen(); }
__bool switch_to_backup() { UTILS_TIME t1, t2; __bool ret; time_mark(&t1); utils_trace(">> %s : switching to backup mode ....\n", _texttime().data()); ret = set_power_state(PWR_BACKUP); time_mark(&t2); utils_trace( ">> Mode switch %s , time elapsed is %.3f seconds.\n", ret? "OK" : "FAILED.", time_diff(&t2, &t1) ); return ret; }
int main(int argc, char *argv[]) { char *env_top; char **preset_argv; int preset_argc = 0; void *mask; int need_mini = 1; struct statics statics; globalstate *gstate; /* get our name */ if (argc > 0) { if ((myname = strrchr(argv[0], '/')) == 0) { myname = argv[0]; } else { myname++; } } /* binary compatibility check */ #ifdef HAVE_UNAME { struct utsname uts; if (uname(&uts) == 0) { if (strcmp(uts.machine, UNAME_HARDWARE) != 0) { fprintf(stderr, "%s: incompatible hardware platform\n", myname); exit(EX_UNAVAILABLE); } } } #endif /* initialization */ gstate = (globalstate *)calloc(1, sizeof(globalstate)); gstate->statics = &statics; time_mark(NULL); /* preset defaults for various options */ gstate->show_usernames = Yes; gstate->topn = DEFAULT_TOPN; gstate->delay = DEFAULT_DELAY; gstate->fulldraw = Yes; gstate->use_color = Yes; gstate->interactive = Maybe; /* preset defaults for process selection */ gstate->pselect.idle = Yes; gstate->pselect.system = No; gstate->pselect.fullcmd = No; gstate->pselect.command = NULL; gstate->pselect.uid = -1; gstate->pselect.mode = 0; /* use a large buffer for stdout */ #ifdef HAVE_SETVBUF setvbuf(stdout, stdoutbuf, _IOFBF, BUFFERSIZE); #else #ifdef HAVE_SETBUFFER setbuffer(stdout, stdoutbuf, BUFFERSIZE); #endif #endif /* get preset options from the environment */ if ((env_top = getenv("TOP")) != NULL) { preset_argv = argparse(env_top, &preset_argc); preset_argv[0] = myname; do_arguments(gstate, preset_argc, preset_argv); } /* process arguments */ do_arguments(gstate, argc, argv); #ifdef ENABLE_COLOR /* If colour has been turned on read in the settings. */ env_top = getenv("TOPCOLOURS"); if (!env_top) { env_top = getenv("TOPCOLORS"); } /* must do something about error messages */ color_env_parse(env_top); color_activate(gstate->use_color); #endif /* in order to support forward compatability, we have to ensure that the entire statics structure is set to a known value before we call machine_init. This way fields that a module does not know about will retain their default values */ memzero((void *)&statics, sizeof(statics)); statics.boottime = -1; /* call the platform-specific init */ if (machine_init(&statics) == -1) { exit(EX_SOFTWARE); } /* create a helper list of sort order names */ gstate->order_namelist = string_list(statics.order_names); /* look up chosen sorting order */ if (gstate->order_name != NULL) { int i; if (statics.order_names == NULL) { message_error(" This platform does not support arbitrary ordering"); } else if ((i = string_index(gstate->order_name, statics.order_names)) == -1) { message_error(" Sort order `%s' not recognized", gstate->order_name); message_error(" Recognized sort orders: %s", gstate->order_namelist); } else { gstate->order_index = i; } } /* initialize extensions */ init_username(); /* initialize termcap */ gstate->smart_terminal = screen_readtermcap(gstate->interactive); /* determine interactive state */ if (gstate->interactive == Maybe) { gstate->interactive = smart_terminal; } /* if displays were not specified, choose an appropriate default */ if (gstate->displays == 0) { gstate->displays = gstate->smart_terminal ? Infinity: 1; } /* we don't need a mini display when delay is less than 2 seconds or when we are not on a smart terminal */ if (gstate->delay <= 1 || !smart_terminal) { need_mini = 0; } /* set constants for username/uid display */ if (gstate->show_usernames) { gstate->header_text = format_header("USERNAME"); gstate->get_userid = username; } else { gstate->header_text = format_header(" UID "); gstate->get_userid = itoa7; } gstate->pselect.usernames = gstate->show_usernames; /* initialize display */ if ((gstate->max_topn = display_init(&statics)) == -1) { fprintf(stderr, "%s: can't allocate sufficient memory\n", myname); exit(EX_OSERR); } /* check for infinity and for overflowed screen */ if (gstate->topn == Infinity) { gstate->topn = INT_MAX; } else if (gstate->topn > gstate->max_topn) { #if 0 message_error(" This terminal can only display %d processes", gstate->max_topn); #endif } #ifdef ENABLE_COLOR /* producing a list of color tags is easy */ if (gstate->show_tags) { color_dump(stdout); exit(EX_OK); } #endif /* hold all signals while we initialize the screen */ mask = hold_signals(); screen_init(); /* set the signal handlers */ set_signals(); /* longjmp re-entry point */ /* set the jump buffer for long jumps out of signal handlers */ if (setjmp(jmp_int) != 0) { /* this is where we end up after processing sigwinch or sigtstp */ /* tell display to resize its buffers, and get the new length */ if ((gstate->max_topn = display_resize()) == -1) { /* thats bad */ quit(EX_OSERR); /*NOTREACHED*/ } /* set up for a full redraw, and get the current line count */ gstate->fulldraw = Yes; /* safe to release the signals now */ release_signals(mask); } else { /* release the signals */ release_signals(mask); /* some systems require a warmup */ /* always do a warmup for batch mode */ if (gstate->interactive == 0 || statics.flags.warmup) { struct system_info system_info; struct timeval timeout; time_mark(&(gstate->now)); get_system_info(&system_info); (void)get_process_info(&system_info, &gstate->pselect, 0); timeout.tv_sec = 1; timeout.tv_usec = 0; select(0, NULL, NULL, NULL, &timeout); /* if we've warmed up, then we can show good states too */ gstate->show_cpustates = Yes; need_mini = 0; } } /* main loop */ while ((gstate->displays == -1) || (--gstate->displays > 0)) { do_display(gstate); if (gstate->interactive) { if (need_mini) { do_minidisplay(gstate); need_mini = 0; } do_command(gstate); } else { do_wait(gstate); } } /* do one last display */ do_display(gstate); quit(EX_OK); /* NOTREACHED */ return 1; /* Keep compiler quiet. */ }
void do_display(globalstate *gstate) { int active_procs; int i; time_t curr_time; caddr_t processes; struct system_info system_info; char *hdr; /* get the time */ time_mark(&(gstate->now)); curr_time = (time_t)(gstate->now.tv_sec); /* get the current stats */ get_system_info(&system_info); /* get the current processes */ processes = get_process_info(&system_info, &(gstate->pselect), gstate->order_index); /* determine number of processes to actually display */ if (gstate->topn > 0) { /* this number will be the smallest of: active processes, number user requested, number current screen accomodates */ active_procs = system_info.P_ACTIVE; if (active_procs > gstate->topn) { active_procs = gstate->topn; } if (active_procs > gstate->max_topn) { active_procs = gstate->max_topn; } } else { /* dont show any */ active_procs = 0; } hdr = gstate->header_text; /* full screen or update? */ if (gstate->fulldraw) { display_clear(); i_loadave(system_info.last_pid, system_info.load_avg); i_uptime(&(gstate->statics->boottime), &curr_time); i_timeofday(&curr_time); i_procstates(system_info.p_total, system_info.procstates, gstate->pselect.threads); if (gstate->show_cpustates) { i_cpustates(system_info.cpustates); } else { if (smart_terminal) { z_cpustates(); } gstate->show_cpustates = Yes; } i_kernel(system_info.kernel); i_memory(system_info.memory); i_swap(system_info.swap); i_message(&(gstate->now)); i_header(hdr); for (i = 0; i < active_procs; i++) { i_process(i, format_next_process(processes, gstate->get_userid)); } i_endscreen(); if (gstate->smart_terminal) { gstate->fulldraw = No; } } else { u_loadave(system_info.last_pid, system_info.load_avg); u_uptime(&(gstate->statics->boottime), &curr_time); i_timeofday(&curr_time); u_procstates(system_info.p_total, system_info.procstates, gstate->pselect.threads); u_cpustates(system_info.cpustates); u_kernel(system_info.kernel); u_memory(system_info.memory); u_swap(system_info.swap); u_message(&(gstate->now)); u_header(hdr); for (i = 0; i < active_procs; i++) { u_process(i, format_next_process(processes, gstate->get_userid)); } u_endscreen(); } }
time_mark TimeLineWidget::pos2time(qreal pos) { return time_mark(pos / scale_ / 100. * AV_TIME_BASE); }
LIBUTILS_API char * UTILS_API get_file_versionA(const char * szFile, LARGE_INTEGER * liVersion) { char * pVersion=0; DWORD dwVersionSize, dwHnd; LARGE_INTEGER _liVersion; WORD * s; VS_FIXEDFILEINFO * pBlock; UINT dwBytes; if(!liVersion){ liVersion=&_liVersion; } memset(liVersion,0,sizeof(LARGE_INTEGER)); while(TRUE){ dwHnd = 0; dwVersionSize=GetFileVersionInfoSize((char *)szFile, &dwHnd); if(!dwVersionSize){ return g_szVersion; } pVersion=(char *)malloc(dwVersionSize*4); // *4: for some bugs if(!pVersion){ break; } my_heapchk(); if( !GetFileVersionInfo((char*)szFile, dwHnd, dwVersionSize, pVersion) ){ break; }; my_heapchk(); // Structure used to store enumerated languages and code pages. pBlock=0; dwBytes = sizeof(pBlock); // Retrieve file description for language and code page "i". VerQueryValue(pVersion,"\\",(void**)&pBlock,&dwBytes); my_heapchk(); if(pBlock){ #if 1 liVersion->HighPart=pBlock->dwFileVersionMS; liVersion->LowPart=pBlock->dwFileVersionLS; #else liVersion->HighPart=pBlock->dwProductVersionMS; liVersion->LowPart=pBlock->dwProductVersionLS; #endif } break; }; #ifdef __profile__ time_mark(&t2); utils_debug("get_file_version costs %.3f ms.\n", time_diff(&t2,&t1)*1000); #endif s = (WORD*)liVersion; sprintf(g_szVersion, "%d.%d.%d.%d",s[3],s[2],s[1],s[0]); my_heapchk(); if(pVersion){ free(pVersion); } return g_szVersion; }