int main() { struct statics stat; machine_init(&stat); struct system_info info; get_system_info(&info); for(;;) { printf("Used CPU:%.1f%%\n",(float)info.cpustates[0]/10); printf("Nice CPU:%.1f%%\n",(float)info.cpustates[1]/10); printf("System CPU:%.1f%%\n",(float)info.cpustates[2]/10); printf("Idle CPU:%.1f%%\n",(float)info.cpustates[3]/10); printf("total memroy:%d\n", info.memory[0]); printf("free memroy:%d\n", info.memory[1]); printf("buffers:%d\n", info.memory[2]); printf("cached:%d\n", info.memory[3]); printf("total swap:%d\n", info.memory[4]); printf("free swap:%d\n", info.memory[5]); sleep(2); printf("..................................\n"); get_system_info(&info); } return 0; }
void user_l( void ) { int i; int pid; uint32_t time; char buf[16]; time = get_system_info( SYSINFO_TIME ); i = itos16( buf, time, 1 ); write( FD_CONSOLE, "User L running, initial time ", 0 ); write( FD_CONSOLE, buf, i ); write( FD_CONSOLE, "\n", 1 ); write( FD_SIO, "L", 1 ); for( i = 0; i < 3 ; ++i ) { pid = spawn( user_x ); if( pid < 0 ) { write( FD_CONSOLE, "User L spawn() #", 0 ); pid = itos10( buf, i ); write( FD_CONSOLE, buf, pid ); write( FD_CONSOLE, " failed\n", 0 ); } else { sleep( 0 ); write( FD_SIO, "L", 1 ); } } time = get_system_info( SYSINFO_TIME ); i = itos16( buf, time, 1 ); write( FD_CONSOLE, "User L exiting at time ", 0 ); write( FD_CONSOLE, buf, i ); write( FD_CONSOLE, "\n", 1 ); exit(); }
FractalEngine::FractalEngine(BHandler* parent, BLooper* looper) : BLooper("FractalEngine"), fWidth(0), fHeight(0), fRenderBuffer(NULL), fRenderBufferLen(0), fSubsampling(2), fMessenger(parent, looper), fIterations(1024), fColorset(Colorset_Royal) { fDoSet = &FractalEngine::DoSet_Mandelbrot; fRenderSem = create_sem(0, "RenderSem"); fRenderStoppedSem = create_sem(0, "RenderStopped"); system_info info; get_system_info(&info); fThreadCount = info.cpu_count; if (fThreadCount > MAX_RENDER_THREADS) fThreadCount = MAX_RENDER_THREADS; for (uint8 i = 0; i < fThreadCount; i++) { fRenderThreads[i] = spawn_thread(&FractalEngine::RenderThread, BString().SetToFormat("RenderThread%d", i).String(), B_NORMAL_PRIORITY, this); resume_thread(fRenderThreads[i]); } }
SnowView::SnowView(BMessage *archive) : BView(archive) { system_info si; PRINT(("SnowView()\n")); #ifdef DEBUG archive->PrintToStream(); #endif fDragger = NULL; fAttached = false; fMsgRunner = NULL; fFallenBmp = NULL; fFallenView = NULL; fFallenReg = NULL; fCachedParent = NULL; fShowClickMe = false; SetFlags(Flags() & ~B_PULSE_NEEDED); /* it's only used when in the app */ get_system_info(&si); fNumFlakes = ((int32)(si.cpu_clock_speed/1000000)) * si.cpu_count / 3; //; printf("BSnow: using %ld flakes\n", fNumFlakes); for (int i = 0; i < WORKSPACES_COUNT; i++) { fFlakes[i] = new flake[fNumFlakes]; memset(fFlakes[i], 0, fNumFlakes * sizeof(flake)); } for (int i = 0; i < NUM_PATTERNS; i++) { fFlakeBitmaps[i] = new BBitmap(BRect(0,0,7,7), B_CMAP8); fFlakeBitmaps[i]->SetBits(gFlakeBits[i], 8*8, 0, B_CMAP8); } fCurrentWorkspace = 0; SetHighColor(255,255,255); SetDrawingMode(B_OP_OVER); }
void PulseView::Init() { popupmenu = new BPopUpMenu("PopUpMenu", false, false, B_ITEMS_IN_COLUMN); popupmenu->SetFont(be_plain_font); mode1 = new BMenuItem("", NULL, 0, 0); mode2 = new BMenuItem("", NULL, 0, 0); preferences = new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS), new BMessage(PV_PREFERENCES), 0, 0); about = new BMenuItem(B_TRANSLATE("About Pulse" B_UTF8_ELLIPSIS), new BMessage(PV_ABOUT), 0, 0); popupmenu->AddItem(mode1); popupmenu->AddItem(mode2); popupmenu->AddSeparatorItem(); system_info sys_info; get_system_info(&sys_info); // Only add menu items to control CPUs on an SMP machine if (sys_info.cpu_count >= 2) { cpu_menu_items = new BMenuItem *[sys_info.cpu_count]; char temp[20]; for (int x = 0; x < sys_info.cpu_count; x++) { sprintf(temp, "CPU %d", x + 1); BMessage *message = new BMessage(PV_CPU_MENU_ITEM); message->AddInt32("which", x); cpu_menu_items[x] = new BMenuItem(temp, message, 0, 0); popupmenu->AddItem(cpu_menu_items[x]); } popupmenu->AddSeparatorItem(); } popupmenu->AddItem(preferences); popupmenu->AddItem(about); }
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(); }
void fastPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE + 8 ]; struct timeval tv; system_info info; initRandomData( randomState, buffer, RANDOM_BUFSIZE ); gettimeofday( &tv, NULL ); addRandomValue( randomState, tv.tv_sec ); addRandomValue( randomState, tv.tv_usec ); /* Get the number of microseconds since the user last provided any input to any part of the system, the state of keyboard shift keys */ #if 0 /* See comment at start */ bigtime_t idleTime; uint32 value; idleTime = idle_time(); addRandomData( randomState, &idleTime, sizeof( bigtime_t ) ); value = modifiers(); addRandomValue( randomState, value ); #endif /* 0 */ /* Get various fixed values (the 64-bit machine ID, CPU count and type(s), clock speed, platform type, etc) and variable resources (number of in- use pages, semaphores, ports, threads, teams, number of page faults, and number of microseconds the CPU has been active) */ get_system_info( &info ); addRandomData( randomState, &info, sizeof( info ) ); /* Flush any remaining data through */ endRandomData( randomState, 5 ); }
int GetMinimumViewWidth() { system_info sys_info; get_system_info(&sys_info); return (sys_info.cpu_count * 2) + 1; }
void ProcessController::AttachedToWindow() { BView::AttachedToWindow(); if (Parent()) SetViewColor(B_TRANSPARENT_COLOR); else SetViewColor(kBlack); Preferences tPreferences(kPreferencesFileName, NULL, false); DefaultColors(); system_info info; get_system_info(&info); gCPUcount = info.cpu_count; Update(); gIdleColor = kIdleGreen; gIdleColorSelected = tint_color(gIdleColor, B_HIGHLIGHT_BACKGROUND_TINT); gKernelColor = kKernelBlue; gKernelColorSelected = tint_color(gKernelColor, B_HIGHLIGHT_BACKGROUND_TINT); gUserColor = tint_color(gKernelColor, B_LIGHTEN_2_TINT); gUserColorSelected = tint_color(gUserColor, B_HIGHLIGHT_BACKGROUND_TINT); gFrameColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_HIGHLIGHT_BACKGROUND_TINT); gFrameColorSelected = tint_color(gFrameColor, B_HIGHLIGHT_BACKGROUND_TINT); gMenuBackColor = ui_color(B_MENU_BACKGROUND_COLOR); gMenuBackColorSelected = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR); gWhiteSelected = tint_color(kWhite, B_HIGHLIGHT_BACKGROUND_TINT); BMessenger messenger(this); BMessage message('Puls'); fMessageRunner = new BMessageRunner(messenger, &message, 250000, -1); }
int _ultra_hwd_init_substrate( int cidx ) { int retval; /* retval = _papi_hwi_setup_vector_table(vtable, _solaris_ultra_table); if ( retval != PAPI_OK ) return(retval); */ /* Fill in what we can of the papi_system_info. */ retval = get_system_info( &_papi_hwi_system_info ); if ( retval ) return ( retval ); /* Setup memory info */ retval = _papi_os_vector.get_memory_info( &_papi_hwi_system_info.hw_info, 0 ); if ( retval ) return ( retval ); lock_init( ); SUBDBG( "Found %d %s %s CPUs at %f Mhz.\n", _papi_hwi_system_info.hw_info.totalcpus, _papi_hwi_system_info.hw_info.vendor_string, _papi_hwi_system_info.hw_info.model_string, _papi_hwi_system_info.hw_info.mhz ); return ( PAPI_OK ); }
void ProcessController::Update() { system_info info; get_system_info(&info); bigtime_t now = system_time(); cpu_info* cpuInfos = new cpu_info[gCPUcount]; get_cpu_info(0, gCPUcount, cpuInfos); fMemoryUsage = float(info.used_pages) / float(info.max_pages); // Calculate work done since last call to Update() for each CPU for (unsigned int x = 0; x < gCPUcount; x++) { bigtime_t load = cpuInfos[x].active_time - fPrevActive[x]; bigtime_t passed = now - fPrevTime; float cpuTime = float(load) / float(passed); fPrevActive[x] = cpuInfos[x].active_time; if (load > passed) fPrevActive[x] -= load - passed; // save overload for next period... if (cpuTime < 0) cpuTime = 0; if (cpuTime > 1) cpuTime = 1; fCPUTimes[x] = cpuTime; } fPrevTime = now; delete[] cpuInfos; }
static int modmem_memory_total( INSTANCE * my, int * params ) { #ifdef WIN32 MEMORYSTATUS mem ; GlobalMemoryStatus( &mem ) ; return mem.dwTotalPhys ; #elif defined(TARGET_BEOS) system_info info; get_system_info( &info ); return B_PAGE_SIZE * ( info.max_pages ); #elif !defined(TARGET_MAC) && !defined(TARGET_WII) /* Linux and other Unix (?) */ struct sysinfo meminf; int fv; if ( sysinfo( &meminf ) == -1 ) return -1; if ( !( fv = kernel_version_type() ) ) return -1; if ( fv == 1 ) return meminf.totalram * meminf.mem_unit; else return meminf.totalram; return -1; #else return 0; //TODO #endif }
UInt32 GetNumberOfProcessors() { system_info info; get_system_info(&info); int nbcpu = info.cpu_count; if (nbcpu < 1) nbcpu = 1; return nbcpu; }
/* * Get timestamp counter frequency from the kernel */ static frame_time_t beos_get_tsc_freq (void) { system_info info; get_system_info (&info); return info.cpu_clock_speed; }
int main(int argc, char **argv) { team_info tinfo; int32 cookie = 0; int32 i; system_info sysinfo; // show up some stats first... get_system_info(&sysinfo); printf("sem: total: %5" B_PRIu32 ", used: %5" B_PRIu32 ", left: %5" B_PRIu32 "\n\n", sysinfo.max_sems, sysinfo.used_sems, sysinfo.max_sems - sysinfo.used_sems); if (argc == 1) { while (get_next_team_info( &cookie, &tinfo) == B_OK) list_sems(&tinfo); return 0; } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { fprintf(stderr, "Usage: %s [-s semid] [teamid]\n", argv[0]); fputs(" List the semaphores allocated by the specified\n", stderr); fputs(" team, or all teams if none is specified.\n", stderr); fputs("\n", stderr); fputs(" The -s option displays the sem_info data for a\n", stderr); fputs(" specified semaphore.\n", stderr); return 0; } else if (strcmp(argv[i], "-s") == 0) { if (argc < i + 2) printf("-s used without associated sem id\n"); else { sem_id id = atoi(argv[i + 1]); sem_info info; if (get_sem_info(id, &info) == B_OK) { print_header(NULL); print_sem_info(&info); } else printf("semaphore %" B_PRId32 " unknown\n\n", id); i++; } } else { team_id team; team = atoi(argv[i]); if (get_team_info(team, &tinfo) == B_OK) list_sems(&tinfo); else printf("team %" B_PRId32 " unknown\n\n", team); } } return 0; }
MainWorker::MainWorker(JobQueue& queue) : Worker(queue) { // TODO: keep track of workers, and quit them on destruction system_info info; if (get_system_info(&info) == B_OK) fCPUCount = info.cpu_count; }
bool get_team_name_and_icon(info_pack& infoPack, bool icon) { BPath systemPath; find_directory(B_BEOS_SYSTEM_DIRECTORY, &systemPath); bool nameFromArgs = false; bool tryTrackerIcon = true; for (int len = strlen(infoPack.team_info.args) - 1; len >= 0 && infoPack.team_info.args[len] == ' '; len--) { infoPack.team_info.args[len] = 0; } app_info info; status_t status = be_roster->GetRunningAppInfo(infoPack.team_info.team, &info); if (status == B_OK || infoPack.team_info.team == B_SYSTEM_TEAM) { if (infoPack.team_info.team == B_SYSTEM_TEAM) { // Get icon and name from kernel system_info systemInfo; get_system_info(&systemInfo); BPath kernelPath(systemPath); kernelPath.Append(systemInfo.kernel_name); get_ref_for_path(kernelPath.Path(), &info.ref); nameFromArgs = true; } } else { BEntry entry(infoPack.team_info.args, true); status = entry.GetRef(&info.ref); if (status != B_OK || strncmp(infoPack.team_info.args, systemPath.Path(), strlen(systemPath.Path())) != 0) nameFromArgs = true; tryTrackerIcon = (status == B_OK); } strncpy(infoPack.team_name, nameFromArgs ? infoPack.team_info.args : info.ref.name, B_PATH_NAME_LENGTH - 1); if (icon) { #ifdef __HAIKU__ infoPack.team_icon = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32); #else infoPack.team_icon = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8); #endif if (!tryTrackerIcon || BNodeInfo::GetTrackerIcon(&info.ref, infoPack.team_icon, B_MINI_ICON) != B_OK) { // TODO: don't hardcode the "app" icon! infoPack.team_icon->SetBits(k_app_mini, 256, 0, B_CMAP8); } } else infoPack.team_icon = NULL; return true; }
/*! Detect SIMD flags for use in AppServer. Checks all CPUs in the system and chooses the minimum supported set of instructions. */ static void detect_simd() { #if __INTEL__ // Only scan CPUs for which we are certain the SIMD flags are properly // defined. const char* vendorNames[] = { "GenuineIntel", "AuthenticAMD", "CentaurHauls", // Via CPUs, MMX and SSE support "RiseRiseRise", // should be MMX-only "CyrixInstead", // MMX-only, but custom MMX extensions "GenuineTMx86", // MMX and SSE 0 }; system_info systemInfo; if (get_system_info(&systemInfo) != B_OK) return; // We start out with all flags set and end up with only those flags // supported across all CPUs found. uint32 appServerSIMD = 0xffffffff; for (int32 cpu = 0; cpu < systemInfo.cpu_count; cpu++) { cpuid_info cpuInfo; get_cpuid(&cpuInfo, 0, cpu); // Get the vendor string and terminate it manually char vendor[13]; memcpy(vendor, cpuInfo.eax_0.vendor_id, 12); vendor[12] = 0; bool vendorFound = false; for (uint32 i = 0; vendorNames[i] != 0; i++) { if (strcmp(vendor, vendorNames[i]) == 0) vendorFound = true; } uint32 cpuSIMD = 0; uint32 maxStdFunc = cpuInfo.regs.eax; if (vendorFound && maxStdFunc >= 1) { get_cpuid(&cpuInfo, 1, 0); uint32 edx = cpuInfo.regs.edx; if (edx & (1 << 23)) cpuSIMD |= APPSERVER_SIMD_MMX; if (edx & (1 << 25)) cpuSIMD |= APPSERVER_SIMD_SSE; } else { // no flags can be identified cpuSIMD = 0; } appServerSIMD &= cpuSIMD; } gAppServerSIMDFlags = appServerSIMD; #endif // __INTEL__ }
void init_crypt() { system_info info; if (get_system_info(&info) == B_OK) sThreadCount = info.cpu_count; if (sThreadCount == 0) sThreadCount = 1; }
bool TypeEditorView::TypeMatches() { // the default is to accept anything that easily fits into memory system_info info; get_system_info(&info); return fEditor.FileSize() / B_PAGE_SIZE < info.max_pages / 2; }
MultiLocker::MultiLocker(const char* semaphoreBaseName) : fInit(B_NO_INIT), fReadCount(0), fReadSem(-1), fWriteCount(0), fWriteSem(-1), fLockCount(0), fWriterLock(-1), fWriterNest(0), fWriterThread(-1), fWriterStackBase(0), fDebugArray(NULL), fMaxThreads(0) { //build the semaphores if (semaphoreBaseName) { char name[128]; sprintf(name, "%s-%s", semaphoreBaseName, "ReadSem"); fReadSem = create_sem(0, name); sprintf(name, "%s-%s", semaphoreBaseName, "WriteSem"); fWriteSem = create_sem(0, name); sprintf(name, "%s-%s", semaphoreBaseName, "WriterLock"); fWriterLock = create_sem(0, name); } else { fReadSem = create_sem(0, "MultiLocker_ReadSem"); fWriteSem = create_sem(0, "MultiLocker_WriteSem"); fWriterLock = create_sem(0, "MultiLocker_WriterLock"); } if (fReadSem >= 0 && fWriteSem >=0 && fWriterLock >= 0) fInit = B_OK; #if DEBUG //we are in debug mode! //create the reader tracking list //the array needs to be large enough to hold all possible threads system_info sys; get_system_info(&sys); fMaxThreads = sys.max_threads; fDebugArray = (int32 *) malloc(fMaxThreads * sizeof(int32)); for (int32 i = 0; i < fMaxThreads; i++) { fDebugArray[i] = 0; } #endif #if TIMING //initialize the counter variables rl_count = ru_count = wl_count = wu_count = islock_count = 0; rl_time = ru_time = wl_time = wu_time = islock_time = 0; #if DEBUG reg_count = unreg_count = 0; reg_time = unreg_time = 0; #endif #endif }
static bigtime_t ActivityLevel() { // stolen from roster server bigtime_t time = 0; system_info sinfo; get_system_info(&sinfo); for (int32 index = 0; index < sinfo.cpu_count; index++) time += sinfo.cpu_infos[index].active_time; return time / ((bigtime_t) sinfo.cpu_count); }
MultiLocker::MultiLocker(const char* name) : fInit(B_NO_INIT), fReadCount(0), fReadSem(-1), fWriteCount(0), fWriteSem(-1), fLockCount(0), fWriterLock(-1), fWriterNest(0), fWriterThread(-1), fWriterStackBase(0), fDebugArray(NULL), fMaxThreads(0) { BString buf; //build the semaphores buf = name; buf << " ReadSem"; fReadSem = create_sem(0, buf.String()); buf = name; buf << " WriteSem"; fWriteSem = create_sem(0, buf.String()); buf = name; buf << " WriterLock"; fWriterLock = create_sem(0, buf.String()); if (fReadSem >= 0 && fWriteSem >=0 && fWriterLock >= 0) fInit = B_OK; #if DEBUG //we are in debug mode! //create the reader tracking list //the array needs to be large enough to hold all possible threads system_info sys; get_system_info(&sys); fMaxThreads = sys.max_threads; printf("max_threads: %ld used_threads: %ld\n", sys.max_threads, sys.used_threads); fDebugArray = (int32 *) malloc(fMaxThreads * sizeof(int32)); for (int32 i = 0; i < fMaxThreads; i++) { fDebugArray[i] = 0; } #endif #if TIMING //initialize the counter variables rl_count = ru_count = wl_count = wu_count = islock_count = 0; rl_time = ru_time = wl_time = wu_time = islock_time = 0; #if DEBUG reg_count = unreg_count = 0; reg_time = unreg_time = 0; #endif #endif }
DWORD get_process_count() { static DWORD process_count = 0; if( process_count == 0 ) { SYSTEM_INFO info; get_system_info( &info ); process_count = info.dwNumberOfProcessors; } return process_count; }
// CountBlocks off_t Volume::CountBlocks() const { size_t bytes = 0; system_info sysInfo; if (get_system_info(&sysInfo) == B_OK) { int32 freePages = sysInfo.max_pages - sysInfo.used_pages; bytes = (uint32)freePages * B_PAGE_SIZE + fBlockAllocator->GetAvailableBytes(); } return bytes / kDefaultBlockSize; }
dfs_system_status *send_sysinfo_request(char **argv) { int namenode_socket = connect_to_nn(argv[1], atoi(argv[2])); if (namenode_socket < 0) { return NULL; } dfs_system_status* ret = get_system_info(namenode_socket); close(namenode_socket); return ret; }
/****************************************************************** * RAMView::Pulse() *****************************************************************/ void RAMView::Pulse() { double ratio; system_info sysInfo; get_system_info(&sysInfo); // calculate the percentage of used pages ratio = (double) sysInfo.used_pages / sysInfo.max_pages; // the TRUE below doesn't mean anything for this class UpdateTimesteps(ratio, TRUE); }
float Prefs::GetNormalWindowHeight() { system_info sys_info; get_system_info(&sys_info); float height = PROGRESS_MTOP + PROGRESS_MBOTTOM + sys_info.cpu_count * ITEM_OFFSET; if (PULSEVIEW_MIN_HEIGHT > height) height = PULSEVIEW_MIN_HEIGHT; return height; }
BTranslatorRoster::Private::Private() : BHandler("translator roster"), BLocker("translator list"), fABISubDirectory(NULL), fNextID(1), fLazyScanning(true), fSafeMode(false) { char parameter[32]; size_t parameterLength = sizeof(parameter); if (_kern_get_safemode_option(B_SAFEMODE_SAFE_MODE, parameter, ¶meterLength) == B_OK) { if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on") || !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes") || !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) fSafeMode = true; } if (_kern_get_safemode_option(B_SAFEMODE_DISABLE_USER_ADD_ONS, parameter, ¶meterLength) == B_OK) { if (!strcasecmp(parameter, "enabled") || !strcasecmp(parameter, "on") || !strcasecmp(parameter, "true") || !strcasecmp(parameter, "yes") || !strcasecmp(parameter, "enable") || !strcmp(parameter, "1")) fSafeMode = true; } // We might run in compatibility mode on a system with a different ABI. The // translators matching our ABI can usually be found in respective // subdirectories of the translator directories. system_info info; if (get_system_info(&info) == B_OK && (info.abi & B_HAIKU_ABI_MAJOR) != (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR)) { switch (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR) { case B_HAIKU_ABI_GCC_2: fABISubDirectory = "gcc2"; break; case B_HAIKU_ABI_GCC_4: fABISubDirectory = "gcc4"; break; } } // we're sneaking us into the BApplication if (be_app != NULL && be_app->Lock()) { be_app->AddHandler(this); be_app->Unlock(); } }
// dump entire log void log_printall( FILE *logfile, char *buffer, uint32 buffer_len ) { uint32 pos; get_system_info( &sysinfo ); for( pos = 0; pos < buffer_len; ) { log_entry *entry; entry = (log_entry *)(buffer + pos); log_printentry( logfile, entry/*, &tsc*/ ); pos += sizeof( log_entry ) + (entry->num_args - 1) * sizeof( uint32 ); } }