static NVRAM_HANDLER( bmcbowl ) { int i; if (read_or_write) mame_fwrite(file, stats_ram, stats_ram_size); else #ifdef NVRAM_HACK for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; init_stats(bmc_nv1,ARRAY_LENGTH(bmc_nv1),0); init_stats(bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0); init_stats(bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2); #else if (file) mame_fread(file, stats_ram, stats_ram_size); else for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; #endif }
static NVRAM_HANDLER( bmcbowl ) { bmcbowl_state *state = machine.driver_data<bmcbowl_state>(); int i; if (read_or_write) file->write(state->m_stats_ram, state->m_stats_ram_size); else #ifdef NVRAM_HACK for (i = 0; i < state->m_stats_ram_size; i++) state->m_stats_ram[i] = 0xff; init_stats(state,bmc_nv1,ARRAY_LENGTH(bmc_nv1),0); init_stats(state,bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0); init_stats(state,bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2); #else if (file) file->read(state->m_stats_ram, state->m_stats_ram_size); else for (i = 0; i < state->m_stats_ram_size; i++) state->m_stats_ram[i] = 0xff; #endif }
static NVRAM_HANDLER( bmc_nvram ) { int i; if (read_or_write) mame_fwrite(file, stats_ram, stats_ram_size); else #ifdef NVRAM_HACK for (i = 0; i < stats_ram_size; i++) { stats_ram[i] = 0xff; init_stats(bmc_nv1,0); init_stats(bmc_nv2,0x3b0); init_stats(bmc_nv3,0xfe2); } #else if (file) mame_fread(file, stats_ram, stats_ram_size); else for (i = 0; i < stats_ram_size; i++) stats_ram[i] = 0xff; #endif }
void bmcbowl_state::machine_reset() { #ifdef NVRAM_HACK for (int i = 0; i < m_stats_ram.bytes(); i++) m_stats_ram[i] = 0xff; init_stats(this,bmc_nv1,ARRAY_LENGTH(bmc_nv1),0); init_stats(this,bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0); init_stats(this,bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2); #endif }
void olsr_init_tuples(struct olsrv2 *olsr) { olsr->changes_topology = OLSR_FALSE; olsr->changes_neighborhood = OLSR_FALSE; flash_change_flags(olsr); init_rcv_msg_set(olsr); init_proc_set(olsr); init_relay_set(olsr); init_forward_set(olsr); init_link_set(olsr); init_2neigh_set(olsr); init_topology_set(olsr); init_routing_set(olsr); init_mpr_set(olsr); init_mpr_selector_set(olsr); init_stats(olsr); init_symmetric_neighbor_set(olsr); init_association_set(olsr); init_adv_neigh_set(olsr); init_relay_set(olsr); init_assn_history_set(olsr); init_attached_set(olsr); }
proxy_t::proxy_t(McrouterInstance& rtr) : router_(rtr), destinationMap(folly::make_unique<ProxyDestinationMap>(this)), randomGenerator(folly::randomNumberSeed()), fiberManager( fiber_local::ContextTypeTag(), folly::make_unique<folly::fibers::EventBaseLoopController>(), getFiberManagerOptions(router_.opts())) { memset(stats, 0, sizeof(stats)); memset(stats_bin, 0, sizeof(stats_bin)); memset(stats_num_within_window, 0, sizeof(stats_num_within_window)); static uint64_t next_magic = 0x12345678900000LL; magic = __sync_fetch_and_add(&next_magic, 1); init_stats(stats); messageQueue_ = folly::make_unique<MessageQueue<ProxyMessage>>( router_.opts().client_queue_size, [this] (ProxyMessage&& message) { this->messageReady(message.type, message.data); }, router_.opts().client_queue_no_notify_rate, router_.opts().client_queue_wait_threshold_us, &nowUs, [this] () { stat_incr_safe(stats, client_queue_notifications_stat); } ); statsContainer = folly::make_unique<ProxyStatsContainer>(*this); }
/** * detector_init - Standard module initialization code */ static int detector_init(void) { int ret = -ENOMEM; printk(KERN_INFO BANNER "version %s\n", VERSION); ret = init_stats(); if (0 != ret) goto out; ret = init_debugfs(); if (0 != ret) goto err_stats; if (enabled) ret = start_kthread(); goto out; err_stats: ring_buffer_free(ring_buffer); out: return ret; }
void TSPluginInit(int argc, const char *argv[]) { const char prefix[] = "http://"; int uri_len; TSPluginRegistrationInfo info; info.plugin_name = "redirect-1"; info.vendor_name = "MyCompany"; info.support_email = "*****@*****.**"; if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) { TSError("Plugin registration failed.\n"); } if (!check_ts_version()) { TSError("Plugin requires Traffic Server 3.0 or later\n"); return; } if (argc == 3) { block_ip = TSstrdup(argv[1]); /* * The Location header must contain an absolute URI: */ url_redirect = TSstrdup(argv[2]); uri_len = strlen(prefix) + strlen(url_redirect) + 1; uri_redirect = TSmalloc(uri_len); TSstrlcpy(uri_redirect, prefix, uri_len); TSstrlcat(uri_redirect, url_redirect, uri_len); } else { TSError("Incorrect syntax in plugin.conf: correct usage is" "redirect-1.so ip_deny url_redirect"); return; } ip_deny = inet_addr(block_ip); TSDebug("redirect_init", "initializing stats..."); init_stats(); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL)); TSDebug("redirect_init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s", block_ip, url_redirect, uri_redirect); // ToDo: Should figure out how to print IPs which are IPv4 / v6. // TSDebug("redirect_init", "ip_deny is %ld\n", ip_deny); /* * Demonstrate another tracing function. This can be used to * enable debug calculations and other work that should only * be done in debug mode. */ if (TSIsDebugTagSet("redirect_demo")) TSDebug("redirect_init", "The redirect_demo tag is set"); else TSDebug("redirect_init", "The redirect_demo tag is not set"); }
/** * Main program * @return */ int main(int argc, char** argv) { // document root char* docroot = open_documentroot(argc, argv); int server = creer_serveur(WEBSERVER_PORT); printf("Server launched:\n"); // Mimes loadMimes(); // Load stats init_stats(); // Signaux initialiser_signaux(); /** * Get client request * @return */ createClient(server, docroot); return 0; }
int menu(t_assets *assets) { t_stats stats; int end; int play; int window; end = 0; play = 0; window = 0; srand(time(NULL)); while (!end) { if (Mix_PlayingMusic() != 1) Mix_PlayMusic(assets->sounds.menumusic, -1); events_menu(&play, &end, &window); show_menu(assets, &window, end, play); if (play) { init_stats(&stats); play_game(assets, &stats); show_stats(&stats); play = 0; Mix_PlayMusic(assets->sounds.menumusic, -1); } } return (0); }
Clustering::Clustering(const SparseMatrix& a, const OptimizationParams& params, ClusteringStats* sub_stats, double extra_loss_self) : params(params) , trace_out(params.trace_out) , neighbors(a.cols()) , node_perm(a.cols()) , clus_size(a.cols()) , extra_loss_self(extra_loss_self) , a(a) , node_clus(a.cols()) { // parameters that make no sense if (this->params.min_num_clusters < 0) { throw std::invalid_argument("min_num_clusters should be non-negative"); } if (this->params.max_num_clusters <= 0) { throw std::invalid_argument("max_num_clusters should be positive"); } // intialize node_perm and node_stats. // These don't depend on the clustering, so they don't have to go into recalc_internal_data() for (size_t i = 0 ; i < node_perm.size() ; ++i) { node_perm[i] = i; } if (sub_stats) { node_stats = *sub_stats; } else { init_stats(node_stats, a, NULL, sub_stats); } // initial clustering reset_to_singletons(); }
void Clustering::verify_clus_stats() const { #define error(X...) {printf(X); throw std::logic_error("verify cluster stats failed");} #define check(sub,str,ii) \ if (abs(clus_stats sub - cs sub) > validate_epsilon) \ error("At " str " %f != %f (diff: %g)\n",ii,clus_stats sub, cs sub, clus_stats sub - cs sub) ClusteringStats cs; init_stats(cs, a, &node_clus[0], &node_stats); for (size_t i = 0 ; i < clus_stats.size() ; ++i) { check([i].degree,"[%d].degree",(int)i); check([i].self,"[%d].self",(int)i); check([i].size,"[%d].size",(int)i); } check(.total.degree,"%s.degree","total"); check(.total.self,"%s.self","total"); check(.total.size,"%s.size","total"); Doubles new_sl; double new_loss = params.lossfun->loss(cs, num_clusters(), &new_sl) + extra_loss_self * cs.total.self / cs.total.degree; if (abs(loss - new_loss) > validate_epsilon) { error("Incorrect loss update: %f != %f\n",loss,new_loss); } for (int i = 0 ; i < MAX_DOUBLES ; ++i) { if (abs(sum_local_loss[i] - new_sl[i]) > validate_epsilon) { error("Incorrect local loss [%d] update: %f != %f\n",i, sum_local_loss[i], new_sl[i]); } } #undef check }
/** * @brief Initialize the MapReduce configuration. */ static void init_mr_config (void) { srand (12345); init_config (); init_stats (); init_job (); distribute_data (); }
static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) { int i; struct perf_stat *ps = evsel->priv; for (i = 0; i < 3; i++) init_stats(&ps->res_stats[i]); }
void stats_tic (char *statname) { if (load_ctr < 0) init_stats (); memset (&stats_tic_data.statname, 0, sizeof (stats_tic_data.statname)); strncpy (&stats_tic_data.statname, statname, 256); get_stats (&stats_tic_data); }
gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free) { kstat_t *ksp; kstat_named_t *knp; gint n; if (!kc) init_stats(); if (!(ksp = kstat_lookup (kc, "unix", 0, "system_pages"))) return FALSE; kstat_read (kc, ksp, NULL); knp = kstat_data_lookup (ksp, "physmem"); *memory_total = getpagesize () * knp->value.ui64; knp = kstat_data_lookup (ksp, "freemem"); *memory_free = getpagesize () * knp->value.ui64; *memory_cache = 0; *memory_buffers = 0; *swap_total = *swap_free = 0; if ((n = swapctl (SC_GETNSWP, NULL)) > 0) { struct swaptable *st; struct swapent *swapent; gchar path[MAXPATHLEN]; gint i; if ((st = malloc (sizeof (int) + n * sizeof (swapent_t))) == NULL) return FALSE; st->swt_n = n; swapent = st->swt_ent; for (i = 0; i < n; i++, swapent++) swapent->ste_path = path; if ((swapctl (SC_LIST, st)) == -1) { free (st); return FALSE; } swapent = st->swt_ent; for (i = 0; i < n; i++, swapent++) { *swap_total += swapent->ste_pages * getpagesize (); *swap_free += swapent->ste_free * getpagesize (); } free (st); } return TRUE; }
void main (int argc, char *argv[]) { if (argc != 2) { printf ("usage: %s <0|1>", argv[0]); exit (1); } if (strncmp (argv[1], "0") == 0) { init_stats ("utrecht", 50000, 0); init_graphs (1, "Title1.Title2", "Aegis.Ultrix", 20, "3.0", "5.0"); stats_enable (0); } else { init_stats ("utrecht", 50000, 1); } stats_barrier (); sleep (2); stats_done (1); }
player_t init_player(char symbol, int x, int y, int max_hp) { player_t player; player.symbol = symbol; player.x = x; player.y = y; player.stats = init_stats(max_hp, max_hp, 12, 12, 12, 12); return player; }
void init_player(WINDOW* mapw, WINDOW* stats, WINDOW* hp, WINDOW* area, WINDOW* examine, map* start_map) { map_win = mapw; stats_win = stats; hp_win = hp; area_win = area; examine_win = examine; init_stats(); current_map = start_map; }
void TSPluginInit(int argc, const char *argv[]) { const char prefix[] = "http://"; int uri_len; TSPluginRegistrationInfo info; info.plugin_name = PLUGIN_NAME; info.vendor_name = "Apache Software Foundation"; info.support_email = "*****@*****.**"; if (TSPluginRegister(&info) != TS_SUCCESS) { TSError("[%s] Plugin registration failed", PLUGIN_NAME); } if (argc == 3) { block_ip = TSstrdup(argv[1]); /* * The Location header must contain an absolute URI: */ url_redirect = TSstrdup(argv[2]); uri_len = strlen(prefix) + strlen(url_redirect) + 1; uri_redirect = TSmalloc(uri_len); TSstrlcpy(uri_redirect, prefix, uri_len); TSstrlcat(uri_redirect, url_redirect, uri_len); } else { TSError("[%s] Incorrect syntax in plugin.conf: correct usage is", PLUGIN_NAME "redirect_1.so ip_deny url_redirect"); return; } ip_deny = inet_addr(block_ip); TSDebug(PLUGIN_NAME, "initializing stats"); init_stats(); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL)); TSDebug(PLUGIN_NAME ".init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s", block_ip, url_redirect, uri_redirect); /* * Demonstrate another tracing function. This can be used to * enable debug calculations and other work that should only * be done in debug mode. */ if (TSIsDebugTagSet(PLUGIN_NAME ".demo")) { TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is set"); } else { TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is not set"); } }
int main() // int argc, char* argv) { init_stats(&stats); board_t* board = new_board(); if (false == load_board(board)) { printf("bad board\n"); } else { printf("loaded board:\n"); print_board(board); solve_board(board); } // print_board(board); return 0; }
gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) { kstat_t *ksp; kstat_named_t *knp; static gulong ticks_total = 0, ticks_total_old = 0; gulong ticks_user = 0, ticks_system = 0; if (!kc) init_stats (); _cpu_count = 0; kstat_chain_update (kc); ticks_total_old = ticks_total; ticks_total = 0; for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { if (!g_strcmp0 (ksp->ks_module, "cpu_info")) { _cpu_count += 1; } else if (!g_strcmp0 (ksp->ks_module, "cpu") && !g_strcmp0 (ksp->ks_name, "sys")) { kstat_read (kc, ksp, NULL); knp = kstat_data_lookup (ksp, "cpu_nsec_user"); ticks_user += knp->value.ul / 100000; knp = kstat_data_lookup (ksp, "cpu_nsec_kernel"); ticks_system += knp->value.ul / 100000; knp = kstat_data_lookup (ksp, "cpu_nsec_intr"); ticks_system += knp->value.ul / 100000; knp = kstat_data_lookup (ksp, "cpu_nsec_idle"); ticks_total += knp->value.ul / 100000; ticks_total += ticks_user + ticks_system; } } if (ticks_total > ticks_total_old) ticks_total_delta = ticks_total - ticks_total_old; get_cpu_percent (0, ticks_user, cpu_user, ticks_system, cpu_system); *cpu_count = _cpu_count; return TRUE; }
void matlib_main() { MATRIX *A, *B, *C; MATRIX *At, *Bt; long n, ni, i; double sum; random_1(-1); n = query_long("dimension of arrays", 3L); ni = query_long("number of iterations", 100L); #ifdef VAX_VMS init_stats(); #endif m_alloc(&A, n, n); m_alloc(&At, n, n); m_alloc(&B, n, n); m_alloc(&Bt, n, n); m_alloc(&C, n, n); for (i=sum=0; i<ni; i++) { m_rand(At, -1.0L, 1.0L); m_trans(A, At); m_invert(B, A); m_mult(C, A, B); sum += fabs(m_det(C)-1.0); } m_free(&A); m_free(&At); m_free(&B); m_free(&Bt); m_free(&C); printf("M.A.D.{DET{A.INV(A))}-1} = %e\n", sum/ni); #ifdef VAX_VMS report_stats(stdout, "stats: "); #endif }
/* *************************************************************************** * Allocate and init structures, according to system state. *************************************************************************** */ void io_sys_init(void) { /* Allocate and init stat common counters */ init_stats(); /* How many processors on this machine? */ cpu_nr = get_cpu_nr(~0, FALSE); /* Get number of block devices and partitions in /proc/diskstats */ if ((iodev_nr = get_diskstats_dev_nr(CNT_PART, CNT_ALL_DEV)) > 0) { flags |= I_F_HAS_DISKSTATS; iodev_nr += NR_DEV_PREALLOC; } if (!HAS_DISKSTATS(flags) || (DISPLAY_PARTITIONS(flags) && !DISPLAY_PART_ALL(flags))) { /* * If /proc/diskstats exists but we also want stats for the partitions * of a particular device, stats will have to be found in /sys. So we * need to know if /sys is mounted or not, and set flags accordingly. */ /* Get number of block devices (and partitions) in sysfs */ if ((iodev_nr = get_sysfs_dev_nr(DISPLAY_PARTITIONS(flags))) > 0) { flags |= I_F_HAS_SYSFS; iodev_nr += NR_DEV_PREALLOC; } else { fprintf(stderr, _("Cannot find disk data\n")); exit(2); } } /* Also allocate stat structures for "group" devices */ iodev_nr += group_nr; /* * Allocate structures for number of disks found, but also * for groups of devices if option -g has been entered on the command line. * iodev_nr must be <> 0. */ salloc_device(iodev_nr); }
void Clustering::recalc_internal_data() { if (params.check_invariants) verify_partition(); // recalculate accumulated degrees init_stats(clus_stats, a, &node_clus[0], &node_stats); // find empty clusters fill(clus_size.begin(),clus_size.end(), 0); empty_cluss.clear(); for (size_t i = 0 ; i < node_clus.size() ; ++i) { clus_size[node_clus[i]]++; } for (size_t i = 0 ; i < clus_stats.size() ; ++i) { if (clus_size[i] == 0) { clus_size[i] = -static_cast<int>(empty_cluss.size()); empty_cluss.push_back(i); } } // calculate loss loss = params.lossfun->loss(clus_stats, num_clusters(), &sum_local_loss) + extra_loss_self * clus_stats.total.self / clus_stats.total.degree; }
//! Do a full init and execution run. Tests end-to-end static int test_stats_run(const char *config_file_path) { print_header(__func__); char *(*check_call)() = testing_service_check_call; char *(*state_call)() = testing_service_state_call; const char *test_home = getenv(EUCALYPTUS_ENV_VAR_NAME); //Init the config file stuff LOGDEBUG("Setting up config files and values for init test\n"); char configFiles[1][EUCA_MAX_PATH]; bzero(configFiles[0], EUCA_MAX_PATH); euca_strncpy(configFiles[0], config_file_path, EUCA_MAX_PATH); configInitValues(configEntryKeysRestart, configEntryKeysNoRestart); readConfigFile(configFiles, 1); LOGDEBUG("Getting sensor list to validate config works\n"); char *test_value = configFileValue(SENSOR_LIST_CONF_PARAM_NAME); if(!test_value) { LOGERROR("Config setup didn't work. Null value found\n"); return EUCA_ERROR; } else { LOGINFO("Config file has enabled stats: %s\n", test_value); } LOGDEBUG("Done with config file checks\n"); flush_sensor_registry(); //just to be sure from other tests initialize_message_sensor("testservice", 60, 60, test_get_msg_stats, test_set_msg_stats); initialize_service_state_sensor("testservice", 60, 60, state_call, check_call); if(init_stats(test_home, "testservice", test_lock, test_unlock) != EUCA_OK) { LOGERROR("Error initialing stats\n"); flush_sensor_registry(); return EUCA_ERROR; } LOGINFO("Setting some message stats and doing an internal run\n"); //populate some stats for the message stats update_message_stats(test_msg_stats, "fakemessage", 500, 0); update_message_stats(test_msg_stats, "fakemessageDescribe", 250, 0); update_message_stats(test_msg_stats, "fakemessageRun", 200, 0); int ret = internal_sensor_pass(TRUE); flush_sensor_registry(); return ret; }
/* *-------------------------------------------------------------- * * decodeInitTables -- * * Initialize all the tables for VLC decoding; this must be * called when the system is set up before any decoding can * take place. * * Results: * All the decoding tables will be filled accordingly. * * Side effects: * The corresponding global array for each decoding table * will be filled. * *-------------------------------------------------------------- */ void decodeInitTables() { init_mb_addr_inc(); init_mb_type_P(); init_mb_type_B(); init_motion_vectors(); #ifdef FLOATDCT if (qualityFlag) init_float_idct(); else #endif init_pre_idct(); #ifdef ANALYSIS { init_stats(); } #endif }
void init_subsystems(){ init_cal(); init_cli_macro(); init_clipboard(); init_commandline(); init_evilloop(); init_exec_cmd(); init_expanded(); init_file(); init_file_ascii(); init_file_help(); init_file_hnb(); init_file_html(); init_file_opml(); init_file_ps(); init_file_xml(); init_go(); init_insertbelow(); init_keepstate(); init_mem(); init_movenode(); init_nodetest(); init_outdent_indent(); init_prefs(); init_query(); init_quit(); init_remove(); init_search(); init_sort(); init_spell(); init_stats(); init_tree_todo(); init_ui_binding(); init_ui_cli(); init_ui_draw(); init_ui_edit(); init_ui_menu(); init_ui_overlay(); init_ui_style(); }
int close_streamer(struct opt_s *opt) { D("Closing streamer"); struct stats *stats_full = (struct stats *)malloc(sizeof(struct stats)); init_stats(stats_full); D("stats ready"); if (opt->streamer_ent != NULL) opt->streamer_ent->close(opt->streamer_ent, (void *)stats_full); D("Closed streamer_ent"); #if(!DAEMON) close_rbufs(opt, stats_full); close_recp(opt, stats_full); D("Membranch and diskbranch shut down"); #else stats_full->total_written = opt->bytes_exchanged; #endif D("Printing stats"); print_stats(stats_full, opt); free(stats_full); D("Stats over"); return 0; }
/* Could have options for printing for how many rows we want, how much we want * to trim the max/min, and how many samples per bin. */ void compute_stats(void **data, int nr_i, int nr_j, struct sample_stats *stats) { uint64_t sample_time, hist_max_time, hist_min_time, lat_max_time, lat_min_time; size_t hist_idx, lat_idx, hist_bin_sz, lat_bin_sz; float accum_samples = 0.0, coef_var; unsigned int *hist_times; unsigned int *lat_times; unsigned int nr_hist_bins = 75; /* looks reasonable when printed */ unsigned int nr_lat_bins = 500; /* affects granularity of lat perc */ unsigned int max_dots_per_row = 45; /* looks good with 80-wide col */ unsigned int max_hist_bin = 0; #define HI_COEF_VAR 1.0 init_stats(stats); /* First pass, figure out the min, max, avg, etc. */ for (int i = 0; i < nr_i; i++) { for (int j = 0; j < nr_j; j++) { /* get_sample returns 0 on success. o/w, skip the sample */ if (stats->get_sample(data, i, j, &sample_time)) continue; /* depending on semantics, we could break */ stats->total_samples++; stats->avg_time += sample_time; stats->max_time = sample_time > stats->max_time ? sample_time : stats->max_time; stats->min_time = sample_time < stats->min_time ? sample_time : stats->min_time; } } if (stats->total_samples < 2) { printf("Not enough samples (%d) for avg and var\n", stats->total_samples); return; } stats->avg_time /= stats->total_samples; /* Second pass, compute the variance. Want to do this before the * histograms, so we can trim the serious outliers */ for (int i = 0; i < nr_i; i++) { for (int j = 0; j < nr_j; j++) { if (stats->get_sample(data, i, j, &sample_time)) continue; /* var: (sum_i=1..n { (x_i - xbar)^2 }) / (n - 1) */ stats->var_time += (sample_time - stats->avg_time) * (sample_time - stats->avg_time); } } stats->var_time /= stats->total_samples - 1; /* We have two histogram structures. The main one is for printing, and the * other is for computing latency percentiles. The only real diff btw the * two is the number of bins. The latency one has a lot more, for finer * granularity, and the regular one has fewer for better printing. * * Both have the same max and min bin values. Any excesses get put in the * smallest or biggest bin. This keeps the granularity reasonable in the * face of very large outliers. Normally, I trim off anything outside 3 * stddev. * * High variation will throw off our histogram bins, so we adjust. A * coef_var > 1 is considered high variance. The numbers I picked are just * heuristics to catch SMM interference and make the output look nice. */ coef_var = sqrt(stats->var_time) / stats->avg_time; if (coef_var > HI_COEF_VAR) { hist_max_time = stats->avg_time * 3; hist_min_time = stats->avg_time / 3; } else { /* 'normal' data */ /* trimming the printable hist at 3 stddevs, which for normal data is * 99.7% of the data. For most any data, it gets 89% (Chebyshev's * inequality) */ hist_max_time = stats->avg_time + 3 * sqrt(stats->var_time); hist_min_time = stats->avg_time - 3 * sqrt(stats->var_time); if (hist_min_time > hist_max_time) hist_min_time = 0; } lat_max_time = hist_max_time; lat_min_time = hist_min_time; hist_bin_sz = (hist_max_time - hist_min_time) / nr_hist_bins + 1; lat_bin_sz = (lat_max_time - lat_min_time) / nr_lat_bins + 1; hist_times = malloc(sizeof(unsigned int) * nr_hist_bins); lat_times = malloc(sizeof(unsigned int) * nr_lat_bins); if (!hist_times || !lat_times) { perror("compute_stats failed to alloc hist/lat arrays:"); free(hist_times); free(lat_times); return; } memset(hist_times, 0, sizeof(unsigned int) * nr_hist_bins); memset(lat_times, 0, sizeof(unsigned int) * nr_lat_bins); /* third pass, fill the bins for the histogram and latencies */ for (int i = 0; i < nr_i; i++) { for (int j = 0; j < nr_j; j++) { if (stats->get_sample(data, i, j, &sample_time)) continue; /* need to shift, offset by min_time. anything too small is 0 and * will go into the first bin. anything too large will go into the * last bin. */ lat_idx = sample_time < lat_min_time ? 0 : (sample_time - lat_min_time) / lat_bin_sz; lat_idx = MIN(lat_idx, nr_lat_bins - 1); lat_times[lat_idx]++; hist_idx = sample_time < hist_min_time ? 0 : (sample_time - hist_min_time) / hist_bin_sz; hist_idx = MIN(hist_idx, nr_hist_bins - 1); hist_times[hist_idx]++; /* useful for formatting the ***s */ max_hist_bin = (hist_times[hist_idx] > max_hist_bin) ? hist_times[hist_idx] : max_hist_bin; } } /* Compute latency percentiles */ for (int i = 0; i < nr_lat_bins; i++) { accum_samples += lat_times[i]; /* (i + 1), since we've just accumulated one bucket's worth */ if (!stats->lat_50 && accum_samples / stats->total_samples > 0.50) stats->lat_50 = (i + 1) * lat_bin_sz + lat_min_time; if (!stats->lat_75 && accum_samples / stats->total_samples > 0.75) stats->lat_75 = (i + 1) * lat_bin_sz + lat_min_time; if (!stats->lat_90 && accum_samples / stats->total_samples > 0.90) stats->lat_90 = (i + 1) * lat_bin_sz + lat_min_time; if (!stats->lat_99 && accum_samples / stats->total_samples > 0.99) stats->lat_99 = (i + 1) * lat_bin_sz + lat_min_time; } for (int i = 0; i < nr_hist_bins; i++) { uint64_t interval_start = i * hist_bin_sz + hist_min_time; uint64_t interval_end = (i + 1) * hist_bin_sz + hist_min_time; /* customize the first and last entries */ if (i == 0) interval_start = MIN(interval_start, stats->min_time); if (i == nr_hist_bins - 1) { interval_end = MAX(interval_end, stats->max_time); /* but not at the sake of formatting! (8 spaces) */ interval_end = MIN(interval_end, 99999999); } printf(" [%8llu - %8llu] %7d: ", interval_start, interval_end, hist_times[i]); /* nr_dots = hist_times[i] * nr_dots_per_sample * = hist_times[i] * (max_num_dots / max_hist_bin) */ int nr_dots = hist_times[i] * max_dots_per_row / max_hist_bin; for (int j = 0; j < nr_dots; j++) printf("*"); printf("\n"); } printf("\n"); printf("Samples per dot: %d\n", max_hist_bin / max_dots_per_row); printf("Total samples: %llu\n", stats->total_samples); printf("Avg time : %llu\n", stats->avg_time); printf("Stdev time : %f\n", sqrt(stats->var_time)); printf("Coef Var : %f\n", coef_var); if (coef_var > HI_COEF_VAR) printf("\tHigh coeff of var with serious outliers, adjusted bins\n"); /* numbers are overestimates by at most a lat bin */ printf("50/75/90/99: %d / %d / %d / %d (-<%d)\n", stats->lat_50, stats->lat_75, stats->lat_90, stats->lat_99, lat_bin_sz); printf("Min / Max : %llu / %llu\n", stats->min_time, stats->max_time); printf("\n"); free(hist_times); free(lat_times); }