Ejemplo n.º 1
0
void mtr_fill_graph(int at, int cols) 
{
	int* saved;
	int i;

	saved = net_saved_pings(at);
	for (i = SAVED_PINGS-cols; i < SAVED_PINGS; i++) {
		if (saved[i] == -2) {
			printw(" ");
		} else if (saved[i] == -1) {
		        attrset(block_col[0]);
			printw("%c", '?');
			attrset(A_NORMAL);
		} else {
			if (display_mode == 1) {
				if (saved[i] > scale[6]) {
					printw("%c", block_map[NUM_FACTORS-1]);
				} else {
					printw(".");
				}
			} else {
				mtr_print_scaled(saved[i]);
			}
		}
	}
}
Ejemplo n.º 2
0
void mtr_fill_graph(int at, int cols) 
{
	int* saved;
	int i;

	saved = net_saved_pings(at);
	for (i = SAVED_PINGS-cols; i < SAVED_PINGS; i++) {
		if (saved[i] == -2) {
			printw(" ");
		} else if (saved[i] == -1) {
			attron(A_BOLD);
			printw("?");
			attroff(A_BOLD);
		} else {
			if (display_mode == 1) {
				if (saved[i] > scale[6]) {
					printw("%c", block_map[7]);
				} else {
					printw(".");
				}
			} else {
				mtr_print_scaled(saved[i]);
			}
		}
	}
}
Ejemplo n.º 3
0
void mtr_gen_scale(void) 
{
	int *saved, i, max, at;
	int range;

	low_ms = 1000000;
	high_ms = -1;

	for (i = 0; i < NUM_FACTORS; i++) {
		scale[i] = 0;
	}
	max = net_max();
	for (at = display_offset; at < max; at++) {
		saved = net_saved_pings(at);
		for (i = 0; i < SAVED_PINGS; i++) {
			if (saved[i] < 0) continue;
			if (saved[i] < low_ms) {
				low_ms = saved[i];
			}
			if (saved[i] > high_ms) {
				high_ms = saved[i];
			}
		}
	}
	range = high_ms - low_ms;
	for (i = 0; i < NUM_FACTORS; i++) {
		scale[i] = low_ms + ((double)range * factors[i]);
	}
}
Ejemplo n.º 4
0
void gc_redraw(void) {
	gc_keyaction(cr_dispatch_event());
	if (paused)
		return;

	int i, at;
	int min = net_min();
	int max = net_max();
	int hops = max - min /* + 1 */;
	if (!hops)
		hops++;

	cr_set_hops(hops, min);

	struct timeval now;
	gettimeofday(&now, NULL);
	int dt = (now.tv_sec - lasttime.tv_sec) * USECONDS + (now.tv_usec - lasttime.tv_usec);
	lasttime = now;

	if (dt < timeout) {
		int pings = net_xmit(min);
		for (at = min + 1; at < max; at++)
			if (net_xmit(at) != pings)
					return;
		if (pings > num_pings)
			num_pings = pings;
		else
			return;
	}

	if (params.enable_legend) {
		static int hi_max;
		if (!hostinfo_max)
			   hi_max = 0;
		if (hostinfo_max > hi_max) {
			hi_max = hostinfo_max;
			curses_cols = cr_recalc(hostinfo_max);
			pr_lastd();
		}
		cr_init_legend();
		cr_print_legend_header(display_mode ? legend_hd[LEGEND_HEADER] : legend_hd[LEGEND_HEADER_STATIC]);
	}

	for (i = 0, at = min; i < hops; i++, at++) {
		ip_t *addr = net_addr(at);

		if (addrcmp((void *)addr, (void *)&unspec_addr, af) != 0) {
			int *saved = net_saved_pings(at);
			int saved_ndx = SAVED_PINGS - 2;	// waittime ago
			if (params.jitter_graph) {
				// jitter, defined as "tN - tN-1" (net.c)
				if ((saved[saved_ndx] < 0) || (saved[saved_ndx - 1] < 0))	// unsent, unknown, etc.
					data[i] = -1;
				else {
					int saved_jttr = saved[saved_ndx] - saved[saved_ndx - 1];
					data[i] = (saved_jttr < 0) ? -saved_jttr : saved_jttr;
				}
			} else
				data[i] = (saved[saved_ndx] >= 0) ? saved[saved_ndx] : -1;

			if (params.enable_legend) {
				// line+hop
				cr_print_hop(i);

				// hostinfo
				fill_hostinfo(at, addr);

				char *stat = buf + strlen(buf) + 1;
				// statistics
				if (display_mode) {
					mtr_gen_scale_gc();
					char *pos = stat;
					int j;
#ifdef UNICODE
					if (display_mode == 3) {
						for (j = SAVED_PINGS - curses_cols; j < SAVED_PINGS; j++) {
							*(wchar_t*)pos = mtr_curses_saved_wch(saved[j]);
							pos += sizeof(wchar_t);
						}
						*(wchar_t*)pos = L'\0';
					} else
#endif
					{
						for (j = SAVED_PINGS - curses_cols; j < SAVED_PINGS; j++)
							*pos++ = mtr_curses_saved_ch(saved[j]);
						*pos = 0;
					}
				} else
					mtr_fill_data(at, stat);
				cr_print_host(i, data[i], buf, stat);

				// mpls
				if (enablempls)
					gc_print_mpls(i, data[i], net_mpls(at));

				// multipath
				if (params.enable_multipath) {
					int j;
					for (j = 0; j < MAXPATH; j++) {
						ip_t *addrs = net_addrs(at, j);
						if (addrcmp((void *)addrs, (void *)addr, af) == 0)
							continue;
						if (addrcmp((void *)addrs, (void *)&unspec_addr, af) == 0)
							break;
						fill_hostinfo(at, addrs);
						cr_print_host(i, data[i], buf, NULL);
						if (enablempls)	// multipath+mpls
							gc_print_mpls(i, data[i], net_mplss(at, j));
					}
				}
			}
		} else	// empty hop
			if (params.enable_legend) {
				cr_print_hop(i);
				cr_print_host(i, 0, NULL, NULL);
			}
	}

	if (params.enable_legend)
		if (display_mode) {
			mtr_curses_scale_desc(legend_hd[LEGEND_FOOTER]);
			cr_print_legend_footer(legend_hd[LEGEND_FOOTER]);
		}

	cr_redraw(data);

	if (hops)
		timeout = POS_ROUND(((WaitTime * hops) / NUMHOSTS) * USECONDS);
}