void begin_color_coded (double r, double lo, double hi) { if (r < lo) begin_color(color_lo); else if (r > hi) begin_color(color_hi); else begin_color(color_normal); }
static void print_typing (SLOT *sp) { sprintf (msg_buf, "%s/%s\n", sp->acct.id, sp->acct.handle); writestr (cur_slot, " "); begin_color (cur_slot, sp->acct.msgcolor); writestr (cur_slot, msg_buf); reset_attr (cur_slot); }
void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) { for(const auto &instrument : measurements) { *_stream << begin_color("3") << " " << instrument.first << ":"; auto add_measurements = [](Measurement::Value a, const Measurement & b) { return a + b.value(); }; auto cmp_measurements = [](const Measurement & a, const Measurement & b) { return a.value() < b.value(); }; int num_values = instrument.second.size(); const auto minmax_values = std::minmax_element(instrument.second.begin(), instrument.second.end(), cmp_measurements); Measurement::Value sum_values = std::accumulate(instrument.second.begin(), instrument.second.end(), Measurement::Value(minmax_values.first->value().is_floating_point), add_measurements); // Calculate the median value auto measurements = instrument.second; std::nth_element(measurements.begin(), measurements.begin() + (num_values / 2), measurements.end(), cmp_measurements); const auto median_value = measurements[num_values / 2]; // Calculate the relative standard deviation auto mean_value = sum_values / num_values; std::vector<Measurement::Value> diff(measurements.size(), minmax_values.first->value().is_floating_point); std::transform(measurements.begin(), measurements.end(), diff.begin(), [mean_value](const Measurement & x) { return x.value() - mean_value; }); auto sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), Measurement::Value(minmax_values.first->value().is_floating_point)); auto variance = sq_sum / measurements.size(); auto rsd = Measurement::Value::relative_standard_deviation(variance, mean_value); if(num_values > 2) { sum_values -= minmax_values.first->value() + minmax_values.second->value(); num_values -= 2; } *_stream << " "; *_stream << "MEDIAN=" << median_value.value() << " " << median_value.unit() << ", "; *_stream << "AVG=" << (sum_values / num_values) << " " << minmax_values.second->unit() << ", "; *_stream << "STDDEV=" << arithmetic_to_string(rsd, 2) << " %, "; if(num_values > 1) { *_stream << "MIN=" << *minmax_values.first << ", "; *_stream << "MAX=" << *minmax_values.second; } *_stream << end_color() << "\n"; } }
void writeaction (SLOT *sp, char *msg) { select_stop (sp); select_wrap (sp); begin_attr (sp, 1); begin_color (sp, cur_slot->acct.msgcolor); writestr (sp, msg); reset_attr (sp); writech (sp, '\n'); clear_stop (sp); clear_wrap (sp); }
void dump_userinfoshort (ACCOUNT *acct, int logged_in) { ACCOUNT *cur_acct; long idle, hours, mins, secs; cur_acct = &cur_slot->acct; writestr (cur_slot, "Login/Handle: "); begin_color (cur_slot, acct->msgcolor); writestr (cur_slot, acct->id); writech (cur_slot, '/'); writestr (cur_slot, acct->handle); reset_attr (cur_slot); writestr (cur_slot, "\nChannel: "); if (cur_acct->level == TOPLEVEL || channels[acct->chan].name || acct->chan == cur_acct->chan || !strcmp(acct->id, cur_acct->id)) { writeint (cur_slot, acct->chan); writestr (cur_slot, "\n"); } else writestr (cur_slot, "**\n"); if (cur_acct->level >= 2 || acct->email_public || !strcmp(acct->id, cur_acct->id)) { writestr (cur_slot, "Email address is "); writestr (cur_slot, acct->email_address); writestr (cur_slot, acct->email_public ? " [public]\n" : " [private]\n"); } else writestr (cur_slot, "Email address is *PRIVATE*\n"); writestr (cur_slot, "Last logout: "); writestr (cur_slot, ctime(&acct->last_logout)); if (logged_in) { /* calculate idle time if the user is logged in */ idle = time (NULL) - acct->last_typed; hours = idle / 3600; idle -= hours * 3600; mins = idle / 60; secs = idle - (mins * 60); sprintf (msg_buf, "Last typed: %.24s (idle: %dh %02dm %02ds)\n", ctime(&acct->last_typed), hours, mins, secs); writestr (cur_slot, msg_buf); } else { writestr (cur_slot, "Last typed: "); writestr (cur_slot, ctime(&acct->last_typed)); } }
void paabout (SLOT *sl, char *msg) { SLOT *sp; SLOT_LIST *slist; write_log_paabout (sl, msg); slist = channels[MAINLIST].members; while (slist) { sp = slist->slot; if (sp && (sp->acct.pa_notify || (sl->acct.chan == sp->acct.chan))) { select_stop (sp); select_wrap (sp); begin_color (sp, sl->acct.msgcolor); if (slots_f) { writestr (sp, "-- #"); writeint (sp, sl->nslot); } else { writestr (sp, "--"); } writech (sp, ' '); writestr (sp, msg); writestr (sp, " channel "); if (sl->acct.chan == sp->acct.chan || sl->flags.listed || sl->acct.chan == 1 || sp->acct.level > 2) writetwodig (sp, sl->acct.chan); else writestr (sp, "**"); writestr (sp, ": "); writestr (sp, sl->acct.id); writech (sp, '/'); writestr (sp, sl->acct.handle); reset_attr (sp); writech (sp, '\n'); clear_stop (sp); clear_wrap (sp); } slist = slist->next; } }
void writemsg_raw (char *msg, int color, char nlchar) { select_wrap (cur_slot); writestr (cur_slot, " "); begin_color (cur_slot, color); while (*msg) { if (*msg == nlchar) writestr (cur_slot, "\n "); else writech (cur_slot, *msg); msg++; } reset_attr (cur_slot); writech (cur_slot, '\n'); clear_wrap (cur_slot); }
void operact (SLOT *from, SLOT *to, char * msg) { SLOT *sp; SLOT_LIST *sl; sl = channels[MAINLIST].members; while(sl) { sp = sl->slot; if (sp && sp != from && sp->acct.level > 3) { select_stop (sp); select_wrap (sp); if (from) begin_color (sp, from->acct.msgcolor); writestr (sp, "** "); if (from) { writestr (sp, from->acct.id); writech (sp, '/'); writestr (sp, from->acct.handle); writech (sp, ' '); } writestr (sp, msg); if (to != NULL) { writech (sp, ' '); writestr (sp, to->acct.id); writech (sp, '/'); writestr (sp, to->acct.handle); } if (from) reset_attr (sp); writech (sp, '\n'); clear_stop (sp); clear_wrap (sp); } sl = sl->next; } }
void writemsg (SLOT *sp, char *msg, int typ) { char *s; char *t; select_stop (sp); select_wrap (sp); begin_color (sp, cur_slot->acct.msgcolor); /* Emphasize personal messages */ if (typ == 1) begin_attr (sp, 1); s = sp->acct.msgfmt; while (*s) { if (*s == '%') { switch (*++s) { case '\\': writech (sp, '\\'); break; case '_': writech (sp, '_'); break; case 'm': while (*msg) { if (*msg == cur_slot->acct.nlchar && sp->acct.newlines) writestr (sp, "\n "); else writech (sp, *msg); msg++; } break; default: if (shared_spec (sp, cur_slot, *s)) break; writech (sp, '%'); if (!*s) s--; else writech (sp, *s); } } else if (*s == '_') { t = (char *)index (++s, '_'); if (typ == 2) { if (t != NULL) *t = '\0'; writestr (sp, s); if (t != NULL) *t = '_'; } if (t == NULL) break; else s = t; } else if (*s == '\\') { t = (char *)index (++s, '\\'); if (typ == 1) { if (t != NULL) *t = '\0'; writestr (sp, s); if (t != NULL) *t = '\\'; } if (t == NULL) break; else s = t; } else writech (sp, *s); s++; } reset_attr (sp); writech (sp, '\n'); clear_stop (sp); clear_wrap (sp); }
int main (int argc, char *argv[]) { struct stats s, s0; int print = 0; FILE *fp = fopen(STATS_FILE, "rb"); if (fp != NULL) { fread(&s0, sizeof(struct stats), 1, fp); fclose(fp); print = 1; } get_times(&s); get_temp(&s); get_mail(&s); get_cputime(&s); get_power(&s); get_mem(&s); get_txrx(&s); if (print) { int i; double temp = 1e-3*s.temp; double charge = 100*s.charge_now/s.charge_full; double tx = (s.tx-s0.tx)/(s.t-s0.t); double rx = (s.rx-s0.rx)/(s.t-s0.t); double mem = s.mem*9.5367431640625e-07; double cpu_pct[MAX_CPUS]; for (i=0; i < s.n_cpus; i++) { double idle = s.cpu_idle[i] - s0.cpu_idle[i]; double total = s.cpu_total[i] - s0.cpu_total[i]; cpu_pct[i] = 1-idle/total; } fputs(" [", stdout); begin_color(color_bar); fputs(th_spc, stdout); for (i=0; i < s.n_cpus; i++) { print_bar(cpu_pct[i]); fputs(th_spc, stdout); } end_color(); fputc(']', stdout); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); end_color(); begin_color_coded (temp, LO_TEMP, HI_TEMP); num_print (temp, 3, degc); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); fputs(spc, stdout); end_color(); begin_color_coded (mem, LO_MEM, HI_MEM); num_print (mem, 4, "MB"); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); fputs(spc, stdout); end_color(); begin_color (s.ac_connected ? "cyan" : "red"); fputs(s.ac_connected ? acon : acoff, stdout); fputc(' ', stdout); end_color(); begin_color_coded (100-charge, LO_CHARGE, HI_CHARGE); num_print (charge, 3, "%"); end_color(); begin_color (color_div); fputs(spc, stdout); fputs(divider, stdout); end_color(); begin_color_coded (tx, LO_RATE, HI_RATE); num_print (tx, 0, "B/s "); end_color(); begin_color (color_up); fputs(up, stdout); end_color(); begin_color_coded (rx, LO_RATE, HI_RATE); fputs(spc, stdout); num_print (rx, 0, "B/s "); end_color(); begin_color (color_down); fputs(down, stdout); end_color(); fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); fputs(spc, stdout); end_color(); if (s.gmail) { begin_color (color_mail); printf ("%2d/g", s.gmail); end_color(); } if (s.uiucmail) { begin_color (color_mail); printf ("%2d/u", s.uiucmail); end_color(); } if (s.uiucmail || s.gmail) { fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); fputs(spc, stdout); end_color(); } begin_color (color_date); fputs(s.date, stdout); end_color(); fputs(spc, stdout); begin_color (color_div); fputs(divider, stdout); end_color(); } fp = fopen(STATS_FILE, "wb"); fwrite(&s, sizeof(struct stats), 1, fp); fclose(fp); return 0; }
void PrettyPrinter::print_info(const std::string &info) { *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n"; }
void PrettyPrinter::print_test_header(const TestInfo &info) { *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n"; }
void PrettyPrinter::print_entry(const std::string &name, const std::string &value) { *_stream << begin_color("4") << name << " = " << value << end_color() << "\n"; }
void PrettyPrinter::print_error(const std::exception &error, bool expected) { std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: "; *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n"; }