void main(uint32 kernel_image_size) { puts("\nHello world\n", 30); puts("Shellcode OS is starting...\n", 30); CppInit(); //callbios 要求内存地址位于1M一下, //因此,此处从栈(esp<0x00090000)中分配meminfo memory_info meminfo; uint32 memsize = get_mem_info(meminfo); printf("memsize=%08X(%dMb)\n", memsize, memsize >> 20); System.Init(kernel_image_size, &meminfo); uint32 system_stack = System.get_stack(); __asm mov esp, system_stack // //LIST<PROCESS>* process_list = new LIST<PROCESS>(); //PROCESS* proc = new PROCESS(); //printf("process_list=%08X process=%08X\n", process_list, (uint32)proc); //process_list->insert_head(proc); //process_list->remove_tail(); //delete process_list; //delete proc; //load_minidump(); //load_shellcode(); // _enable(); panic(""); _enable(); __asm jmp $ }
void mman_scan(int action) { extern char screenstate; static pos = 0,zavora = 0; MEMORYSTATUS mmi; char c[10]; if (screenstate && !zavora) { zavora = 1; switch(action) { case MMA_SWAP:curcolor = RGB555(31,0,0);break; case MMA_READ:curcolor = RGB555(0,31,0);break; case MMA_SWAP_READ:curcolor = RGB555(0,0,31);break; case MMA_FREE:curcolor = RGB555(31,31,31);break; } bar(pos,0,pos+16,16); get_mem_info(&mmi); set_font(H_FBOLD,RGB555(31,31,31)); curcolor = 0; bar(16,0,66,16); position(16,0);sprintf(c,"%d",mmi.dwAvailPageFile/1024); outtext(c); showview(pos,0,66,16); zavora = 0; } }
int main( int argc, char *argv[] ) { char *opt; int print; print = 0; if( argc > 1 ) { opt = argv[1]; if( *opt == '/' || *opt == '-' ) { if( opt[1] == 'v' || opt[1] == 'V' ) { print = 1; } } if( print == 0 ) { Usage(); exit(0); } } TechOutFile = fopen( "techinfo.out", "w" ); do_company_header(); get_compiler_patch(); get_wsql_patch(); get_mem_info(); get_config_files(); machine_type( print ); #ifndef __OS2__ check_dos_comm(); #endif fclose( TechOutFile ); return( 0 ); }
int get_gpu_id_mem() { unsigned int ncores; unsigned int gpuarray[NDEV]; int ret=get_mem_info(&ncores,gpuarray); if(ret<0) { fprintf(stderr,"Can not Get Next GPU ID Correctly..\n"); return 0; } int i; int ind; int val=(1L<<31)-1; fprintf(stderr,"\033[33mVal:=%d\n\033[0m",val); for(i=0; i<ncores; i++) { printf("[%d]::%d(%d)\n",i,Byte2Mib(gpuarray[i]),gpuarray[i]); if(gpuarray[i]<val) { val=gpuarray[i]; ind=i; } } return ind; }
int mem_pool_delete (int pool_id) { struct mem_info *p = get_mem_info (pool_id); if (!p) { return -1; } free_mem (p->addr_blks); free_mem (p->saddr); free_mem (p); return 0; }
HPCC_Params * initialize () { prepareComm(); get_mem_info(); maxprocmem = ((uint64_t) mem_total) * 1024 / 2; HPCC_Params *params = (HPCC_Params *) malloc (sizeof (HPCC_Params)); params->HPLMaxProcMem = maxprocmem; getASCIITime (params->nowASCII, sizeof(params->nowASCII)-1); params->outFname = OUTFNAME; return params; }
u32 cw_get_ap_local_info(ap_local_info_t *ap_info) { cpu_info_t cpu_stat1; cpu_info_t cpu_stat2; get_mem_info(ap_info); get_run_time(ap_info); get_cpu_info((cpu_info_t *)&cpu_stat1); sleep(1); get_cpu_info((cpu_info_t *)&cpu_stat2); ap_info->cpu_idle_rate = cal_cpu_rate ((cpu_info_t *)&cpu_stat1, (cpu_info_t *)&cpu_stat2); return CWLAN_OK; }
void SmallMem::free(void* addr) { if (addr == nullptr) { return; } ptrdiff_t offset = char_ptr(addr) - sizeof(mem_info) - char_ptr(reserved_mem); mem_info* info = get_mem_info(addr); ptrdiff_t end = (char_ptr(addr) + info->size) - char_ptr(reserved_mem); for (ptrdiff_t i = offset; i < end; i++) { clear_bit(i); } }
int main(int argc, char* argv[]) { procstat_t stPreCpuUsage, stCurCpuUsage; procstat_t d; procstat_t u100; /* percentages(%x100) per total */ #ifdef CPU_FREQ cpuinfo_t c0; cpuinfo_t c1; cpuinfo_t c2; cpuinfo_t c3; #endif unsigned long long total, usage100; FILE *ofp = NULL; time_t old, new; clock_t timeStamp = 0; int i = 0; int isFirst = 1; int logInterval = 0; int logTime = 0; int l_pseONOFF = 0; #ifdef PROC_MEM float mem_portion = 0; #endif #ifdef SCORECALC SCORE_RESULT_T stScore = {}; int final_descision = 0; #endif if (argc != 3) { printf("Usage : ./cpu-daemon [interval (ms)] [logging time (s)]\n"); return 0; } for(i = 1; i<argc; i++) { printf("%s ", argv[i]); } logInterval = atoi(argv[1]) * 1000; logTime = atoi(argv[2]); printf("\n v1.3 log Interval = %d[us] log Time = %d[s]\n", logInterval, logTime); time(&old); read_proc_stat(&stPreCpuUsage); ofp = fopen("/data/cpulog/pseON.txt", "rt"); if(ofp == NULL){ printf("fopen open error\n"); return 0; } fscanf(ofp, "%d", &l_pseONOFF); fclose(ofp); ofp = NULL; if((l_pseONOFF == 1)&&(read_scaling_governor() != G_USERSPACE)) { printf("Change to USERSPACE \n"); set_scaling_governor(G_USERSPACE); } while(1) { time(&new); if(difftime(new, old) < logTime) { usleep(logInterval); timeStamp = clock(); read_proc_stat(&stCurCpuUsage); diff_proc_stat(&stCurCpuUsage, &stPreCpuUsage, &d); stPreCpuUsage = stCurCpuUsage; #ifdef CPU_THREAD read_run_thread_number(&c0); #endif #ifdef CPU_FREQ read_cpu0_cur_freq(&c0); read_cpu1_cur_freq(&c1); read_cpu2_cur_freq(&c2); read_cpu3_cur_freq(&c3); #endif #ifdef PROC_MEM mem_portion = get_mem_info(); //printf("PSS : %7.2f%%\n", mem_portion); #endif total = d.user + d.system + d.nice + d.idle + d.iowait + d.irq + d.softirq + d.steal + d.guest + d.guest_nice; u100.user = d.user * 10000 / total; u100.nice = d.nice * 10000 / total; u100.system = d.system * 10000 / total; u100.idle = d.idle * 10000 / total; u100.iowait = d.iowait * 10000 / total; u100.irq = d.irq * 10000 / total; u100.softirq = d.softirq * 10000 / total; u100.steal = d.steal * 10000 / total; u100.guest = d.guest * 10000 / total; u100.guest_nice = d.guest_nice * 10000 / total; usage100 = 10000 - u100.idle; if(isFirst) { isFirst = 0; if (mkdir("/data/cpulog", 775) == -1 && errno != EEXIST) { fprintf(stderr, "Problem creating directory"); perror(" "); } #ifdef SCORECALC //Load each Usage & Score value data from Text files. loadUsageScoreValue(); #endif ofp = fopen("/data/cpulog/cpulog.txt", "w"); if(ofp == NULL) { printf("fopen w error\n"); return 0; } #if defined(CPU_THREAD) && defined(CPU_FREQ) && defined(PROC_MEM) && defined(SCORECALC) fprintf(ofp, "[%5.5s],[%5.5s],[%5.5s], [%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","thread", "freq0", "freq1","freq2","freq3", "mem","score", "decision", "tarFreq" ); #elif defined(CPU_THREAD) && defined(CPU_FREQ) && defined(PROC_MEM) fprintf(ofp, "[%5.5s],[%5.5s],[%5.5s], [%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","thread", "freq0", "freq1","freq2","freq3", "mem"); #elif defined (CPU_THREAD) && defined(CPU_FREQ) fprintf(ofp, "[%5.5s],[%5.5s],[%5.5s], [%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","thread", "freq0", "freq1","freq2","freq3"); #else fprintf(ofp, "[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","user","nice","system","idle","iowait","irq","softirq","steal","guest","guest_nice"); #endif fclose(ofp); #if defined(CPU_THREAD) && defined(CPU_FREQ) && defined(PROC_MEM) printf("[%5.5s],[%5.5s],[%5.5s],[%5.5s], [%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","thread","freq0", "freq1","freq2","freq3", "mem"); #elif defined (CPU_THREAD) && defined(CPU_FREQ) printf("[%5.5s],[%5.5s],[%5.5s],[%5.5s], [%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","thread","freq0", "freq1","freq2","freq3"); #else printf( "[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s],[%5.5s]\n", "time","cpu","user","nice","system","idle","iowait","irq","softirq","steal","guest","guest_nice"); #endif } #if defined(CPU_THREAD) && defined(CPU_FREQ) && defined(PROC_MEM) printf("%6.2fs,%4llu.%02llu, %7d,%7d, %7d, %7d, %7d, %4.2f \n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, c0.run_thread, c0.scaling_cur_freq, c1.scaling_cur_freq, c2.scaling_cur_freq, c3.scaling_cur_freq, mem_portion ); #elif defined (CPU_THREAD) && defined(CPU_FREQ) printf("%6.2fs,%4llu.%02llu, %7d,%7d, %7d, %7d, %7d \n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, c0.run_thread, c0.scaling_cur_freq, c1.scaling_cur_freq, c2.scaling_cur_freq, c3.scaling_cur_freq ); #else printf("%6.2fs,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu\n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, u100.user/100, u100.user%100, u100.nice/100, u100.nice%100, u100.system/100, u100.system%100, u100.idle/100, u100.idle%100, u100.iowait/100, u100.iowait%100, u100.irq/100, u100.irq%100, u100.softirq/100, u100.softirq%100, u100.steal/100, u100.steal%100, u100.guest/100, u100.guest%100, u100.guest_nice/100, u100.guest_nice%100 ); #endif ofp = fopen("/data/cpulog/cpulog.txt", "a"); if(ofp == NULL) { printf("fopen a error\n"); return 0; } #ifdef SCORECALC RESOURCE_USAGE_T stResourceUsage; stResourceUsage.cpuUsage = (float)usage100/100; stResourceUsage.threadUsage = c0.run_thread; stResourceUsage.memoryUsage = mem_portion; stResourceUsage.cpuFreq = c0.scaling_cur_freq/1000; stScore = calcResourceScore(&stResourceUsage); #endif #if defined(CPU_THREAD) && defined(CPU_FREQ) && defined(SCORECALC) fprintf(ofp, "%6.2fs,%4llu.%02llu, %7d, %7d, %7d, %7d, %7d, %4.2f,%7d,%7d,%7d \n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, c0.run_thread, c0.scaling_cur_freq, c1.scaling_cur_freq, c2.scaling_cur_freq, c3.scaling_cur_freq, mem_portion, stScore.score, stScore.finalDecision, stScore.targetFreq ); #elif defined(CPU_THREAD) && defined(CPU_FREQ) fprintf(ofp, "%6.2fs,%4llu.%02llu, %7d, %7d, %7d, %7d, %7d, %4.2f \n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, c0.run_thread, c0.scaling_cur_freq, c1.scaling_cur_freq, c2.scaling_cur_freq, c3.scaling_cur_freq, mem_portion ); #elif defined (CPU_THREAD) && defined(CPU_FREQ) fprintf(ofp, "%6.2fs,%4llu.%02llu, %7d, %7d, %7d, %7d, %7d \n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, c0.run_thread, c0.scaling_cur_freq, c1.scaling_cur_freq, c2.scaling_cur_freq, c3.scaling_cur_freq ); #else fprintf(ofp, "%6.2fs,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu,%4llu.%02llu\n", (double)timeStamp/CLOCKS_PER_SEC, usage100/100, usage100%100, u100.user/100, u100.user%100, u100.nice/100, u100.nice%100, u100.system/100, u100.system%100, u100.idle/100, u100.idle%100, u100.iowait/100, u100.iowait%100, u100.irq/100, u100.irq%100, u100.softirq/100, u100.softirq%100, u100.steal/100, u100.steal%100, u100.guest/100, u100.guest%100, u100.guest_nice/100, u100.guest_nice%100 ); #endif fclose(ofp); } else { printf("cpu usage logging finished\n"); if(read_scaling_governor() != G_ONDEMAND) { printf("Come back to ONDEMAND \n"); set_scaling_governor(G_ONDEMAND); } return 0; } }
int main(int argc, char *argv[]) { pm_kernel_t *ker; pm_process_t *proc; pid_t *pids; size_t num_procs; uint64_t total_pss; uint64_t total_uss; uint64_t total_swap; uint64_t total_pswap; uint64_t total_uswap; uint64_t total_zswap; int error; bool has_swap = false, has_zram = false; uint64_t required_flags = 0; uint64_t flags_mask = 0; int arg; size_t i; enum { WS_OFF, WS_ONLY, WS_RESET, } ws; uint64_t mem[MEMINFO_COUNT] = { }; pm_proportional_swap_t *p_swap; float zram_cr = 0.0; signal(SIGPIPE, SIG_IGN); compfn = &sort_by_pss; order = -1; ws = WS_OFF; bool oomadj = false; for (arg = 1; arg < argc; arg++) { if (!strcmp(argv[arg], "-v")) { compfn = &sort_by_vss; continue; } if (!strcmp(argv[arg], "-r")) { compfn = &sort_by_rss; continue; } if (!strcmp(argv[arg], "-p")) { compfn = &sort_by_pss; continue; } if (!strcmp(argv[arg], "-u")) { compfn = &sort_by_uss; continue; } if (!strcmp(argv[arg], "-s")) { compfn = &sort_by_swap; continue; } if (!strcmp(argv[arg], "-o")) { compfn = &sort_by_oomadj; oomadj = true; continue; } if (!strcmp(argv[arg], "-c")) { required_flags = 0; flags_mask = (1 << KPF_SWAPBACKED); continue; } if (!strcmp(argv[arg], "-C")) { required_flags = flags_mask = (1 << KPF_SWAPBACKED); continue; } if (!strcmp(argv[arg], "-k")) { required_flags = flags_mask = (1 << KPF_KSM); continue; } if (!strcmp(argv[arg], "-w")) { ws = WS_ONLY; continue; } if (!strcmp(argv[arg], "-W")) { ws = WS_RESET; continue; } if (!strcmp(argv[arg], "-R")) { order *= -1; continue; } if (!strcmp(argv[arg], "-h")) { usage(argv[0]); exit(0); } fprintf(stderr, "Invalid argument \"%s\".\n", argv[arg]); usage(argv[0]); exit(EXIT_FAILURE); } get_mem_info(mem); p_swap = pm_memusage_pswap_create(mem[MEMINFO_SWAP_TOTAL] * 1024); error = pm_kernel_create(&ker); if (error) { fprintf(stderr, "Error creating kernel interface -- " "does this kernel have pagemap?\n"); exit(EXIT_FAILURE); } error = pm_kernel_pids(ker, &pids, &num_procs); if (error) { fprintf(stderr, "Error listing processes.\n"); exit(EXIT_FAILURE); } std::vector<proc_info> procs(num_procs); for (i = 0; i < num_procs; i++) { procs[i].pid = pids[i]; procs[i].oomadj = getoomadj(pids[i]); pm_memusage_zero(&procs[i].usage); pm_memusage_pswap_init_handle(&procs[i].usage, p_swap); error = pm_process_create(ker, pids[i], &proc); if (error) { fprintf(stderr, "warning: could not create process interface for %d\n", pids[i]); continue; } switch (ws) { case WS_OFF: error = pm_process_usage_flags(proc, &procs[i].usage, flags_mask, required_flags); break; case WS_ONLY: error = pm_process_workingset(proc, &procs[i].usage, 0); break; case WS_RESET: error = pm_process_workingset(proc, NULL, 1); break; } if (error) { fprintf(stderr, "warning: could not read usage for %d\n", pids[i]); } if (ws != WS_RESET && procs[i].usage.swap) { has_swap = true; } pm_process_destroy(proc); } free(pids); if (ws == WS_RESET) exit(0); procs.erase(std::remove_if(procs.begin(), procs.end(), [](auto proc){ return proc.usage.vss == 0; }), procs.end()); qsort(procs.data(), procs.size(), sizeof(procs[0]), compfn); if (has_swap) { uint64_t zram_mem_used = get_zram_mem_used(); if (zram_mem_used) { mem[MEMINFO_ZRAM_TOTAL] = zram_mem_used/1024; zram_cr = (float) mem[MEMINFO_ZRAM_TOTAL] / (mem[MEMINFO_SWAP_TOTAL] - mem[MEMINFO_SWAP_FREE]); has_zram = true; } } printf("%5s ", "PID"); if (oomadj) { printf("%5s ", "oom"); } if (ws) { printf("%7s %7s %7s ", "WRss", "WPss", "WUss"); if (has_swap) { printf("%7s %7s %7s ", "WSwap", "WPSwap", "WUSwap"); if (has_zram) { printf("%7s ", "WZSwap"); } } } else { printf("%8s %7s %7s %7s ", "Vss", "Rss", "Pss", "Uss"); if (has_swap) { printf("%7s %7s %7s ", "Swap", "PSwap", "USwap"); if (has_zram) { printf("%7s ", "ZSwap"); } } } printf("%s\n", "cmdline"); total_pss = 0; total_uss = 0; total_swap = 0; total_pswap = 0; total_uswap = 0; total_zswap = 0; std::vector<uint64_t> lmk_minfree; std::vector<int> lmk_adj; if (oomadj) { getminfree(&lmk_minfree, &lmk_adj); } auto lmk_minfree_it = lmk_minfree.cbegin(); auto lmk_adj_it = lmk_adj.cbegin(); auto print_oomadj_totals = [&](int adj){ for (; lmk_adj_it != lmk_adj.cend() && lmk_minfree_it != lmk_minfree.cend() && adj > *lmk_adj_it; lmk_adj_it++, lmk_minfree_it++) { // Print the cumulative total line printf("%5s ", ""); // pid printf("%5s ", ""); // oomadj if (ws) { printf("%7s %6" PRIu64 "K %6" PRIu64 "K ", "", total_pss / 1024, total_uss / 1024); } else { printf("%8s %7s %6" PRIu64 "K %6" PRIu64 "K ", "", "", total_pss / 1024, total_uss / 1024); } if (has_swap) { printf("%6" PRIu64 "K ", total_swap / 1024); printf("%6" PRIu64 "K ", total_pswap / 1024); printf("%6" PRIu64 "K ", total_uswap / 1024); if (has_zram) { printf("%6" PRIu64 "K ", total_zswap / 1024); } } printf("TOTAL for oomadj < %d (%6" PRIu64 "K)\n", *lmk_adj_it, *lmk_minfree_it / 1024); } }; for (auto& proc: procs) { if (oomadj) { print_oomadj_totals(proc.oomadj); } std::string cmdline = getprocname(proc.pid); total_pss += proc.usage.pss; total_uss += proc.usage.uss; total_swap += proc.usage.swap; printf("%5d ", proc.pid); if (oomadj) { printf("%5d ", proc.oomadj); } if (ws) { printf("%6zuK %6zuK %6zuK ", proc.usage.rss / 1024, proc.usage.pss / 1024, proc.usage.uss / 1024 ); } else { printf("%7zuK %6zuK %6zuK %6zuK ", proc.usage.vss / 1024, proc.usage.rss / 1024, proc.usage.pss / 1024, proc.usage.uss / 1024 ); } if (has_swap) { pm_swapusage_t su; pm_memusage_pswap_get_usage(&proc.usage, &su); printf("%6zuK ", proc.usage.swap / 1024); printf("%6zuK ", su.proportional / 1024); printf("%6zuK ", su.unique / 1024); total_pswap += su.proportional; total_uswap += su.unique; pm_memusage_pswap_free(&proc.usage); if (has_zram) { size_t zpswap = su.proportional * zram_cr; printf("%6zuK ", zpswap / 1024); total_zswap += zpswap; } } printf("%s\n", cmdline.c_str()); } pm_memusage_pswap_destroy(p_swap); if (oomadj) { print_oomadj_totals(INT_MAX); } // Print the separator line printf("%5s ", ""); if (oomadj) { printf("%5s ", ""); } if (ws) { printf("%7s %7s %7s ", "", "------", "------"); } else { printf("%8s %7s %7s %7s ", "", "", "------", "------"); } if (has_swap) { printf("%7s %7s %7s ", "------", "------", "------"); if (has_zram) { printf("%7s ", "------"); } } printf("%s\n", "------"); // Print the total line printf("%5s ", ""); if (oomadj) { printf("%5s ", ""); } if (ws) { printf("%7s %6" PRIu64 "K %6" PRIu64 "K ", "", total_pss / 1024, total_uss / 1024); } else { printf("%8s %7s %6" PRIu64 "K %6" PRIu64 "K ", "", "", total_pss / 1024, total_uss / 1024); } if (has_swap) { printf("%6" PRIu64 "K ", total_swap / 1024); printf("%6" PRIu64 "K ", total_pswap / 1024); printf("%6" PRIu64 "K ", total_uswap / 1024); if (has_zram) { printf("%6" PRIu64 "K ", total_zswap / 1024); } } printf("TOTAL\n"); printf("\n"); if (has_swap) { printf("ZRAM: %" PRIu64 "K physical used for %" PRIu64 "K in swap " "(%" PRIu64 "K total swap)\n", mem[MEMINFO_ZRAM_TOTAL], (mem[MEMINFO_SWAP_TOTAL] - mem[MEMINFO_SWAP_FREE]), mem[MEMINFO_SWAP_TOTAL]); } printf(" RAM: %" PRIu64 "K total, %" PRIu64 "K free, %" PRIu64 "K buffers, " "%" PRIu64 "K cached, %" PRIu64 "K shmem, %" PRIu64 "K slab\n", mem[MEMINFO_TOTAL], mem[MEMINFO_FREE], mem[MEMINFO_BUFFERS], mem[MEMINFO_CACHED], mem[MEMINFO_SHMEM], mem[MEMINFO_SLAB]); return 0; }
int main(int argc,char **argv) { int opt; int digit_optind = 0; char *dbprofile = "/etc/my.cnf"; int lc,lcw,lt,prs,conferr; //Innodb locks number. CNF cnf; cnf.host = (char *)malloc(sizeof(char)*128); cnf.user = (char *)malloc(sizeof(char)*128); cnf.password = (char *)malloc(sizeof(char)*128); cnf.port = 0; cnf.socket = (char *)malloc(sizeof(char)*128); cnf.pidfile = (char *)malloc(sizeof(char)*128); memset(cnf.host,0,128); memset(cnf.user,0,128); memset(cnf.password,0,128); memset(cnf.socket,0,128); memset(cnf.pidfile,0,128); if(argc <= 1){ //如果没有给参数,就去/etc/my.cnf中取 parse_cnf(dbprofile,&cnf); }else{ while(1){ int this_option_optind = optind? optind: 1; int option_index = 0; static struct option long_options[] = { {"osinfo",no_argument,0,'o'}, {"appls",no_argument,0,'a'}, {"bufps",no_argument,0,'b'} }; opt = getopt_long(argc,argv,"h:P:u:p:s:",long_options,&option_index); if(opt == -1) break; switch(opt){ case 'h': sprintf(cnf.host,"%s",optarg); break; case 'P': cnf.port = atoi(optarg); break; case 'u': sprintf(cnf.user,optarg); break; case 'p': sprintf(cnf.password,optarg); break; case 's': sprintf(cnf.socket,optarg); break; default: fprintf(stdout,"Parametera Error"); } } } PLA *pla; pla = (PLA*)malloc(sizeof(PLA)); //定义Osinfo的一个实例 Osinfo *os; int get_os_info_res = 0; os = (Osinfo *)malloc(sizeof(Osinfo)); malloc_os_info(os); os->port = cnf.port; //获取操作系统状态信息 get_os_info_res = get_os_info(os); if(get_os_info_res == -1){ perror("get_os_info()"); exit(1); } /*创建一个数据库快照实例并初始化这个实例。*/ MysqlSnapshot ms; malloc_ms(&ms); /*性能指标信息*/ PERF perf; malloc_perf(&perf); /*Innodb Locks Summary*/ INNODB_LOCK ail[]={0}; INNODB_LOCK **il; il = (INNODB_LOCK **)&ail; INNODB_LOCKWAIT ailw[]={0}; INNODB_LOCKWAIT **ilw; ilw = (INNODB_LOCKWAIT **)&ailw; INNODB_TRX ait[]={0}; INNODB_TRX **it; it = (INNODB_TRX **)&ait; MYPS amps[]={0}; MYPS **procs; procs = (MYPS **)&s; //得到CPU硬件信息 get_cpu_hardinfo(os); //得到内存信息 get_mem_info(os); //得到系统负载信息 get_loadavg_info(os); //得到CPU运行状态 get_cpuavg_info(os); /*创建一个MySQL数据库连接*/ MYSQL *conn = NULL; conn = mysql_init(NULL); //连接到MySQL服务。 mysql_real_connect(conn,cnf.host,cnf.user,cnf.password,NULL,cnf.port,cnf.socket,0); if(conn->net.last_errno != 0){ fprintf(stdout,"%s,host=%s,port=%d,region=%s,sport=%d Connection_ErrMsg=\"%s\",Connection_Errno=%d\n","ParateraDB",os->hostname,os->port,"DatabaseConnection",cnf.port,conn->net.last_error,conn->net.last_errno); exit(conn->net.last_errno); } fprintf(stdout,"%s,host=%s,port=%d,region=%s,sport=%d Connection_errMsg=\"OK\",Connection_Errno=%d\n","ParateraDB",os->hostname,os->port,"DatabaseConnection",cnf.port,conn->net.last_errno); //if(strstr(mysql_get_server_info(conn),"5.6") == NULL){ // fprintf(stderr,"Server Unknown\n"); // exit(0); //} //得到数据库服务器快照信息 get_mysql_snapshot(&ms,conn); //获取系统性能信息 get_perf(&ms,&perf,conn); //打印数据库服务器快照信息 get_process_summary(conn,procs,&prs); //打印数据库服务器快照信息 get_innodb_locks_summary(conn,il,&lc); get_innodb_lockwait_summary(conn,ilw,&lcw); //获取INNODB存储引擎的SQL查询内容. get_innodb_transactions_summary(conn,it,<); //得到文件系统使用信息 get_fsusage(&ms); processlist_analysis(conn,pla); influx_files_output(os,&ms,&perf); influx_appls_output(os,&ms,&perf,pla); influx_locks_output(os,&ms); influx_bufps_output(os,&ms,&perf); influx_query_output(os,&ms,&perf); influx_threads_output(os,&ms,&perf); influx_logs_output(os,&ms,&perf); if(strstr(ms.version,"5.6") != NULL){ ShowSlaveStatus(&ms,conn); influx_slave_status_output(&ms,os); } else if(strstr(ms.version,"5.7") != NULL){ ShowSlaveStatus7(&ms,conn); influx_slave_status_output7(&ms,os); } else{ fprintf(stderr,"Not Support Database Version\n"); } influx_mmtrk_output(os,&ms); influx_wsrep_output(&ms,os); exit(0); }