display-statistics.c 5.17 KB
Newer Older
1 2
/* horst - Highly Optimized Radio Scanning Tool
 *
3
 * Copyright (C) 2005-2016 Bruno Randolf (br1@einfach.org)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

20 21 22 23 24 25 26
/******************* STATISTICS *******************/

#include <stdlib.h>

#include "display.h"
#include "main.h"
#include "util.h"
27
#include "wlan_util.h"
28 29 30 31 32 33 34 35 36

#define STAT_PACK_POS 9
#define STAT_BYTE_POS (STAT_PACK_POS + 9)
#define STAT_BPP_POS (STAT_BYTE_POS + 9)
#define STAT_PP_POS (STAT_BPP_POS + 6)
#define STAT_BP_POS (STAT_PP_POS + 6)
#define STAT_AIR_POS (STAT_BP_POS + 6)
#define STAT_AIRG_POS (STAT_AIR_POS + 6)

Bruno Randolf's avatar
Bruno Randolf committed
37
void update_statistics_win(WINDOW *win)
38 39 40
{
	int i;
	int line;
41
	int bps, dps, pps, rps;
42 43 44 45 46 47 48 49 50 51 52 53
	float duration;

	werase(win);
	wattron(win, WHITE);
	box(win, 0 , 0);
	print_centered(win, 0, COLS, " Packet Statistics ");

	if (stats.packets == 0) {
		wnoutrefresh(win);
		return; /* avoid floating point exceptions */
	}

54 55 56 57
	mvwprintw(win, 2, 2, "Packets: %d", stats.packets );
	mvwprintw(win, 3, 2, "Bytes:   %s (%d)",
		  kilo_mega_ize(stats.bytes), stats.bytes );
	mvwprintw(win, 4, 2, "Average: ~%d B/Pkt", stats.bytes / stats.packets);
58

59 60 61 62 63
	mvwprintw(win, 2, 40, "Retries:       %3.1f%% (%d)",
		  stats.retries * 100.0 / stats.packets, stats.retries);

	get_per_second(stats.bytes, stats.duration, stats.packets, stats.retries,
		       &bps, &dps, &pps, &rps);
64

65
	bps = bps * 8;
66

67 68
	mvwprintw(win, 3, 40, "Total bit/sec: %s (%d)",
		  kilo_mega_ize(bps), bps);
69
	wattron(win, A_BOLD);
70 71
	mvwprintw(win, 4, 40, "Total Usage:   %3.1f%% (%d)",
		  dps * 1.0 / 10000, dps ); /* usec in % */
72 73 74 75 76 77 78 79 80 81 82 83 84
	wattroff(win, A_BOLD);

	line = 6;
	mvwprintw(win, line, STAT_PACK_POS, " Packets");
	mvwprintw(win, line, STAT_BYTE_POS, "   Bytes");
	mvwprintw(win, line, STAT_BPP_POS, "~B/P");
	mvwprintw(win, line, STAT_PP_POS, "Pkts%%");
	mvwprintw(win, line, STAT_BP_POS, "Byte%%");
	wattron(win, A_BOLD);
	mvwprintw(win, line, STAT_AIR_POS, "Usage%%");
	mvwprintw(win, line++, 2, "RATE");
	wattroff(win, A_BOLD);
	mvwhline(win, line++, 2, '-', COLS-4);
85
	for (i = 1; i < MAX_RATES && line < LINES - 2; i++) {
86 87
		if (stats.packets_per_rate[i] > 0) {
			wattron(win, A_BOLD);
88
			if (i <= 12)
89 90 91
				mvwprintw(win, line, 2, "%3dM", rate_index_to_rate(i)/10);
			else
				mvwprintw(win, line, 2, "MCS%d", i - 12);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
			wattroff(win, A_BOLD);
			mvwprintw(win, line, STAT_PACK_POS, "%8d",
				stats.packets_per_rate[i]);
			mvwprintw(win, line, STAT_BYTE_POS, "%8s",
				kilo_mega_ize(stats.bytes_per_rate[i]));
			mvwprintw(win, line, STAT_BPP_POS, "%4d",
				stats.bytes_per_rate[i] / stats.packets_per_rate[i]);
			mvwprintw(win, line, STAT_PP_POS, "%2.1f",
				stats.packets_per_rate[i] * 100.0 / stats.packets);
			mvwprintw(win, line, STAT_BP_POS, "%2.1f",
				stats.bytes_per_rate[i] * 100.0 / stats.bytes);
			wattron(win, A_BOLD);
			duration = stats.duration_per_rate[i] * 100.0 / stats.duration;
			mvwprintw(win, line, STAT_AIR_POS, "%2.1f", duration);
			mvwhline(win, line, STAT_AIRG_POS, '*',
				normalize(duration, 100, COLS - STAT_AIRG_POS - 2));
			wattroff(win, A_BOLD);
			line++;
		}
	}

	line++;
114 115 116 117 118 119 120 121 122 123 124 125 126 127
	if (line < LINES - 2) {
		mvwprintw(win, line, STAT_PACK_POS, " Packets");
		mvwprintw(win, line, STAT_BYTE_POS, "   Bytes");
		mvwprintw(win, line, STAT_BPP_POS, "~B/P");
		mvwprintw(win, line, STAT_PP_POS, "Pkts%%");
		mvwprintw(win, line, STAT_BP_POS, "Byte%%");
		wattron(win, A_BOLD);
		mvwprintw(win, line, STAT_AIR_POS, "Usage%%");
		mvwprintw(win, line++, 2, "TYPE");
		wattroff(win, A_BOLD);
	}
	if (line < LINES - 2)
		mvwhline(win, line++, 2, '-', COLS - 4);
	for (i = 0; i < MAX_FSTYPE && line < LINES - 2; i++) {
128
		if (stats.packets_per_type[i] > 0) {
129
			wattron(win, get_packet_type_color(i));
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
			wattron(win, A_BOLD);
			mvwprintw(win, line, 2, "%s", get_packet_type_name(i));
			wattroff(win, A_BOLD);
			mvwprintw(win, line, STAT_PACK_POS, "%8d",
				stats.packets_per_type[i]);
			mvwprintw(win, line, STAT_BYTE_POS, "%8s",
				kilo_mega_ize(stats.bytes_per_type[i]));
			mvwprintw(win, line, STAT_BPP_POS, "%4d",
				stats.bytes_per_type[i] / stats.packets_per_type[i]);
			mvwprintw(win, line, STAT_PP_POS, "%2.1f",
				stats.packets_per_type[i] * 100.0 / stats.packets);
			mvwprintw(win, line, STAT_BP_POS, "%2.1f",
				stats.bytes_per_type[i] * 100.0 / stats.bytes);
			wattron(win, A_BOLD);
			if (stats.duration > 0)
				duration = stats.duration_per_type[i] * 100.0 / stats.duration;
			else
				duration = 100.0;
			mvwprintw(win, line, STAT_AIR_POS, "%2.1f", duration);
			mvwhline(win, line, STAT_AIRG_POS, '*',
				normalize(duration, 100, COLS - STAT_AIRG_POS - 2));
			wattroff(win, A_BOLD);
			line++;
		}
	}
	wnoutrefresh(win);
}