static void spiflash_setup_xfer(struct spiflash_transaction *trans, uint16_t txlen, uint16_t rxlen) { sg_init(trans->flash_tx_sg, trans->spi_query, txlen); sg_init(trans->flash_rx_sg, trans->spi_response, rxlen); }
LxQtCpuLoad::LxQtCpuLoad(ILxQtPanelPlugin* plugin, QWidget* parent): QFrame(parent), mPlugin(plugin), m_showText(false), m_barOrientation(TopDownBar), m_timerID(-1) { setObjectName("LxQtCpuLoad"); QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(&m_stuff); /* Initialise statgrab */ #ifdef STATGRAB_NEWER_THAN_0_90 sg_init(0); #else sg_init(); #endif /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); } m_font.setPointSizeF(8); settingsChanged(); }
static void send_command(struct nrf_transaction_t *trans, spi_cb *cb, void *data) { struct sg *tx = trans->tx_len ? sg_init(trans->tx_sg, &trans->cmd, 1, trans->tx_data, trans->tx_len) : sg_init(trans->tx_sg, &trans->cmd, 1); struct sg *rx = trans->rx_len ? sg_init(trans->rx_sg, &trans->status, 1, trans->rx_data, trans->rx_len) : sg_init(trans->rx_sg, &trans->status, 1); spi_queue_xfer_sg(&trans->spi_ctx, NRF_SPI_CS, tx, rx, cb, data); }
void spl_board_init(void) { bcu_init(); sbc_init(); sg_init(); uniphier_board_reset(); pll_init(); uniphier_board_init(); led_write(L, 0, , ); clkrst_init(); led_write(L, 1, , ); { int res; res = umc_init(); if (res < 0) { while (1) ; } } led_write(L, 2, , ); enable_dpll_ssc(); led_write(L, 3, , ); }
void sg_concat_front(sg_buf* buf, sg_buf* second){ sg_concat_back(second, buf); *buf = *second; sg_init(buf); }
sg_buf* sg_alloc(void){ sg_buf* b = malloc(sizeof(sg_buf)); if(b) sg_init(b); return b; }
static int do_init(void) { #if HAVE_SETLOCALE if (setlocale(LC_NUMERIC, COLLECTD_LOCALE) == NULL) WARNING("setlocale (\"%s\") failed.", COLLECTD_LOCALE); /* Update the environment, so that libraries that are calling * setlocale(LC_NUMERIC, "") don't accidentally revert these changes. */ unsetenv("LC_ALL"); setenv("LC_NUMERIC", COLLECTD_LOCALE, /* overwrite = */ 1); #endif #if HAVE_LIBKSTAT kc = NULL; update_kstat(); #endif #if HAVE_LIBSTATGRAB if (sg_init( #if HAVE_LIBSTATGRAB_0_90 0 #endif )) { ERROR("sg_init: %s", sg_str_error(sg_get_error())); return -1; } if (sg_drop_privileges()) { ERROR("sg_drop_privileges: %s", sg_str_error(sg_get_error())); return -1; } #endif return plugin_init_all(); } /* int do_init () */
void sg_concat_back(sg_buf* buf, sg_buf* second){ buf->totalLen += second->totalLen; if(buf->last) buf->last->next = second->first; else buf->first = second->first; buf->last = second->last; sg_init(second); }
int main(int argc, char **argv){ sg_network_iface_stats *network_iface_stats; size_t iface_count, i; /* Initialise helper - e.g. logging, if any */ sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL); /* Initialise statgrab */ sg_init(1); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != SG_ERROR_NONE) sg_die("Error. Failed to drop privileges", 1); network_iface_stats = sg_get_network_iface_stats(&iface_count); if(network_iface_stats == NULL) sg_die("Failed to get network interface stats", 1); if (argc != 1) { /* If an argument is given, use bsearch to find just that * interface. */ sg_network_iface_stats key; key.interface_name = argv[1]; network_iface_stats = bsearch(&key, network_iface_stats, iface_count, sizeof *network_iface_stats, sg_network_iface_compare_name); if (network_iface_stats == NULL) { fprintf(stderr, "Interface %s not found\n", argv[1]); exit(1); } iface_count = 1; } printf("Name\tSpeed\tDuplex\n"); for(i = 0; i < iface_count; i++) { printf("%s\t%llu\t", network_iface_stats->interface_name, network_iface_stats->speed); switch (network_iface_stats->duplex) { case SG_IFACE_DUPLEX_FULL: printf("full\n"); break; case SG_IFACE_DUPLEX_HALF: printf("half\n"); break; default: printf("unknown\n"); break; } network_iface_stats++; } exit(0); }
/* * call-seq: * Statgrab.new(drop_privileges=true) * * Set privileges and prepare connections, and then drop privileges. * See <tt>statgrab(3)</tt> manpage. */ static VALUE statgrab_initialize(VALUE self, VALUE args) { if (sg_init()) statgrab_handle_error(); if (rb_ary_shift(args) != Qfalse && sg_drop_privileges()) statgrab_handle_error(); return self; }
LxQtNetworkMonitor::LxQtNetworkMonitor(ILxQtPanelPlugin *plugin, QWidget* parent): QFrame(parent), mPlugin(plugin) { QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(&m_stuff); setLayout(layout); /* Initialise statgrab */ #ifdef STATGRAB_NEWER_THAN_0_90 sg_init(0); #else sg_init(); #endif m_iconList << "modem" << "monitor" << "network" << "wireless"; startTimer(800); settingsChanged(); }
int main(int argc, char **argv) { sg_log_init("libstatgrab-test", "SGTEST_LOG_PROPERTIES", argc ? argv[0] : NULL); sg_init(1); if( 0 != get_params( opt_def, argc, argv ) ) { help(argv[0]); return 1; } if( opt_def[OPT_HLP].optarg.b ) { help(argv[0]); return 0; } else if( opt_def[OPT_LIST].optarg.b ) { print_testable_functions(0); return 0; } else if( opt_def[OPT_RUN].optarg.str ) { size_t *test_routines = NULL; size_t entries = funcnames_to_indices(opt_def[OPT_RUN].optarg.str, &test_routines, 0); int errors = 0; if( 0 == entries ) { die( ESRCH, "no functions to test" ); return 255; } while( opt_def[OPT_NLOOPS].optarg.u-- > 0 ) { size_t func_rel_idx; for( func_rel_idx = 0; func_rel_idx < entries; ++func_rel_idx ) { mark_func(test_routines[func_rel_idx]); if( !run_func( test_routines[func_rel_idx], 0 ) ) { done_func(test_routines[func_rel_idx], 0); ++errors; } else { done_func(test_routines[func_rel_idx], 1); } } } (void)report_testable_functions(0); free(test_routines); return errors; } help(argv[0]); return 1; }
/** Allocate and initialize a new segment. */ Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created) { Segment* sg; s_segments_created_count++; s_segments_alive_count++; if (s_max_segments_alive_count < s_segments_alive_count) s_max_segments_alive_count = s_segments_alive_count; sg = VG_(malloc)("drd.segment.sn.1", sizeof(*sg)); tl_assert(sg); sg_init(sg, creator, created); return sg; }
/** Allocate and initialize a new segment. */ Segment* sg_new(ThreadId const creator, ThreadId const created) { Segment* sg; s_created_segments_count++; s_alive_segments_count++; if (s_max_alive_segments_count < s_alive_segments_count) s_max_alive_segments_count = s_alive_segments_count; sg = VG_(malloc)(sizeof(*sg)); tl_assert(sg); sg_init(sg, creator, created); return sg; }
void spl_board_init(void) { bcu_init(); sbc_init(); sg_init(); uniphier_board_reset(); pll_init(); uniphier_board_init(); led_write(L, 0, , ); memconf_init(); led_write(L, 1, , ); early_clkrst_init(); led_write(L, 2, , ); early_pin_init(); led_write(L, 3, , ); #ifdef CONFIG_SPL_SERIAL_SUPPORT preloader_console_init(); #endif led_write(L, 4, , ); { int res; res = umc_init(); if (res < 0) { while (1) ; } } led_write(L, 5, , ); enable_dpll_ssc(); led_write(L, 6, , ); }
/** Allocate and initialize a new segment. */ Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created) { Segment* sg; s_segments_created_count++; s_segments_alive_count++; if (s_max_segments_alive_count < s_segments_alive_count) s_max_segments_alive_count = s_segments_alive_count; sg = VG_(malloc)("drd.segment.sn.1", sizeof(*sg)); sg_init(sg, creator, created); if (DRD_(g_sg_list)) { DRD_(g_sg_list)->g_prev = sg; sg->g_next = DRD_(g_sg_list); } DRD_(g_sg_list) = sg; return sg; }
int main(int argc, char **argv){ extern char *optarg; int c; int delay = 1; sg_page_stats *page_stats; while ((c = getopt(argc, argv, "d:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); break; } } /* Initialise helper - e.g. logging, if any */ sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL); /* Initialise statgrab */ sg_init(1); register_sig_flagger( SIGINT, &quit ); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != SG_ERROR_NONE) sg_die("Error. Failed to drop privileges", 1); page_stats = sg_get_page_stats_diff(NULL); if(page_stats == NULL) sg_die("Failed to get page stats", 1); while( (page_stats = sg_get_page_stats_diff(NULL)) != NULL){ int ch; printf("Pages in : %llu\n", page_stats->pages_pagein); printf("Pages out : %llu\n", page_stats->pages_pageout); ch = inp_wait(delay); if( quit || (ch == 'q') ) break; } exit(0); }
RazorCpuLoad::RazorCpuLoad(const RazorPanelPluginStartInfo* startInfo, QWidget* parent): RazorPanelPlugin(startInfo, parent), m_showText(false), m_timerID(-1) { setObjectName("CpuLoad"); addWidget(&m_stuff); /* Initialise statgrab */ sg_init(); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); } m_font.setPointSizeF(8); settingsChanged(); }
int main(int argc, char **argv){ sg_mem_stats *mem_stats; sg_swap_stats *swap_stats; long long total, free; /* Initialise helper - e.g. logging, if any */ sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL); /* Initialise statgrab */ sg_init(1); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != SG_ERROR_NONE) sg_die("Error. Failed to drop privileges", 1); if( ((mem_stats = sg_get_mem_stats(NULL)) != NULL) && ((swap_stats = sg_get_swap_stats(NULL)) != NULL) ) { printf("Total memory in bytes : %llu\n", mem_stats->total); printf("Used memory in bytes : %llu\n", mem_stats->used); printf("Cache memory in bytes : %llu\n", mem_stats->cache); printf("Free memory in bytes : %llu\n", mem_stats->free); printf("Swap total in bytes : %llu\n", swap_stats->total); printf("Swap used in bytes : %llu\n", swap_stats->used); printf("Swap free in bytes : %llu\n", swap_stats->free); total = mem_stats->total + swap_stats->total; free = mem_stats->free + swap_stats->free; printf("Total VM usage : %5.2f%%\n", 100 - (((float)total/(float)free))); } else { sg_die("Unable to get VM stats", 1); } exit(0); }
static size_t program_sector(size_t addr) { static struct spi_ctx_bare sp_ctx; static struct sg tx_sg[2]; static uint8_t header[4]; size_t len = FLASH_SECTOR_SIZE; write_enable(); header[0] = EZPORT_SP; header[1] = addr >> 16; header[2] = addr >> 8; header[3] = addr; sg_init(tx_sg, (void *)header, 4, _binary_payload_bin_start + addr, len); spi_queue_xfer_sg(&sp_ctx, EZPORT_SPI_CS, tx_sg, NULL, NULL, NULL); check_status(); return (addr + len); }
int main(int argc, char **argv) { sg_fs_stats *fs_stats; size_t fs_size; /* Initialise helper - e.g. logging, if any */ sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL); /* Initialise statgrab */ sg_init(1); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); return 1; } fs_stats = sg_get_fs_stats(&fs_size); if(fs_stats == NULL) sg_die("Failed to get file systems snapshot", 1); printf( "%-16s %-24s %-8s %16s %16s %16s %7s %7s %7s %7s %9s %9s %7s %7s %7s %7s\n", "device", "mountpt", "fstype", "size", "used", "avail", "i-total", "i-used", "i-free", "i-avail", "io size", "block size", "b-total", "b-used", "b-free", "b-avail"); for( ; fs_size > 0 ; --fs_size, ++fs_stats ) { printf( "%-16s %-24s %-8s %16llu %16llu %16llu %7llu %7llu %7llu %7llu %9llu %9llu %7llu %7llu %7llu %7llu\n", fs_stats->device_name, fs_stats->mnt_point, fs_stats->fs_type, fs_stats->size, fs_stats->used, fs_stats->avail, fs_stats->total_inodes, fs_stats->used_inodes, fs_stats->free_inodes, fs_stats->avail_inodes, fs_stats->io_size, fs_stats->block_size, fs_stats->total_blocks, fs_stats->used_blocks, fs_stats->free_blocks, fs_stats->avail_blocks); } return 0; }
int main(int argc, char **argv) { opterr = 0; while (1) { int c = getopt(argc, argv, "lbmunsot:pf:KMG"); if (c == -1) break; switch (c) { case 'l': display_mode = DISPLAY_LINUX; break; case 'b': display_mode = DISPLAY_BSD; break; case 'm': display_mode = DISPLAY_MRTG; break; case 'u': display_mode = DISPLAY_PLAIN; break; case 'n': repeat_mode = REPEAT_NONE; break; case 's': repeat_mode = REPEAT_FOREVER; break; case 'o': repeat_mode = REPEAT_ONCE; break; case 't': repeat_time = atoi(optarg); break; case 'p': use_cpu_percent = 1; break; case 'f': float_scale_factor = atol(optarg); break; case 'K': bytes_scale_factor = 1024; break; case 'M': bytes_scale_factor = 1024 * 1024; break; case 'G': bytes_scale_factor = 1024 * 1024 * 1024; break; default: usage(); } } if (display_mode == DISPLAY_MRTG) { if ((argc - optind) != 2) die("mrtg mode: must specify exactly two stats"); if (repeat_mode == REPEAT_FOREVER) die("mrtg mode: cannot repeat display"); } if (use_cpu_percent && repeat_mode == REPEAT_NONE) die("CPU percentage usage display requires stat differences"); if (repeat_mode == REPEAT_NONE) use_diffs = 0; else use_diffs = 1; select_interesting(argc - optind, &argv[optind]); /* We don't care if sg_init fails, because we can just display the statistics that can be read as non-root. */ sg_init(); sg_snapshot(); if (sg_drop_privileges() != 0) die("Failed to drop setuid/setgid privileges"); switch (repeat_mode) { case REPEAT_NONE: get_stats(); print_stats(argc, argv); break; case REPEAT_ONCE: get_stats(); sleep(repeat_time); sg_snapshot(); get_stats(); print_stats(argc, argv); break; case REPEAT_FOREVER: while (1) { get_stats(); print_stats(argc, argv); printf("\n"); sleep(repeat_time); sg_snapshot(); } } if (display_mode == DISPLAY_MRTG) { printf("\n"); printf("statgrab\n"); } sg_shutdown(); return 0; }
int main(int argc, char **argv) { sg_log_init("libstatgrab-test", "SGTEST_LOG_PROPERTIES", argc ? argv[0] : NULL); sg_init(1); if( 0 != get_params( opt_def, argc, argv ) ) { help(argv[0]); return 1; } if( opt_def[OPT_HLP].optarg.b ) { help(argv[0]); return 0; } else if( opt_def[OPT_LIST].optarg.b ) { print_testable_functions(0); return 0; } else if( opt_def[OPT_RUN].optarg.str ) { unsigned long numthreads, i; size_t *test_routines = NULL, nfuncs, ok; struct statgrab_testfuncs *sg_testfuncs = get_testable_functions(&nfuncs); size_t entries = funcnames_to_indices(opt_def[OPT_RUN].optarg.str, &test_routines, 0); pthread_t *threadid = NULL; int rc, errors = 0; if( 0 == entries ) { die( ESRCH, "no functions to test" ); return 255; } if( -1 != opt_def[OPT_NTHREADS].optarg.s ) { numthreads = opt_def[OPT_NTHREADS].optarg.u; if( numthreads < entries ) { die( ERANGE, "%s %s - to small number for thread count", argv[0], argv[2] ); } } else if( opt_def[OPT_MTHREADS].optarg.u > 1 ) { numthreads = entries * opt_def[OPT_MTHREADS].optarg.u; } else { numthreads = entries; } if( NULL == ( threadid = calloc( sizeof(threadid[0]), numthreads ) ) ) die( ENOMEM, "%s", argv[0] ); rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); TRACE_LOG_FMT( "multi_threaded", "create %lu threads", numthreads ); for( i = 0; i < numthreads; ++i ) { mark_func(test_routines[i % entries]); rc = pthread_create( &threadid[i], NULL, threadfunc, &test_routines[i % entries] ); prove_libcall("pthread_create", rc); } rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); while( test_counter < numthreads ) sched_yield(); rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); /* The condition has occured. Set the flag and wake up any waiting threads */ conditionMet = 1; TRACE_LOG( "multi_threaded", "Wake up all waiting threads..." ); rc = pthread_cond_broadcast(&cond); prove_libcall("pthread_cond_broadcast", rc); rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); TRACE_LOG( "multi_threaded", "Wait for threads and cleanup" ); do { struct timespec ts = { 1, 0 }; struct timeval tv; gettimeofday(&tv, NULL); ts.tv_sec += tv.tv_sec; rc = pthread_mutex_lock(&mutex); prove_libcall("pthread_mutex_lock", rc); pthread_cond_timedwait(&cond, &mutex, &ts); prove_libcall("pthread_cond_timedwait", rc); ok = report_testable_functions(0); rc = pthread_mutex_unlock(&mutex); prove_libcall("pthread_mutex_unlock", rc); if( ok != nfuncs ) printf( "---------------\n" ); fflush(stdout); } while( ok != nfuncs ); for (i=0; i<numthreads; ++i) { rc = pthread_join(threadid[i], NULL); prove_libcall("pthread_join", rc); } pthread_cond_destroy(&cond); pthread_mutex_destroy(&mutex); for( i = 0; i < nfuncs; ++i ) errors += sg_testfuncs[i].needed - sg_testfuncs[i].succeeded; TRACE_LOG_FMT( "multi_threaded", "Main completed with test_counter = %lu", test_counter ); return errors; } help(argv[0]); return 1; }
void prtm2d_lop(bool adj, bool add, int nm, int nd, float *mod, float *dat) /*< prtm2d linear operator >*/ { int i1,i2,it,is,ig, gx, gz; if(nm!=nx*nz) sf_error("model size mismatch: %d!=%d",nm, nx*nz); if(nd!=nt*ng*ns) sf_error("data size mismatch: %d!=%d",nd,nt*ng*ns); sf_adjnull(adj, add, nm, nd, mod, dat); for(is=0; is<ns; is++) {/* it may be parallized using MPI */ /* initialize is-th source wavefield Ps[] */ memset(sp0[0], 0, nzpad*nxpad*sizeof(float)); memset(sp1[0], 0, nzpad*nxpad*sizeof(float)); if (csdgather){ gxbeg=sxbeg+is*jsx-distx; sg_init(gxz, gzbeg, gxbeg, jgz, jgx, ng); } if(adj){/* migration: mm=Lt dd */ for(it=0; it<nt; it++){ add_source(&sxz[is], sp1, 1, &wlt[it], true); step_forward(sp0, sp1, vv, false); apply_sponge(sp0); apply_sponge(sp1); ptr=sp0; sp0=sp1; sp1=ptr; boundary_rw(sp0, &rwbndr[it*4*(nx+nz)], false); } memset(gp0[0], 0, nzpad*nxpad*sizeof(float)); memset(gp1[0], 0, nzpad*nxpad*sizeof(float)); for (it=nt-1; it >-1; it--) { /* reverse time order, Img[]+=Ps[]* Pg[]; */ if(verb) sf_warning("%d;",it); /* reconstruct source wavefield Ps[] */ boundary_rw(sp0, &rwbndr[it*4*(nx+nz)], true); ptr=sp0; sp0=sp1; sp1=ptr; step_forward(sp0, sp1, vv, false); add_source(&sxz[is], sp1, 1, &wlt[it], false); /* backpropagate receiver wavefield */ for(ig=0;ig<ng; ig++){ gx=gxz[ig]/nz; gz=gxz[ig]%nz; gp1[gx+nb][gz+nb]+=dat[it+ig*nt+is*nt*ng]; } step_forward(gp0, gp1, vv, false); apply_sponge(gp0); apply_sponge(gp1); ptr=gp0; gp0=gp1; gp1=ptr; for(i2=0; i2<nx; i2++) for(i1=0; i1<nz; i1++) mod[i1+nz*i2]+=sp0[i2+nb][i1+nb]*gp1[i2+nb][i1+nb]; } }else{/* Born modeling/demigration: dd=L mm */ for(it=0; it<nt; it++){ /* forward time order, Pg[]+=Ps[]* Img[]; */ if(verb) sf_warning("%d;",it); for(i2=0; i2<nx; i2++) for(i1=0; i1<nz; i1++) gp1[i2+nb][i1+nb]+=sp0[i2+nb][i1+nb]*mod[i1+nz*i2]; ptr=gp0; gp0=gp1; gp1=ptr; apply_sponge(gp0); apply_sponge(gp1); step_forward(gp0, gp1, vv, true); for(ig=0;ig<ng; ig++){ gx=gxz[ig]/nz; gz=gxz[ig]%nz; dat[it+ig*nt+is*nt*ng]+=gp1[gx+nb][gz+nb]; } add_source(&sxz[is], sp1, 1, &wlt[it], true); step_forward(sp0, sp1, vv, false); apply_sponge(sp0); apply_sponge(sp1); ptr=sp0; sp0=sp1; sp1=ptr; } } } }
int main(int argc, char **argv){ int c; int colouron = 0; char *fslist = NULL; time_t last_update = 0; extern int errno; int delay=2; sg_log_init("saidar", "SAIDAR_LOG_PROPERTIES", argc ? argv[0] : NULL); sg_init(1); if(sg_drop_privileges() != 0){ fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); return 1; } #ifdef COLOR_SUPPORT while ((c = getopt(argc, argv, "d:F:cvh")) != -1){ #else while ((c = getopt(argc, argv, "d:F:vh")) != -1){ #endif switch (c){ case 'd': delay = atoi(optarg); if (delay < 1){ fprintf(stderr, "Time must be 1 second or greater\n"); exit(1); } break; #ifdef COLOR_SUPPORT case 'c': colouron = 1; break; #endif case 'v': version_num(argv[0]); break; case 'h': default: usage(argv[0]); return 1; } } if (fslist) { sg_error rc = set_valid_filesystems(fslist); if(rc != SG_ERROR_NONE) die(sg_str_error(rc)); free(fslist); } else { sg_error rc = set_valid_filesystems("!nfs, nfs3, nfs4, cifs, smbfs, samba, autofs"); if(rc != SG_ERROR_NONE) die(sg_str_error(rc)); } signal(SIGWINCH, sig_winch_handler); initscr(); #ifdef COLOR_SUPPORT /* turn on colour */ if (colouron) { if (has_colors()) { start_color(); use_default_colors(); init_pair(1,COLOR_RED,-1); init_pair(2,COLOR_GREEN,-1); init_pair(3,COLOR_YELLOW,-1); init_pair(4,COLOR_BLUE,-1); init_pair(5,COLOR_MAGENTA,-1); init_pair(6,COLOR_CYAN,-1); } else { fprintf(stderr, "Colour support disabled: your terminal does not support colour."); colouron = 0; } } #endif nonl(); curs_set(0); cbreak(); noecho(); timeout(delay * 1000); newwin(0, 0, 0, 0); clear(); if(!get_stats()){ fprintf(stderr, "Failed to get all the stats. Please check correct permissions\n"); endwin(); return 1; } display_headings(); for(;;){ time_t now; int ch = getch(); if (ch == 'q'){ break; } /* To keep the numbers slightly accurate we do not want them * updating more frequently than once a second. */ now = time(NULL); if ((now - last_update) >= 1) { get_stats(); } last_update = now; if(sig_winch_flag) { clear(); display_headings(); sig_winch_flag = 0; } display_data(colouron); } endwin(); sg_shutdown(); return 0; }
int main(int argc, char **argv){ extern char *optarg; int c; time_t last_update = 0; WINDOW *window; extern int errno; int delay=2; sg_init(); if(sg_drop_privileges() != 0){ fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); return 1; } while ((c = getopt(argc, argv, "vhd:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); if (delay < 1){ fprintf(stderr, "Time must be 1 second or greater\n"); exit(1); } break; case 'v': version_num(argv[0]); break; case 'h': default: usage(argv[0]); return 1; break; } } signal(SIGWINCH, sig_winch_handler); initscr(); nonl(); cbreak(); noecho(); timeout(delay * 1000); window=newwin(0, 0, 0, 0); clear(); if(!get_stats()){ fprintf(stderr, "Failed to get all the stats. Please check correct permissions\n"); endwin(); return 1; } display_headings(); for(;;){ time_t now; int ch = getch(); if (ch == 'q'){ break; } /* To keep the numbers slightly accurate we do not want them * updating more frequently than once a second. */ now = time(NULL); if ((now - last_update) >= 1) { get_stats(); } last_update = now; display_data(); } endwin(); return 0; }
int main(int argc, char **argv){ extern char *optarg; int c; int delay = 1; sg_cpu_percents *cpu_percent; sg_cpu_stats *cpu_diff_stats; while ((c = getopt(argc, argv, "d:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); break; } } #ifdef WIN32 delay = delay * 1000; #endif /* Initialise helper - e.g. logging, if any */ sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL); /* Initialise statgrab */ sg_init(1); /* XXX must be replaced by termios/(n)curses function .... if( 0 != setvbuf(stdin, NULL, _IONBF, 0) ) { perror("setvbuf"); exit(1); } */ /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != SG_ERROR_NONE) { sg_die("Error. Failed to drop privileges", 1); } register_sig_flagger( SIGINT, &quit ); /* Throw away the first reading as thats averaged over the machines uptime */ sg_snapshot(); cpu_percent = sg_get_cpu_percents(NULL); if( NULL == cpu_percent ) sg_die("Failed to get cpu stats", 1); /* Clear the screen ready for display the cpu usage */ printf("\033[2J"); while( ( ( cpu_diff_stats = sg_get_cpu_stats_diff(NULL) ) != NULL ) && ( ( cpu_percent = sg_get_cpu_percents_of(sg_last_diff_cpu_percent, NULL) ) != NULL ) ) { int ch; sg_snapshot(); printf("\033[2;2H%-14s : %lld (%6.2f)", "User CPU", cpu_diff_stats->user, cpu_percent->user); printf("\033[3;2H%-14s : %lld (%6.2f)", "Kernel CPU", cpu_diff_stats->kernel, cpu_percent->kernel); printf("\033[4;2H%-14s : %lld (%6.2f)", "IOWait CPU", cpu_diff_stats->iowait, cpu_percent->iowait); printf("\033[5;2H%-14s : %lld (%6.2f)", "Swap CPU", cpu_diff_stats->swap, cpu_percent->swap); printf("\033[6;2H%-14s : %lld (%6.2f)", "Nice CPU", cpu_diff_stats->nice, cpu_percent->nice); printf("\033[7;2H%-14s : %lld (%6.2f)", "Idle CPU", cpu_diff_stats->idle, cpu_percent->idle); printf("\033[8;2H%-14s : %llu", "Ctxts", cpu_diff_stats->context_switches); printf("\033[9;2H%-14s : %llu", " Voluntary", cpu_diff_stats->voluntary_context_switches); printf("\033[10;2H%-14s : %llu", " Involuntary", cpu_diff_stats->involuntary_context_switches); printf("\033[11;2H%-14s : %llu", "Syscalls", cpu_diff_stats->syscalls); printf("\033[12;2H%-14s : %llu", "Intrs", cpu_diff_stats->interrupts); printf("\033[13;2H%-14s : %llu", "SoftIntrs", cpu_diff_stats->soft_interrupts); fflush(stdout); ch = inp_wait(delay); if( quit || (ch == 'q') ) break; } sg_shutdown(); exit(0); }
int main(int argc, char* argv[]) { int it,kt,ia,is,i1,i2,tdmute,jsx,jsz,jgx,jgz,sxbeg,szbeg,gxbeg,gzbeg, distx, distz; int *sxz, *gxz; float tmp, amp, vmax; float *wlt, *d2x, *d1z, *bndr; float **v0, **vv, **dcal, **den; float **sp, **spz, **spx, **svz, **svx, **gp, **gpz, **gpx, **gvz, **gvx; float ***num, ***adcig; sf_file vmodl, rtmadcig, vecx, vecz; /* I/O files */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); #endif /*< set up I/O files >*/ vmodl = sf_input ("in"); /* velocity model, unit=m/s */ rtmadcig = sf_output("out"); /* ADCIG obtained by Poynting vector */ vecx=sf_output("vecx"); vecz=sf_output("vecz"); /* get parameters for RTM */ if (!sf_histint(vmodl,"n1",&nz)) sf_error("no n1"); if (!sf_histint(vmodl,"n2",&nx)) sf_error("no n2"); if (!sf_histfloat(vmodl,"d1",&dz)) sf_error("no d1"); if (!sf_histfloat(vmodl,"d2",&dx)) sf_error("no d2"); if (!sf_getfloat("amp",&)) amp=1.e3; /* maximum amplitude of ricker wavelet*/ if (!sf_getfloat("fm",&fm)) sf_error("no fm"); /* dominant freq of ricker */ if (!sf_getfloat("dt",&dt)) sf_error("no dt"); /* time interval */ if (!sf_getint("nt",&nt)) sf_error("no nt"); /* total modeling time steps */ if (!sf_getint("ns",&ns)) sf_error("no ns"); /* total shots */ if (!sf_getint("ng",&ng)) sf_error("no ng"); /* total receivers in each shot */ if (!sf_getint("nb",&nb)) nb=20; /* thickness of split PML */ if (!sf_getint("na",&na)) na=30; /* number of angles*/ if (!sf_getint("kt",&kt)) kt=200; /* record poynting vector at kt */ if (!sf_getint("jsx",&jsx)) sf_error("no jsx"); /* source x-axis jump interval */ if (!sf_getint("jsz",&jsz)) jsz=0; /* source z-axis jump interval */ if (!sf_getint("jgx",&jgx)) jgx=1; /* receiver x-axis jump interval */ if (!sf_getint("jgz",&jgz)) jgz=0; /* receiver z-axis jump interval */ if (!sf_getint("sxbeg",&sxbeg)) sf_error("no sxbeg"); /* x-begining index of sources, starting from 0 */ if (!sf_getint("szbeg",&szbeg)) sf_error("no szbeg"); /* z-begining index of sources, starting from 0 */ if (!sf_getint("gxbeg",&gxbeg)) sf_error("no gxbeg"); /* x-begining index of receivers, starting from 0 */ if (!sf_getint("gzbeg",&gzbeg)) sf_error("no gzbeg"); /* z-begining index of receivers, starting from 0 */ if (!sf_getbool("csdgather",&csdgather)) csdgather=true; /* default, common shot-gather; if n, record at every point*/ if (!sf_getfloat("vmute",&vmute)) vmute=1500; /* muting velocity to remove the low-freq noise, unit=m/s*/ if (!sf_getint("tdmute",&tdmute)) tdmute=2./(fm*dt); /* number of deleyed time samples to mute */ _dx=1./dx; _dz=1./dz; nzpad=nz+2*nb; nxpad=nx+2*nb; da=SF_PI/(float)na;/* angle unit, rad; */ var=da/3.; var=2.0*var*var; sf_putint(rtmadcig,"n1",nz); sf_putint(rtmadcig,"n2",nx); sf_putfloat(rtmadcig,"n3",na); sf_putfloat(rtmadcig,"d1",dz); sf_putfloat(rtmadcig,"d2",dx); sf_putfloat(rtmadcig,"d3",90./(float)na); /* allocate variables */ wlt=sf_floatalloc(nt); v0=sf_floatalloc2(nz,nx); vv=sf_floatalloc2(nzpad, nxpad); sp =sf_floatalloc2(nzpad, nxpad); spz=sf_floatalloc2(nzpad, nxpad); spx=sf_floatalloc2(nzpad, nxpad); svz=sf_floatalloc2(nzpad, nxpad); svx=sf_floatalloc2(nzpad, nxpad); gp =sf_floatalloc2(nzpad, nxpad); gpz=sf_floatalloc2(nzpad, nxpad); gpx=sf_floatalloc2(nzpad, nxpad); gvz=sf_floatalloc2(nzpad, nxpad); gvx=sf_floatalloc2(nzpad, nxpad); d1z=sf_floatalloc(nzpad); d2x=sf_floatalloc(nxpad); sxz=sf_intalloc(ns); gxz=sf_intalloc(ng); dcal=sf_floatalloc2(ng,nt); bndr=(float*)malloc(nt*8*(nx+nz)*sizeof(float)); den=sf_floatalloc2(nz,nx); num=sf_floatalloc3(nz,nx,na); adcig=sf_floatalloc3(nz,nx,na); /* initialize variables */ for(it=0;it<nt;it++){ tmp=SF_PI*fm*(it*dt-1.0/fm);tmp*=tmp; wlt[it]=amp*(1.0-2.0*tmp)*expf(-tmp); } sf_floatread(v0[0],nz*nx,vmodl); expand2d(vv, v0); memset(sp [0],0,nzpad*nxpad*sizeof(float)); memset(spx[0],0,nzpad*nxpad*sizeof(float)); memset(spz[0],0,nzpad*nxpad*sizeof(float)); memset(svx[0],0,nzpad*nxpad*sizeof(float)); memset(svz[0],0,nzpad*nxpad*sizeof(float)); memset(gp [0],0,nzpad*nxpad*sizeof(float)); memset(gpx[0],0,nzpad*nxpad*sizeof(float)); memset(gpz[0],0,nzpad*nxpad*sizeof(float)); memset(gvx[0],0,nzpad*nxpad*sizeof(float)); memset(gvz[0],0,nzpad*nxpad*sizeof(float)); vmax=v0[0][0]; for(i2=0; i2<nx; i2++) for(i1=0; i1<nz; i1++) vmax=SF_MAX(v0[i2][i1],vmax); pmlcoeff_init(d1z, d2x, vmax); if (!(sxbeg>=0 && szbeg>=0 && sxbeg+(ns-1)*jsx<nx && szbeg+(ns-1)*jsz<nz)) { sf_error("sources exceeds the computing zone!"); exit(1);} sg_init(sxz, szbeg, sxbeg, jsz, jsx, ns); distx=sxbeg-gxbeg; distz=szbeg-gzbeg; if (csdgather) { if (!(gxbeg>=0 && gzbeg>=0 && gxbeg+(ng-1)*jgx<nx && gzbeg+(ng-1)*jgz<nz && (sxbeg+(ns-1)*jsx)+(ng-1)*jgx-distx <nx && (szbeg+(ns-1)*jsz)+(ng-1)*jgz-distz <nz)) { sf_error("geophones exceeds the computing zone!"); exit(1);} }else{ if (!(gxbeg>=0 && gzbeg>=0 && gxbeg+(ng-1)*jgx<nx && gzbeg+(ng-1)*jgz<nz)) { sf_error("geophones exceeds the computing zone!"); exit(1);} } sg_init(gxz, gzbeg, gxbeg, jgz, jgx, ng); memset(adcig[0][0], 0, na*nz*nx*sizeof(float)); for(is=0; is<ns; is++) { wavefield_init(sp, spz, spx, svz, svx); if (csdgather) { gxbeg=sxbeg+is*jsx-distx; sg_init(gxz, gzbeg, gxbeg, jgz, jgx, ng); } for(it=0; it<nt; it++) { add_source(&sxz[is], sp, 1, &wlt[it], true); step_forward(sp, spz, spx, svz, svx, vv, d1z, d2x); bndr_rw(false, svz, svx, &bndr[it*8*(nx+nz)]); record_seis(dcal[it], gxz, sp, ng); muting(dcal[it], gzbeg, szbeg, gxbeg, sxbeg+is*jsx, jgx, it, tdmute); } wavefield_init(gp, gpz, gpx, gvz, gvx); memset(num[0][0], 0, na*nz*nx*sizeof(float)); memset(den[0], 0, nz*nx*sizeof(float)); for(it=nt-1; it>-1; it--) { add_source(gxz, gp, ng, dcal[it], true); step_forward(gp, gpz, gpx, gvz, gvx, vv, d1z, d2x); if(it==kt) { window2d(v0,svx); sf_floatwrite(v0[0],nz*nx,vecx); window2d(v0,svz); sf_floatwrite(v0[0],nz*nx,vecz); } bndr_rw(true, svz, svx, &bndr[it*8*(nx+nz)]); cross_correlation(num, den, sp, gp, svz, svx, gvz, gvx); step_backward(sp, svz, svx, vv); add_source(&sxz[is], sp, 1, &wlt[it], false); } for(ia=0; ia<na; ia++) for(i2=0; i2<nx; i2++) for(i1=0; i1<nz; i1++) adcig[ia][i2][i1]+=num[ia][i2][i1]/(den[i2][i1]+SF_EPS); } sf_floatwrite(adcig[0][0], na*nz*nx,rtmadcig); free(wlt); free(*v0); free(v0); free(*vv); free(vv); free(*sp); free(sp); free(*spx); free(spx); free(*spz); free(spz); free(*svx); free(svx); free(*svz); free(svz); free(*gp); free(gp); free(*gpx); free(gpx); free(*gpz); free(gpz); free(*gvx); free(gvx); free(*gvz); free(gvz); free(d1z); free(d2x); free(sxz); free(gxz); free(bndr); free(*den); free(den); free(**num); free(*num); free(num); free(**adcig); free(*adcig); free(adcig); exit(0); }
int main(int argc, char **argv) { extern char *optarg; int c; /* We default to 1 second updates and displaying in bytes*/ int delay = 1; char units = 'b'; sg_disk_io_stats *diskio_stats; int num_diskio_stats; /* Parse command line options */ while ((c = getopt(argc, argv, "d:bkm")) != -1) { switch (c) { case 'd': delay = atoi(optarg); break; case 'b': units = 'b'; break; case 'k': units = 'k'; break; case 'm': units = 'm'; break; } } /* Initialise statgrab */ sg_init(); /* Drop setuid/setgid privileges. */ if (sg_drop_privileges() != 0) { perror("Error. Failed to drop privileges"); return 1; } /* We are not interested in the amount of traffic ever transmitted, just differences. * Because of this, we do nothing for the very first call. */ diskio_stats = sg_get_disk_io_stats_diff(&num_diskio_stats); if (diskio_stats == NULL) { perror("Error. Failed to get disk stats"); return 1; } /* Clear the screen ready for display the disk stats */ printf("\033[2J"); /* Keep getting the disk stats */ while ( (diskio_stats = sg_get_disk_io_stats_diff(&num_diskio_stats)) != NULL) { int x; int line_number = 2; long long total_write=0; long long total_read=0; for(x = 0; x < num_diskio_stats; x++) { /* Print at location 2, linenumber the interface name */ printf("\033[%d;2H%-25s : %-10s", line_number++, "Disk Name", diskio_stats->disk_name); /* Print out at the correct location the traffic in the requsted units passed at command time */ switch(units) { case 'b': printf("\033[%d;2H%-25s : %8lld b", line_number++, "Disk read", diskio_stats->read_bytes); printf("\033[%d;2H%-25s : %8lld b", line_number++, "Disk write", diskio_stats->write_bytes); break; case 'k': printf("\033[%d;2H%-25s : %5lld k", line_number++, "Disk read", (diskio_stats->read_bytes / 1024)); printf("\033[%d;2H%-25s : %5lld", line_number++, "Disk write", (diskio_stats->write_bytes / 1024)); break; case 'm': printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Disk read", diskio_stats->read_bytes / (1024.00*1024.00)); printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Disk write", diskio_stats->write_bytes / (1024.00*1024.00)); } printf("\033[%d;2H%-25s : %ld ", line_number++, "Disk systime", (long) diskio_stats->systime); /* Add a blank line between interfaces */ line_number++; /* Add up this interface to the total so we can display a "total" disk io" */ total_write+=diskio_stats->write_bytes; total_read+=diskio_stats->read_bytes; /* Move the pointer onto the next interface. Since this returns a static buffer, we dont need * to keep track of the orginal pointer to free later */ diskio_stats++; } printf("\033[%d;2H%-25s : %-10s", line_number++, "Disk Name", "Total Disk IO"); switch(units) { case 'b': printf("\033[%d;2H%-25s : %8lld b", line_number++, "Disk Total read", total_read); printf("\033[%d;2H%-25s : %8lld b", line_number++, "Disk Total write", total_write); break; case 'k': printf("\033[%d;2H%-25s : %5lld k", line_number++, "Disk Total read", (total_read / 1024)); printf("\033[%d;2H%-25s : %5lld k", line_number++, "Disk Total write", (total_write / 1024)); break; case 'm': printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Disk Total read", (total_read / (1024.00*1024.00))); printf("\033[%d;2H%-25s : %5.2f m", line_number++, "Disk Total write", (total_write / (1024.00*1024.00))); break; } fflush(stdout); sleep(delay); } return 0; }
bool DataSourceStatgrab::InitStatgrab() { if( SG_ERROR_NONE != sg_init(1) ) { report_sg_error("InitDataSourceStatgrab", "sg_init() failed"); return false; } const StatgrabSettings & sgs = Config::getInstance().getStatgrabSettings(); if( !sgs.ValidFilesystems.empty() ) { vector<const char *> newValidFs; set<string> buildValidFs; if( sgs.RemoveFilesystems ) { const char **old_valid_fs = sg_get_valid_filesystems(0); if( 0 == old_valid_fs ) { LOG_BEGIN(loggerModuleName, ERROR_LOG | 0); LOG("InitDataSourceStatgrab(): sg_get_valid_filesystems() failed"); LOG_END; return false; } while( *old_valid_fs ) { buildValidFs.insert(*old_valid_fs); ++old_valid_fs; } for( vector<string>::const_iterator iter = sgs.ValidFilesystems.begin(); iter != sgs.ValidFilesystems.end(); ++iter ) { set<string>::iterator jter = buildValidFs.find( *iter ); if( jter != buildValidFs.end() ) buildValidFs.erase(jter); } } else { for( vector<string>::const_iterator iter = sgs.ValidFilesystems.begin(); iter != sgs.ValidFilesystems.end(); ++iter ) { buildValidFs.insert(*iter); } } newValidFs.reserve( buildValidFs.size() + 1 ); for( set<string>::const_iterator iter = buildValidFs.begin(); iter != buildValidFs.end(); ++iter ) { newValidFs.push_back( iter->c_str() ); } newValidFs.push_back( 0 ); if( SG_ERROR_NONE != sg_set_valid_filesystems( &newValidFs[0] ) ) { report_sg_error("InitDataSourceStatgrab", "sg_set_valid_filesystems() failed"); return false; } } return true; }