void rl_initialize(void) { if (!rl_prompt) rl_prompt = "? "; hist_alloc(); /* Setup I/O descriptors */ if (!rl_instream) el_infd = EL_STDIN; else el_infd = fileno(rl_instream); if (el_infd < 0) el_infd = EL_STDIN; if (!rl_outstream) el_outfd = EL_STDOUT; else el_outfd = fileno(rl_outstream); if (el_outfd < 0) el_outfd = EL_STDOUT; }
static void update_histotier(histotier *ht, u_int64_t s, struct histogram_config *conf, noit_check_t *check, const char *name, double val, u_int64_t cnt) { u_int64_t minute = s/60; u_int8_t second = s%60; u_int8_t sec_bucket = s%10; noit_check_metric_count_add(cnt); if((second != ht->last_second || check->flags & NP_TRANSIENT) && check->feeds) { int last_second = ht->last_second; int last_minute = ht->last_minute; u_int8_t last_bucket; /* If we are transient we're coming to this sloppy. * Someone else owns this ht. So, if we're high-traffic * then last_second has already been bumped, so we need to * rewind it. */ if(check->flags & NP_TRANSIENT && second == last_second) { last_second--; if(last_second < 0) { last_second = 59; last_minute--; } } last_bucket = last_second % 10; if(ht->secs[last_bucket] && hist_num_buckets(ht->secs[last_bucket])) log_histo(conf, check, last_minute * 60 + last_second, name, ht->secs[last_bucket], mtev_true); } if(minute > ht->last_minute) { sweep_roll_n_log(conf, check, ht, name); } else if(second/10 > ht->last_second/10) { sweep_roll_tensec(ht); } if(cnt > 0) { if(ht->secs[sec_bucket] == NULL) ht->secs[sec_bucket] = hist_alloc(); hist_insert(ht->secs[sec_bucket], val, cnt); } ht->last_minute = minute; ht->last_second = second; }
int write_history(const char *filename) { FILE *fp; hist_alloc(); fp = fopen(filename, "w"); if (fp) { int i = 0; while (i < H.Size) fprintf(fp, "%s\n", H.Lines[i++]); fclose(fp); return 0; } return errno; }
int read_history(const char *filename) { FILE *fp; char buf[SCREEN_INC]; hist_alloc(); fp = fopen(filename, "r"); if (fp) { H.Size = 0; while (H.Size < el_hist_size) { if (!fgets(buf, SCREEN_INC, fp)) break; buf[strlen(buf) - 1] = 0; /* Remove '\n' */ add_history(buf); } fclose(fp); return 0; } return errno; }