FreeBSD Bugzilla – Attachment 147812 Details for
Bug 194017
systat(8): Add -altqs flag
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
altqs.c.diff
altqs.c.diff (text/plain), 9.66 KB, created by
David CARLIER
on 2014-09-29 22:50:44 UTC
(
hide
)
Description:
altqs.c.diff
Filename:
MIME Type:
Creator:
David CARLIER
Created:
2014-09-29 22:50:44 UTC
Size:
9.66 KB
patch
obsolete
>diff --git a/usr.bin/systat/altqs.c b/usr.bin/systat/altqs.c >index 29df218..183bbc5 100644 >--- a/usr.bin/systat/altqs.c >+++ b/usr.bin/systat/altqs.c >@@ -24,13 +24,15 @@ > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. >+ * >+ * $FreeBSD$ > */ > > #include <sys/types.h> > #include <sys/socket.h> >-#include <sys/ioctl.h> >- >+#include <sys/queue.h> > #include <sys/sysctl.h> >+#include <sys/ioctl.h> > #include <net/if.h> > #include <net/if_mib.h> > >@@ -39,6 +41,7 @@ > #include <unistd.h> > #include <err.h> > #include <errno.h> >+#include <fnmatch.h> > > #include <altq/altq.h> > #include <altq/altq_cbq.h> >@@ -51,8 +54,23 @@ > #include "extern.h" > #include "convtbl.h" > >+ /* Column numbers */ >+ >+#define C1 0 /* 0-19 */ >+#define C2 20 /* 20-39 */ >+#define C3 40 /* 40-59 */ >+#define C4 60 /* 60-80 */ >+#define C5 80 /* Used for label positioning. */ >+ >+static const int col0 = 0; >+static const int col1 = C1; >+static const int col2 = C2; >+static const int col3 = C3; >+static const int col4 = C4; >+static const int col5 = C5; >+ > static SLIST_HEAD(, qcol) qcols; >-static SLIST_HEAD(, if_stat) curlist; >+static SLIST_HEAD(, if_stat) curlist; > static int pf_fd = -1; > static int qccols; > static int TopSection1; >@@ -85,7 +103,7 @@ struct queue_stats { > typedef struct queue_stats queue_stats_t; > > struct if_stat { >- SLIST_ENTRY(if_stat) link; >+ SLIST_ENTRY(if_stat) link; > SLIST_HEAD(, queue_stats) queues; > char if_name[IF_NAMESIZE]; > struct ifmibdata if_mib; >@@ -95,31 +113,238 @@ struct if_stat { > u_long if_out_curtraffic; > u_long if_in_traffic_peak; > u_long if_out_traffic_peak; >+ u_long if_in_curpps; >+ u_long if_out_curpps; >+ u_long if_in_pps_peak; >+ u_long if_out_pps_peak; > u_int if_row; /* Index into ifmib sysctl */ > u_int row; /* display row (relative) */ >+ int if_ypos; /* -1 if not being displayed */ > u_int display; >+ u_int match; > }; > > typedef struct if_stat if_stat_t; > >-extern u_int curscale; >+extern int curscale; >+extern char *matchline; >+extern int showpps; >+extern int needsort; >+ >+static int needclear = 0; > > static void load_altqs(void); > static void print_altq(if_stat_t *p, queue_stats_t *q); >-static void right_align_string(if_stat_t *); >+static void right_align_string(struct if_stat *); > static void getifmibdata(const int, struct ifmibdata *); > static void sort_interface_list(void); > static u_int getifnum(void); > > #define IFSTAT_ERR(n, s) do { \ >- putchar(''); \ >- closealtqs(wnd); \ >+ putchar('\014'); \ >+ closeifstat(wnd); \ > err((n), (s)); \ > } while (0) > >-#define TOPLINE 1 >+#define TOPLINE 3 > #define TOPQSTART 20 > #define TOPQWIDTH 10 >+#define TOPLABEL \ >+" Interface Traffic Peak Total" >+ >+#define STARTING_ROW (TOPLINE + 1) >+#define ROW_SPACING (3) >+ >+#define IN_col2 (showpps ? ifp->if_in_curpps : ifp->if_in_curtraffic) >+#define OUT_col2 (showpps ? ifp->if_out_curpps : ifp->if_out_curtraffic) >+#define IN_col3 (showpps ? \ >+ ifp->if_in_pps_peak : ifp->if_in_traffic_peak) >+#define OUT_col3 (showpps ? \ >+ ifp->if_out_pps_peak : ifp->if_out_traffic_peak) >+#define IN_col4 (showpps ? \ >+ ifp->if_mib.ifmd_data.ifi_ipackets : ifp->if_mib.ifmd_data.ifi_ibytes) >+#define OUT_col4 (showpps ? \ >+ ifp->if_mib.ifmd_data.ifi_opackets : ifp->if_mib.ifmd_data.ifi_obytes) >+ >+#define EMPTY_COLUMN " " >+#define CLEAR_COLUMN(y, x) mvprintw((y), (x), "%20s", EMPTY_COLUMN); >+ >+#define DOPUTRATE(c, r, d) do { \ >+ CLEAR_COLUMN(r, c); \ >+ if (showpps) { \ >+ mvprintw(r, (c), "%10.3f %cp%s ", \ >+ convert(d##_##c, curscale), \ >+ *get_string(d##_##c, curscale), \ >+ "/s"); \ >+ } \ >+ else { \ >+ mvprintw(r, (c), "%10.3f %s%s ", \ >+ convert(d##_##c, curscale), \ >+ get_string(d##_##c, curscale), \ >+ "/s"); \ >+ } \ >+} while (0) >+ >+#define DOPUTTOTAL(c, r, d) do { \ >+ CLEAR_COLUMN((r), (c)); \ >+ if (showpps) { \ >+ mvprintw((r), (c), "%12.3f %cp ", \ >+ convert(d##_##c, SC_AUTO), \ >+ *get_string(d##_##c, SC_AUTO)); \ >+ } \ >+ else { \ >+ mvprintw((r), (c), "%12.3f %s ", \ >+ convert(d##_##c, SC_AUTO), \ >+ get_string(d##_##c, SC_AUTO)); \ >+ } \ >+} while (0) >+ >+#define PUTRATE(c, r) do { \ >+ DOPUTRATE(c, (r), IN); \ >+ DOPUTRATE(c, (r)+1, OUT); \ >+} while (0) >+ >+#define PUTTOTAL(c, r) do { \ >+ DOPUTTOTAL(c, (r), IN); \ >+ DOPUTTOTAL(c, (r)+1, OUT); \ >+} while (0) >+ >+#define PUTNAME(p) do { \ >+ mvprintw(p->if_ypos, 0, "%s", p->if_name); \ >+ mvprintw(p->if_ypos, col2-3, "%s", (const char *)"in"); \ >+ mvprintw(p->if_ypos+1, col2-3, "%s", (const char *)"out"); \ >+} while (0) >+ >+/* >+ * We want to right justify our interface names against the first column >+ * (first sixteen or so characters), so we need to do some alignment. >+ */ >+static void >+right_align_string(struct if_stat *ifp) >+{ >+ int str_len = 0, pad_len = 0; >+ char *newstr = NULL, *ptr = NULL; >+ >+ if (ifp == NULL || ifp->if_mib.ifmd_name == NULL) >+ return; >+ else { >+ /* string length + '\0' */ >+ str_len = strlen(ifp->if_mib.ifmd_name)+1; >+ pad_len = IF_NAMESIZE-(str_len); >+ >+ newstr = ifp->if_name; >+ ptr = newstr + pad_len; >+ (void)memset((void *)newstr, (int)' ', IF_NAMESIZE); >+ (void)strncpy(ptr, (const char *)&ifp->if_mib.ifmd_name, >+ str_len); >+ } >+ >+ return; >+} >+ >+static int >+check_match(const char *ifname) >+{ >+ char *p = matchline, *c, t; >+ int match = 0, mlen; >+ >+ if (matchline == NULL) >+ return (0); >+ >+ /* Strip leading whitespaces */ >+ while (*p == ' ') >+ p ++; >+ >+ c = p; >+ while ((mlen = strcspn(c, " ;,")) != 0) { >+ p = c + mlen; >+ t = *p; >+ if (p - c > 0) { >+ *p = '\0'; >+ if (fnmatch(c, ifname, FNM_CASEFOLD) == 0) { >+ *p = t; >+ return (1); >+ } >+ *p = t; >+ c = p + strspn(p, " ;,"); >+ } >+ else { >+ c = p + strspn(p, " ;,"); >+ } >+ } >+ >+ return (match); >+} >+ >+/* >+ * This function iterates through our list of interfaces, identifying >+ * those that are to be displayed (ifp->display = 1). For each interf- >+ * rface that we're displaying, we generate an appropriate position for >+ * it on the screen (ifp->if_ypos). >+ * >+ * This function is called any time a change is made to an interface's >+ * ``display'' state. >+ */ >+void >+sort_interface_list(void) >+{ >+ struct if_stat *ifp = NULL; >+ u_int y = 0; >+ >+ y = STARTING_ROW; >+ SLIST_FOREACH(ifp, &curlist, link) { >+ if (matchline && !check_match(ifp->if_mib.ifmd_name)) >+ ifp->match = 0; >+ else >+ ifp->match = 1; >+ if (ifp->display && ifp->match) { >+ ifp->if_ypos = y; >+ y += ROW_SPACING; >+ } >+ else >+ ifp->if_ypos = -1; >+ } >+ >+ needsort = 0; >+ needclear = 1; >+} >+ >+static >+unsigned int >+getifnum(void) >+{ >+ u_int data = 0; >+ size_t datalen = 0; >+ static int name[] = { CTL_NET, >+ PF_LINK, >+ NETLINK_GENERIC, >+ IFMIB_SYSTEM, >+ IFMIB_IFCOUNT }; >+ >+ datalen = sizeof(data); >+ if (sysctl(name, 5, (void *)&data, (size_t *)&datalen, (void *)NULL, >+ (size_t)0) != 0) >+ IFSTAT_ERR(1, "sysctl error"); >+ return (data); >+} >+ >+static void >+getifmibdata(int row, struct ifmibdata *data) >+{ >+ size_t datalen = 0; >+ static int name[] = { CTL_NET, >+ PF_LINK, >+ NETLINK_GENERIC, >+ IFMIB_IFDATA, >+ 0, >+ IFDATA_GENERAL }; >+ datalen = sizeof(*data); >+ name[4] = row; >+ >+ if ((sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL, >+ (size_t)0) != 0) && (errno != ENOENT)) >+ IFSTAT_ERR(2, "sysctl error getting interface data"); >+} > > WINDOW * > openaltqs(void) >@@ -311,94 +536,6 @@ fetchaltqs(void) > return; > } > >-/* >- * We want to right justify our interface names against the first column >- * (first sixteen or so characters), so we need to do some alignment. >- */ >-static void >-right_align_string(if_stat_t *ifp) >-{ >- int str_len = 0, pad_len = 0; >- char *newstr = NULL, *ptr = NULL; >- >- if (ifp == NULL || ifp->if_mib.ifmd_name == NULL) >- return; >- else { >- /* string length + '\0' */ >- str_len = strlen(ifp->if_mib.ifmd_name)+1; >- pad_len = IF_NAMESIZE-(str_len); >- >- newstr = ifp->if_name; >- ptr = newstr + pad_len; >- (void)memset((void *)newstr, (int)' ', IF_NAMESIZE); >- (void)strncpy(ptr, (const char *)&ifp->if_mib.ifmd_name, >- str_len); >- } >- >- return; >-} >- >-/* >- * This function iterates through our list of interfaces, identifying >- * those that are to be displayed (ifp->display = 1). For each interf- >- * rface that we're displaying, we generate an appropriate position for >- * it on the screen (ifp->row). >- * >- * This function is called any time a change is made to an interface's >- * ``display'' state. >- */ >-void >-sort_interface_list(void) >-{ >- if_stat_t *ifp; >- u_int y; >- >- y = 1; >- SLIST_FOREACH(ifp, &curlist, link) { >- if (ifp->display) >- ifp->row = ++y; >- } >- TopSection2 = TopSection1 + y + 4; >- TopSection3 = TopSection2 + y + 4; >-} >- >-static >-unsigned int >-getifnum(void) >-{ >- u_int data = 0; >- size_t datalen = 0; >- static int name[] = { CTL_NET, >- PF_LINK, >- NETLINK_GENERIC, >- IFMIB_SYSTEM, >- IFMIB_IFCOUNT }; >- >- datalen = sizeof(data); >- if (sysctl(name, 5, (void *)&data, (size_t *)&datalen, NULL, >- (size_t)0) != 0) >- IFSTAT_ERR(1, "sysctl error"); >- return data; >-} >- >-static void >-getifmibdata(int row, struct ifmibdata *data) >-{ >- size_t datalen = 0; >- static int name[] = { CTL_NET, >- PF_LINK, >- NETLINK_GENERIC, >- IFMIB_IFDATA, >- 0, >- IFDATA_GENERAL }; >- datalen = sizeof(*data); >- name[4] = row; >- >- if ((sysctl(name, 6, (void *)data, (size_t *)&datalen, NULL, >- (size_t)0) != 0) && (errno != ENOENT)) >- IFSTAT_ERR(2, "sysctl error getting interface data"); >-} >- > static void > load_altqs(void) > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 194017
: 147812