1997-03-23 18:51:21 +00:00
|
|
|
/*
|
|
|
|
* Top users/processes display for Unix
|
|
|
|
* Version 3
|
|
|
|
*
|
|
|
|
* This program may be freely redistributed,
|
|
|
|
* but this entire comment MUST remain intact.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1984, 1989, William LeFebvre, Rice University
|
|
|
|
* Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
|
2000-10-04 23:34:16 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1997-03-23 18:51:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file contains the routines that display information on the screen.
|
|
|
|
* Each section of the screen has two routines: one for initially writing
|
|
|
|
* all constant and dynamic text, and one for only updating the text that
|
|
|
|
* changes. The prefix "i_" is used on all the "initial" routines and the
|
|
|
|
* prefix "u_" is used for all the "updating" routines.
|
|
|
|
*
|
|
|
|
* ASSUMPTIONS:
|
|
|
|
* None of the "i_" routines use any of the termcap capabilities.
|
|
|
|
* In this way, those routines can be safely used on terminals that
|
|
|
|
* have minimal (or nonexistant) terminal capabilities.
|
|
|
|
*
|
|
|
|
* The routines are called in this order: *_loadave, i_timeofday,
|
|
|
|
* *_procstates, *_cpustates, *_memory, *_message, *_header,
|
|
|
|
* *_process, u_endscreen.
|
|
|
|
*/
|
|
|
|
|
2018-06-04 04:59:32 +00:00
|
|
|
#include <sys/cdefs.h>
|
2018-06-03 23:40:54 +00:00
|
|
|
#include <sys/resource.h>
|
2016-05-22 04:17:00 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
2018-06-02 04:08:52 +00:00
|
|
|
#include <assert.h>
|
1997-03-23 18:51:21 +00:00
|
|
|
#include <ctype.h>
|
2018-08-22 10:07:15 +00:00
|
|
|
#include <err.h>
|
2018-05-21 03:58:15 +00:00
|
|
|
#include <stdarg.h>
|
2018-06-02 03:25:15 +00:00
|
|
|
#include <stdbool.h>
|
2018-05-19 23:19:24 +00:00
|
|
|
#include <stdlib.h>
|
2018-06-04 04:59:32 +00:00
|
|
|
#include <stdio.h>
|
2018-05-19 23:19:24 +00:00
|
|
|
#include <string.h>
|
2018-04-18 13:17:14 +00:00
|
|
|
#include <termcap.h>
|
1997-03-23 18:51:21 +00:00
|
|
|
#include <time.h>
|
2016-05-22 04:17:00 +00:00
|
|
|
#include <unistd.h>
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
#include "screen.h" /* interface to screen package */
|
|
|
|
#include "layout.h" /* defines for screen position layout */
|
|
|
|
#include "display.h"
|
|
|
|
#include "top.h"
|
|
|
|
#include "machine.h" /* we should eliminate this!!! */
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
FILE *debug;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int lmpid = 0;
|
|
|
|
static int last_hi = 0; /* used in u_process and u_endscreen */
|
|
|
|
static int lastline = 0;
|
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
#define lineindex(l) ((l)*screen_width)
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* things initialized by display_init and used thruout */
|
|
|
|
|
|
|
|
/* buffer of proc information lines for display updating */
|
2018-05-21 03:36:16 +00:00
|
|
|
static char *screenbuf = NULL;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-06-03 22:42:54 +00:00
|
|
|
static const char * const *procstate_names;
|
|
|
|
static const char * const *cpustate_names;
|
|
|
|
static const char * const *memory_names;
|
|
|
|
static const char * const *arc_names;
|
|
|
|
static const char * const *carc_names;
|
|
|
|
static const char * const *swap_names;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
static int num_procstates;
|
|
|
|
static int num_cpustates;
|
|
|
|
static int num_memory;
|
1997-03-23 18:53:01 +00:00
|
|
|
static int num_swap;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
static int *lprocstates;
|
|
|
|
static int *lcpustates;
|
|
|
|
static int *lmemory;
|
1997-03-23 18:53:01 +00:00
|
|
|
static int *lswap;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2008-01-18 01:43:14 +00:00
|
|
|
static int num_cpus;
|
1997-03-23 18:51:21 +00:00
|
|
|
static int *cpustate_columns;
|
|
|
|
static int cpustate_total_length;
|
2008-01-18 01:43:14 +00:00
|
|
|
static int cpustates_column;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
static enum { OFF, ON, ERASE } header_status = ON;
|
|
|
|
|
2018-06-03 23:40:54 +00:00
|
|
|
static void summary_format(char *, int *, const char * const *);
|
2018-05-21 00:53:42 +00:00
|
|
|
static void line_update(char *, char *, int, int);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
static int setup_buffer_bufsiz = 0;
|
|
|
|
static char * setup_buffer(char *, int);
|
|
|
|
|
2008-01-18 01:43:14 +00:00
|
|
|
int x_lastpid = 10;
|
|
|
|
int y_lastpid = 0;
|
|
|
|
int x_loadave = 33;
|
|
|
|
int x_loadave_nompid = 15;
|
|
|
|
int y_loadave = 0;
|
|
|
|
int x_procstate = 0;
|
|
|
|
int y_procstate = 1;
|
|
|
|
int x_brkdn = 15;
|
|
|
|
int y_brkdn = 1;
|
|
|
|
int x_mem = 5;
|
|
|
|
int y_mem = 3;
|
2012-06-27 18:08:48 +00:00
|
|
|
int x_arc = 5;
|
|
|
|
int y_arc = 4;
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
int x_carc = 5;
|
|
|
|
int y_carc = 5;
|
2008-01-18 01:43:14 +00:00
|
|
|
int x_swap = 6;
|
|
|
|
int y_swap = 4;
|
|
|
|
int y_message = 5;
|
|
|
|
int x_header = 0;
|
|
|
|
int y_header = 6;
|
|
|
|
int x_idlecursor = 0;
|
|
|
|
int y_idlecursor = 5;
|
|
|
|
int y_procs = 7;
|
|
|
|
|
|
|
|
int y_cpustates = 2;
|
|
|
|
int Header_lines = 7;
|
|
|
|
|
2018-06-02 00:02:15 +00:00
|
|
|
int
|
|
|
|
display_resize(void)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int lines;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* first, deallocate any previous buffer that may have been there */
|
|
|
|
if (screenbuf != NULL)
|
|
|
|
{
|
|
|
|
free(screenbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate the current dimensions */
|
|
|
|
/* if operating in "dumb" mode, we only need one line */
|
|
|
|
lines = smart_terminal ? screen_length - Header_lines : 1;
|
|
|
|
|
2002-08-11 18:37:25 +00:00
|
|
|
if (lines < 0)
|
|
|
|
lines = 0;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* now, allocate space for the screen buffer */
|
2018-07-06 12:07:06 +00:00
|
|
|
screenbuf = calloc(lines, screen_width);
|
2018-06-02 21:40:45 +00:00
|
|
|
if (screenbuf == NULL)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
/* oops! */
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return number of lines available */
|
|
|
|
/* for dumb terminals, pretend like we can show any amount */
|
|
|
|
return(smart_terminal ? lines : Largest);
|
|
|
|
}
|
|
|
|
|
2018-06-13 08:52:22 +00:00
|
|
|
int
|
|
|
|
display_updatecpus(struct statics *statics)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int lines;
|
|
|
|
int i;
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* call resize to do the dirty work */
|
|
|
|
lines = display_resize();
|
2011-07-18 21:15:47 +00:00
|
|
|
if (pcpu_stats)
|
2018-06-09 23:24:08 +00:00
|
|
|
num_cpus = statics->ncpus;
|
2011-07-18 21:15:47 +00:00
|
|
|
else
|
2018-06-09 23:24:08 +00:00
|
|
|
num_cpus = 1;
|
2008-01-18 01:43:14 +00:00
|
|
|
cpustates_column = 5; /* CPU: */
|
2018-06-09 23:24:08 +00:00
|
|
|
if (num_cpus > 1) {
|
|
|
|
cpustates_column += 1 + digits(num_cpus); /* CPU #: */
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2011-07-18 21:15:47 +00:00
|
|
|
/* fill the "last" array with all -1s, to insure correct updating */
|
2018-06-09 23:24:08 +00:00
|
|
|
for (i = 0; i < num_cpustates * num_cpus; ++i) {
|
|
|
|
lcpustates[i] = -1;
|
2011-07-18 21:15:47 +00:00
|
|
|
}
|
2018-06-12 07:31:59 +00:00
|
|
|
|
2011-07-11 16:48:52 +00:00
|
|
|
return(lines);
|
|
|
|
}
|
2018-06-12 07:31:59 +00:00
|
|
|
|
2018-06-13 08:52:22 +00:00
|
|
|
int
|
|
|
|
display_init(struct statics * statics)
|
2011-07-11 16:48:52 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int lines;
|
2019-02-10 13:31:08 +00:00
|
|
|
const char * const *pp;
|
2018-05-20 01:32:27 +00:00
|
|
|
int *ip;
|
|
|
|
int i;
|
2011-07-11 16:48:52 +00:00
|
|
|
|
|
|
|
lines = display_updatecpus(statics);
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* only do the rest if we need to */
|
|
|
|
if (lines > -1)
|
|
|
|
{
|
|
|
|
/* save pointers and allocate space for names */
|
|
|
|
procstate_names = statics->procstate_names;
|
2018-06-03 23:40:54 +00:00
|
|
|
num_procstates = 8;
|
2018-06-02 04:08:52 +00:00
|
|
|
assert(num_procstates > 0);
|
2018-06-02 21:40:45 +00:00
|
|
|
lprocstates = calloc(num_procstates, sizeof(int));
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
cpustate_names = statics->cpustate_names;
|
1997-03-23 18:53:01 +00:00
|
|
|
|
|
|
|
swap_names = statics->swap_names;
|
2018-06-03 23:40:54 +00:00
|
|
|
num_swap = 7;
|
2018-06-02 04:08:52 +00:00
|
|
|
assert(num_swap > 0);
|
2018-06-02 21:40:45 +00:00
|
|
|
lswap = calloc(num_swap, sizeof(int));
|
2018-06-03 23:40:54 +00:00
|
|
|
num_cpustates = CPUSTATES;
|
2018-06-02 04:08:52 +00:00
|
|
|
assert(num_cpustates > 0);
|
2018-06-02 21:40:45 +00:00
|
|
|
lcpustates = calloc(num_cpustates * sizeof(int), statics->ncpus);
|
|
|
|
cpustate_columns = calloc(num_cpustates, sizeof(int));
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
memory_names = statics->memory_names;
|
2018-06-03 23:40:54 +00:00
|
|
|
num_memory = 7;
|
2018-06-02 04:08:52 +00:00
|
|
|
assert(num_memory > 0);
|
2018-06-02 21:40:45 +00:00
|
|
|
lmemory = calloc(num_memory, sizeof(int));
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2012-06-27 18:08:48 +00:00
|
|
|
arc_names = statics->arc_names;
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
carc_names = statics->carc_names;
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* calculate starting columns where needed */
|
|
|
|
cpustate_total_length = 0;
|
|
|
|
pp = cpustate_names;
|
|
|
|
ip = cpustate_columns;
|
|
|
|
while (*pp != NULL)
|
|
|
|
{
|
2002-01-24 17:58:42 +00:00
|
|
|
*ip++ = cpustate_total_length;
|
1997-03-23 18:51:21 +00:00
|
|
|
if ((i = strlen(*pp++)) > 0)
|
|
|
|
{
|
|
|
|
cpustate_total_length += i + 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return number of lines available */
|
|
|
|
return(lines);
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_loadave(int mpid, double avenrun[])
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int i;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* i_loadave also clears the screen, since it is first */
|
2018-04-18 13:17:14 +00:00
|
|
|
top_clear();
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* mpid == -1 implies this system doesn't have an _mpid */
|
|
|
|
if (mpid != -1)
|
|
|
|
{
|
|
|
|
printf("last pid: %5d; ", mpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("load averages");
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
printf("%c %5.2f",
|
|
|
|
i == 0 ? ':' : ',',
|
|
|
|
avenrun[i]);
|
|
|
|
}
|
|
|
|
lmpid = mpid;
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_loadave(int mpid, double *avenrun)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int i;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
if (mpid != -1)
|
|
|
|
{
|
|
|
|
/* change screen only when value has really changed */
|
|
|
|
if (mpid != lmpid)
|
|
|
|
{
|
|
|
|
Move_to(x_lastpid, y_lastpid);
|
|
|
|
printf("%5d", mpid);
|
|
|
|
lmpid = mpid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* i remembers x coordinate to move to */
|
|
|
|
i = x_loadave;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = x_loadave_nompid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move into position for load averages */
|
|
|
|
Move_to(i, y_loadave);
|
|
|
|
|
|
|
|
/* display new load averages */
|
|
|
|
/* we should optimize this and only display changes */
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
printf("%s%5.2f",
|
|
|
|
i == 0 ? "" : ", ",
|
|
|
|
avenrun[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_timeofday(time_t *tod)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Display the current time.
|
|
|
|
* "ctime" always returns a string that looks like this:
|
2018-06-12 07:31:59 +00:00
|
|
|
*
|
1997-03-23 18:51:21 +00:00
|
|
|
* Sun Sep 16 01:03:52 1973
|
|
|
|
* 012345678901234567890123
|
|
|
|
* 1 2
|
|
|
|
*
|
|
|
|
* We want indices 11 thru 18 (length 8).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (smart_terminal)
|
|
|
|
{
|
|
|
|
Move_to(screen_width - 8, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
char *foo;
|
|
|
|
foo = ctime(tod);
|
|
|
|
fputs(foo, stdout);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
printf("%-8.8s\n", &(ctime(tod)[11]));
|
|
|
|
lastline = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ltotal = 0;
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *procstates_buffer = NULL;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* *_procstates(total, brkdn, names) - print the process summary line
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is at the beginning of the line on entry
|
|
|
|
* lastline is valid
|
|
|
|
*/
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_procstates(int total, int *brkdn)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int i;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
procstates_buffer = setup_buffer(procstates_buffer, 0);
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* write current number of processes and remember the value */
|
2018-07-10 17:20:27 +00:00
|
|
|
printf("%d %s:", total, ps.thread ? "threads" : "processes");
|
1997-03-23 18:51:21 +00:00
|
|
|
ltotal = total;
|
|
|
|
|
|
|
|
/* put out enough spaces to get to column 15 */
|
|
|
|
i = digits(total);
|
2018-07-10 17:20:27 +00:00
|
|
|
while (i++ < (ps.thread ? 6 : 4))
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
putchar(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* format and print the process state summary */
|
|
|
|
summary_format(procstates_buffer, brkdn, procstate_names);
|
|
|
|
fputs(procstates_buffer, stdout);
|
|
|
|
|
|
|
|
/* save the numbers for next time */
|
|
|
|
memcpy(lprocstates, brkdn, num_procstates * sizeof(int));
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_procstates(int total, int *brkdn)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *new = NULL;
|
2018-05-20 01:32:27 +00:00
|
|
|
int i;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
new = setup_buffer(new, 0);
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* update number of processes only if it has changed */
|
|
|
|
if (ltotal != total)
|
|
|
|
{
|
|
|
|
/* move and overwrite */
|
2018-06-13 00:45:38 +00:00
|
|
|
if (x_procstate == 0) {
|
1997-03-23 18:51:21 +00:00
|
|
|
Move_to(x_procstate, y_procstate);
|
2018-06-13 00:45:38 +00:00
|
|
|
}
|
|
|
|
else {
|
1997-03-23 18:51:21 +00:00
|
|
|
/* cursor is already there...no motion needed */
|
2018-06-13 00:45:38 +00:00
|
|
|
assert(lastline == 1);
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
printf("%d", total);
|
|
|
|
|
|
|
|
/* if number of digits differs, rewrite the label */
|
|
|
|
if (digits(total) != digits(ltotal))
|
|
|
|
{
|
2018-07-10 17:20:27 +00:00
|
|
|
printf(" %s:", ps.thread ? "threads" : "processes");
|
1997-03-23 18:51:21 +00:00
|
|
|
/* put out enough spaces to get to column 15 */
|
|
|
|
i = digits(total);
|
2018-07-10 17:20:27 +00:00
|
|
|
while (i++ < (ps.thread ? 6 : 4))
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
putchar(' ');
|
|
|
|
}
|
|
|
|
/* cursor may end up right where we want it!!! */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save new total */
|
|
|
|
ltotal = total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see if any of the state numbers has changed */
|
|
|
|
if (memcmp(lprocstates, brkdn, num_procstates * sizeof(int)) != 0)
|
|
|
|
{
|
|
|
|
/* format and update the line */
|
|
|
|
summary_format(new, brkdn, procstate_names);
|
|
|
|
line_update(procstates_buffer, new, x_brkdn, y_brkdn);
|
|
|
|
memcpy(lprocstates, brkdn, num_procstates * sizeof(int));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_cpustates(int *states)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int i = 0;
|
|
|
|
int value;
|
2018-06-03 23:40:54 +00:00
|
|
|
const char * const *names;
|
|
|
|
const char *thisname;
|
2018-07-27 07:05:50 +00:00
|
|
|
int *hstates = states;
|
2008-01-18 01:43:14 +00:00
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for (cpu = 0; cpu < num_cpus; cpu++) {
|
|
|
|
names = cpustate_names;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* print tag and bump lastline */
|
2008-01-18 01:43:14 +00:00
|
|
|
if (num_cpus == 1)
|
|
|
|
printf("\nCPU: ");
|
2011-02-01 15:48:27 +00:00
|
|
|
else {
|
|
|
|
value = printf("\nCPU %d: ", cpu);
|
|
|
|
while (value++ <= cpustates_column)
|
|
|
|
printf(" ");
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
lastline++;
|
|
|
|
|
|
|
|
/* now walk thru the names and print the line */
|
|
|
|
while ((thisname = *names++) != NULL)
|
|
|
|
{
|
|
|
|
if (*thisname != '\0')
|
|
|
|
{
|
|
|
|
/* retrieve the value and remember it */
|
|
|
|
value = *states++;
|
|
|
|
|
|
|
|
/* if percentage is >= 1000, print it as 100% */
|
|
|
|
printf((value >= 1000 ? "%s%4.0f%% %s" : "%s%4.1f%% %s"),
|
2008-01-18 01:43:14 +00:00
|
|
|
(i++ % num_cpustates) == 0 ? "" : ", ",
|
1997-03-23 18:51:21 +00:00
|
|
|
((float)value)/10.,
|
|
|
|
thisname);
|
|
|
|
}
|
|
|
|
}
|
2008-01-18 01:43:14 +00:00
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* copy over values into "last" array */
|
2018-07-27 07:05:50 +00:00
|
|
|
states = hstates;
|
2008-01-18 01:43:14 +00:00
|
|
|
memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_cpustates(int *states)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int value;
|
2018-06-08 01:55:47 +00:00
|
|
|
const char * const *names;
|
|
|
|
const char *thisname;
|
2018-07-27 07:05:50 +00:00
|
|
|
int *hstates = states;
|
2018-05-20 01:32:27 +00:00
|
|
|
int *lp;
|
|
|
|
int *colp;
|
2008-01-18 01:43:14 +00:00
|
|
|
int cpu;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2008-01-18 01:43:14 +00:00
|
|
|
for (cpu = 0; cpu < num_cpus; cpu++) {
|
|
|
|
names = cpustate_names;
|
|
|
|
|
|
|
|
Move_to(cpustates_column, y_cpustates + cpu);
|
|
|
|
lastline = y_cpustates + cpu;
|
|
|
|
lp = lcpustates + (cpu * num_cpustates);
|
1997-03-23 18:51:21 +00:00
|
|
|
colp = cpustate_columns;
|
|
|
|
|
|
|
|
/* we could be much more optimal about this */
|
|
|
|
while ((thisname = *names++) != NULL)
|
|
|
|
{
|
|
|
|
if (*thisname != '\0')
|
|
|
|
{
|
|
|
|
/* did the value change since last time? */
|
|
|
|
if (*lp != *states)
|
|
|
|
{
|
|
|
|
/* yes, move and change */
|
2008-01-18 01:43:14 +00:00
|
|
|
Move_to(cpustates_column + *colp, y_cpustates + cpu);
|
|
|
|
lastline = y_cpustates + cpu;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* retrieve value and remember it */
|
|
|
|
value = *states;
|
|
|
|
|
|
|
|
/* if percentage is >= 1000, print it as 100% */
|
|
|
|
printf((value >= 1000 ? "%4.0f" : "%4.1f"),
|
|
|
|
((double)value)/10.);
|
|
|
|
|
|
|
|
/* remember it for next time */
|
2002-01-24 17:58:42 +00:00
|
|
|
*lp = value;
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* increment and move on */
|
|
|
|
lp++;
|
|
|
|
states++;
|
|
|
|
colp++;
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 07:05:50 +00:00
|
|
|
|
|
|
|
states = hstates;
|
2008-01-18 01:43:14 +00:00
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
z_cpustates(void)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int i = 0;
|
2019-02-10 13:31:08 +00:00
|
|
|
const char * const *names;
|
|
|
|
const char *thisname;
|
2011-02-01 15:48:27 +00:00
|
|
|
int cpu, value;
|
2008-01-18 01:43:14 +00:00
|
|
|
|
2018-06-08 01:55:47 +00:00
|
|
|
for (cpu = 0; cpu < num_cpus; cpu++) {
|
|
|
|
names = cpustate_names;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-06-08 01:55:47 +00:00
|
|
|
/* show tag and bump lastline */
|
|
|
|
if (num_cpus == 1)
|
|
|
|
printf("\nCPU: ");
|
|
|
|
else {
|
|
|
|
value = printf("\nCPU %d: ", cpu);
|
|
|
|
while (value++ <= cpustates_column)
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
lastline++;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-06-08 01:55:47 +00:00
|
|
|
while ((thisname = *names++) != NULL)
|
|
|
|
{
|
|
|
|
if (*thisname != '\0')
|
|
|
|
{
|
|
|
|
printf("%s %% %s", (i++ % num_cpustates) == 0 ? "" : ", ", thisname);
|
|
|
|
}
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the "last" array with all -1s, to insure correct updating */
|
2018-06-09 23:24:08 +00:00
|
|
|
for (i = 0; i < num_cpustates * num_cpus; ++i) {
|
|
|
|
lcpustates[i] = -1;
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* *_memory(stats) - print "Memory: " followed by the memory summary string
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is on "lastline"
|
|
|
|
* for i_memory ONLY: cursor is on the previous line
|
|
|
|
*/
|
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *memory_buffer = NULL;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 09:25:21 +00:00
|
|
|
i_memory(int *stats)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
memory_buffer = setup_buffer(memory_buffer, 0);
|
|
|
|
|
1997-03-23 18:53:01 +00:00
|
|
|
fputs("\nMem: ", stdout);
|
1997-03-23 18:51:21 +00:00
|
|
|
lastline++;
|
|
|
|
|
|
|
|
/* format and print the memory summary */
|
|
|
|
summary_format(memory_buffer, stats, memory_names);
|
|
|
|
fputs(memory_buffer, stdout);
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 09:25:21 +00:00
|
|
|
u_memory(int *stats)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *new = NULL;
|
|
|
|
|
|
|
|
new = setup_buffer(new, 0);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* format the new line */
|
|
|
|
summary_format(new, stats, memory_names);
|
|
|
|
line_update(memory_buffer, new, x_mem, y_mem);
|
|
|
|
}
|
|
|
|
|
2012-06-27 18:08:48 +00:00
|
|
|
/*
|
|
|
|
* *_arc(stats) - print "ARC: " followed by the ARC summary string
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is on "lastline"
|
|
|
|
* for i_arc ONLY: cursor is on the previous line
|
|
|
|
*/
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *arc_buffer = NULL;
|
2012-06-27 18:08:48 +00:00
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 03:36:16 +00:00
|
|
|
i_arc(int *stats)
|
2012-06-27 18:08:48 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
arc_buffer = setup_buffer(arc_buffer, 0);
|
|
|
|
|
2012-06-27 18:08:48 +00:00
|
|
|
if (arc_names == NULL)
|
2016-05-22 04:17:00 +00:00
|
|
|
return;
|
2012-06-27 18:08:48 +00:00
|
|
|
|
|
|
|
fputs("\nARC: ", stdout);
|
|
|
|
lastline++;
|
|
|
|
|
|
|
|
/* format and print the memory summary */
|
|
|
|
summary_format(arc_buffer, stats, arc_names);
|
|
|
|
fputs(arc_buffer, stdout);
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_arc(int *stats)
|
2012-06-27 18:08:48 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *new = NULL;
|
|
|
|
|
|
|
|
new = setup_buffer(new, 0);
|
2012-06-27 18:08:48 +00:00
|
|
|
|
|
|
|
if (arc_names == NULL)
|
2016-05-22 04:17:00 +00:00
|
|
|
return;
|
2012-06-27 18:08:48 +00:00
|
|
|
|
|
|
|
/* format the new line */
|
|
|
|
summary_format(new, stats, arc_names);
|
|
|
|
line_update(arc_buffer, new, x_arc, y_arc);
|
|
|
|
}
|
|
|
|
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* *_carc(stats) - print "Compressed ARC: " followed by the summary string
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is on "lastline"
|
|
|
|
* for i_carc ONLY: cursor is on the previous line
|
|
|
|
*/
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *carc_buffer = NULL;
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
|
|
|
|
void
|
2018-05-21 03:36:16 +00:00
|
|
|
i_carc(int *stats)
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
carc_buffer = setup_buffer(carc_buffer, 0);
|
|
|
|
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
if (carc_names == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fputs("\n ", stdout);
|
|
|
|
lastline++;
|
|
|
|
|
|
|
|
/* format and print the memory summary */
|
|
|
|
summary_format(carc_buffer, stats, carc_names);
|
|
|
|
fputs(carc_buffer, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_carc(int *stats)
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *new = NULL;
|
|
|
|
|
|
|
|
new = setup_buffer(new, 0);
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
|
|
|
|
if (carc_names == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* format the new line */
|
|
|
|
summary_format(new, stats, carc_names);
|
|
|
|
line_update(carc_buffer, new, x_carc, y_carc);
|
|
|
|
}
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:53:01 +00:00
|
|
|
/*
|
|
|
|
* *_swap(stats) - print "Swap: " followed by the swap summary string
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is on "lastline"
|
|
|
|
* for i_swap ONLY: cursor is on the previous line
|
|
|
|
*/
|
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *swap_buffer = NULL;
|
1997-03-23 18:53:01 +00:00
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 03:36:16 +00:00
|
|
|
i_swap(int *stats)
|
1997-03-23 18:53:01 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
swap_buffer = setup_buffer(swap_buffer, 0);
|
|
|
|
|
1997-03-23 18:53:01 +00:00
|
|
|
fputs("\nSwap: ", stdout);
|
|
|
|
lastline++;
|
|
|
|
|
|
|
|
/* format and print the swap summary */
|
|
|
|
summary_format(swap_buffer, stats, swap_names);
|
|
|
|
fputs(swap_buffer, stdout);
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 03:36:16 +00:00
|
|
|
u_swap(int *stats)
|
1997-03-23 18:53:01 +00:00
|
|
|
{
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *new = NULL;
|
|
|
|
|
|
|
|
new = setup_buffer(new, 0);
|
1997-03-23 18:53:01 +00:00
|
|
|
|
|
|
|
/* format the new line */
|
|
|
|
summary_format(new, stats, swap_names);
|
|
|
|
line_update(swap_buffer, new, x_swap, y_swap);
|
|
|
|
}
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/*
|
|
|
|
* *_message() - print the next pending message line, or erase the one
|
|
|
|
* that is there.
|
|
|
|
*
|
|
|
|
* Note that u_message is (currently) the same as i_message.
|
|
|
|
*
|
|
|
|
* Assumptions: lastline is consistent
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* i_message is funny because it gets its message asynchronously (with
|
|
|
|
* respect to screen updates).
|
|
|
|
*/
|
|
|
|
|
2018-07-10 00:19:52 +00:00
|
|
|
#define NEXT_MSG_ADDLEN 5
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *next_msg = NULL;
|
1997-03-23 18:51:21 +00:00
|
|
|
static int msglen = 0;
|
|
|
|
/* Invariant: msglen is always the length of the message currently displayed
|
|
|
|
on the screen (even when next_msg doesn't contain that message). */
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_message(void)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-07-10 00:19:52 +00:00
|
|
|
next_msg = setup_buffer(next_msg, NEXT_MSG_ADDLEN);
|
2018-05-21 03:36:16 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
while (lastline < y_message)
|
|
|
|
{
|
|
|
|
fputc('\n', stdout);
|
|
|
|
lastline++;
|
|
|
|
}
|
|
|
|
if (next_msg[0] != '\0')
|
|
|
|
{
|
2018-04-18 13:17:14 +00:00
|
|
|
top_standout(next_msg);
|
1997-03-23 18:51:21 +00:00
|
|
|
msglen = strlen(next_msg);
|
|
|
|
next_msg[0] = '\0';
|
|
|
|
}
|
|
|
|
else if (msglen > 0)
|
|
|
|
{
|
|
|
|
(void) clear_eol(msglen);
|
|
|
|
msglen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_message(void)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
i_message();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int header_length;
|
|
|
|
|
2005-05-18 13:48:33 +00:00
|
|
|
/*
|
|
|
|
* Trim a header string to the current display width and return a newly
|
|
|
|
* allocated area with the trimmed header.
|
|
|
|
*/
|
|
|
|
|
2019-02-10 13:31:08 +00:00
|
|
|
char *
|
2018-06-03 22:42:54 +00:00
|
|
|
trim_header(const char *text)
|
2005-05-18 13:48:33 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
s = NULL;
|
2018-07-06 12:07:06 +00:00
|
|
|
width = screen_width;
|
2005-05-18 13:48:33 +00:00
|
|
|
header_length = strlen(text);
|
|
|
|
if (header_length >= width) {
|
2018-06-03 22:42:54 +00:00
|
|
|
s = strndup(text, width);
|
2005-05-18 13:48:33 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/*
|
|
|
|
* *_header(text) - print the header for the process area
|
|
|
|
*
|
|
|
|
* Assumptions: cursor is on the previous line and lastline is consistent
|
|
|
|
*/
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-03 22:42:54 +00:00
|
|
|
i_header(const char *text)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-06-03 23:40:54 +00:00
|
|
|
char *s;
|
2005-05-18 13:48:33 +00:00
|
|
|
|
|
|
|
s = trim_header(text);
|
|
|
|
if (s != NULL)
|
|
|
|
text = s;
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
if (header_status == ON)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
2011-06-20 16:48:00 +00:00
|
|
|
fputs(text, stdout);
|
1997-03-23 18:51:21 +00:00
|
|
|
lastline++;
|
|
|
|
}
|
|
|
|
else if (header_status == ERASE)
|
|
|
|
{
|
|
|
|
header_status = OFF;
|
|
|
|
}
|
2005-05-18 13:48:33 +00:00
|
|
|
free(s);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-03 22:42:54 +00:00
|
|
|
u_header(const char *text __unused)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2005-05-18 13:48:33 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
if (header_status == ERASE)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
lastline++;
|
|
|
|
clear_eol(header_length);
|
|
|
|
header_status = OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* *_process(line, thisline) - print one process line
|
|
|
|
*
|
|
|
|
* Assumptions: lastline is consistent
|
|
|
|
*/
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_process(int line, char *thisline)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
char *p;
|
|
|
|
char *base;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* make sure we are on the correct line */
|
|
|
|
while (lastline < y_procs + line)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
lastline++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truncate the line to conform to our current screen width */
|
2018-07-06 12:07:06 +00:00
|
|
|
thisline[screen_width] = '\0';
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* write the line out */
|
|
|
|
fputs(thisline, stdout);
|
|
|
|
|
|
|
|
/* copy it in to our buffer */
|
|
|
|
base = smart_terminal ? screenbuf + lineindex(line) : screenbuf;
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(base, thisline);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* zero fill the rest of it */
|
2018-07-06 12:07:06 +00:00
|
|
|
memset(p, 0, screen_width - (p - base));
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_process(int line, char *newline)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
char *optr;
|
|
|
|
int screen_line = line + Header_lines;
|
|
|
|
char *bufferline;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* remember a pointer to the current line in the screen buffer */
|
|
|
|
bufferline = &screenbuf[lineindex(line)];
|
|
|
|
|
|
|
|
/* truncate the line to conform to our current screen width */
|
2018-07-06 12:07:06 +00:00
|
|
|
newline[screen_width] = '\0';
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* is line higher than we went on the last display? */
|
|
|
|
if (line >= last_hi)
|
|
|
|
{
|
|
|
|
/* yes, just ignore screenbuf and write it out directly */
|
|
|
|
/* get positioned on the correct line */
|
|
|
|
if (screen_line - lastline == 1)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
lastline++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Move_to(0, screen_line);
|
|
|
|
lastline = screen_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now write the line */
|
|
|
|
fputs(newline, stdout);
|
|
|
|
|
|
|
|
/* copy it in to the buffer */
|
2018-06-02 08:46:09 +00:00
|
|
|
optr = stpcpy(bufferline, newline);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* zero fill the rest of it */
|
2018-07-06 12:07:06 +00:00
|
|
|
memset(optr, 0, screen_width - (optr - bufferline));
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line_update(bufferline, newline, 0, line + Header_lines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
u_endscreen(int hi)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int screen_line = hi + Header_lines;
|
|
|
|
int i;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
if (smart_terminal)
|
|
|
|
{
|
|
|
|
if (hi < last_hi)
|
|
|
|
{
|
|
|
|
/* need to blank the remainder of the screen */
|
|
|
|
/* but only if there is any screen left below this line */
|
|
|
|
if (lastline + 1 < screen_length)
|
|
|
|
{
|
|
|
|
/* efficiently move to the end of currently displayed info */
|
|
|
|
if (screen_line - lastline < 5)
|
|
|
|
{
|
|
|
|
while (lastline < screen_line)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
lastline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Move_to(0, screen_line);
|
|
|
|
lastline = screen_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clear_to_end)
|
|
|
|
{
|
|
|
|
/* we can do this the easy way */
|
|
|
|
putcap(clear_to_end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use clear_eol on each line */
|
|
|
|
i = hi;
|
|
|
|
while ((void) clear_eol(strlen(&screenbuf[lineindex(i++)])), i < last_hi)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_hi = hi;
|
|
|
|
|
|
|
|
/* move the cursor to a pleasant place */
|
|
|
|
Move_to(x_idlecursor, y_idlecursor);
|
|
|
|
lastline = y_idlecursor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* separate this display from the next with some vertical room */
|
|
|
|
fputs("\n\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-05-21 00:53:42 +00:00
|
|
|
display_header(int t)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-21 00:53:42 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
header_status = ON;
|
|
|
|
}
|
|
|
|
else if (header_status == ON)
|
|
|
|
{
|
|
|
|
header_status = ERASE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 07:44:50 +00:00
|
|
|
new_message(int type, const char *msgfmt, ...)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-21 03:58:15 +00:00
|
|
|
va_list args;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
va_start(args, msgfmt);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* first, format the message */
|
2018-07-10 00:19:52 +00:00
|
|
|
vsnprintf(next_msg, setup_buffer_bufsiz + NEXT_MSG_ADDLEN,
|
|
|
|
msgfmt, args);
|
1997-03-23 18:51:21 +00:00
|
|
|
|
2018-05-21 09:21:42 +00:00
|
|
|
va_end(args);
|
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
if (msglen > 0)
|
|
|
|
{
|
|
|
|
/* message there already -- can we clear it? */
|
|
|
|
if (!overstrike)
|
|
|
|
{
|
|
|
|
/* yes -- write it and clear to end */
|
|
|
|
i = strlen(next_msg);
|
|
|
|
if ((type & MT_delayed) == 0)
|
|
|
|
{
|
2018-06-13 00:45:38 +00:00
|
|
|
if (type & MT_standout) {
|
|
|
|
top_standout(next_msg);
|
|
|
|
} else {
|
|
|
|
fputs(next_msg, stdout);
|
|
|
|
}
|
|
|
|
clear_eol(msglen - i);
|
|
|
|
msglen = i;
|
|
|
|
next_msg[0] = '\0';
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((type & MT_delayed) == 0)
|
|
|
|
{
|
2018-06-13 00:45:38 +00:00
|
|
|
if (type & MT_standout) {
|
|
|
|
top_standout(next_msg);
|
|
|
|
} else {
|
|
|
|
fputs(next_msg, stdout);
|
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
msglen = strlen(next_msg);
|
|
|
|
next_msg[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
clear_message(void)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
if (clear_eol(msglen) == 1)
|
|
|
|
{
|
|
|
|
putchar('\r');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
int
|
2018-06-02 00:02:15 +00:00
|
|
|
readline(char *buffer, int size, int numeric)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
char *ptr = buffer;
|
|
|
|
char ch;
|
|
|
|
char cnt = 0;
|
|
|
|
char maxcnt = 0;
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* allow room for null terminator */
|
|
|
|
size -= 1;
|
|
|
|
|
|
|
|
/* read loop */
|
|
|
|
while ((fflush(stdout), read(0, ptr, 1) > 0))
|
|
|
|
{
|
|
|
|
/* newline means we are done */
|
1997-03-23 18:53:01 +00:00
|
|
|
if ((ch = *ptr) == '\n' || ch == '\r')
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle special editing characters */
|
|
|
|
if (ch == ch_kill)
|
|
|
|
{
|
|
|
|
/* kill line -- account for overstriking */
|
|
|
|
if (overstrike)
|
|
|
|
{
|
|
|
|
msglen += maxcnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return null string */
|
|
|
|
*buffer = '\0';
|
|
|
|
putchar('\r');
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
else if (ch == ch_erase)
|
|
|
|
{
|
|
|
|
/* erase previous character */
|
|
|
|
if (cnt <= 0)
|
|
|
|
{
|
|
|
|
/* none to erase! */
|
|
|
|
putchar('\7');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fputs("\b \b", stdout);
|
|
|
|
ptr--;
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check for character validity and buffer overflow */
|
|
|
|
else if (cnt == size || (numeric && !isdigit(ch)) ||
|
|
|
|
!isprint(ch))
|
|
|
|
{
|
|
|
|
/* not legal */
|
|
|
|
putchar('\7');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* echo it and store it in the buffer */
|
|
|
|
putchar(ch);
|
|
|
|
ptr++;
|
|
|
|
cnt++;
|
|
|
|
if (cnt > maxcnt)
|
|
|
|
{
|
|
|
|
maxcnt = cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all done -- null terminate the string */
|
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
/* account for the extra characters in the message area */
|
|
|
|
/* (if terminal overstrikes, remember the furthest they went) */
|
|
|
|
msglen += overstrike ? maxcnt : cnt;
|
|
|
|
|
|
|
|
/* return either inputted number or string length */
|
|
|
|
putchar('\r');
|
|
|
|
return(cnt == 0 ? -1 : numeric ? atoi(buffer) : cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal support routines */
|
|
|
|
|
2018-06-13 08:52:22 +00:00
|
|
|
static void
|
|
|
|
summary_format(char *str, int *numbers, const char * const *names)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
char *p;
|
|
|
|
int num;
|
2018-06-03 23:40:54 +00:00
|
|
|
const char *thisname;
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
char rbuf[6];
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* format each number followed by its string */
|
|
|
|
p = str;
|
|
|
|
while ((thisname = *names++) != NULL)
|
|
|
|
{
|
|
|
|
/* get the number to format */
|
|
|
|
num = *numbers++;
|
|
|
|
|
|
|
|
/* display only non-zero numbers */
|
|
|
|
if (num > 0)
|
|
|
|
{
|
|
|
|
/* is this number in kilobytes? */
|
|
|
|
if (thisname[0] == 'K')
|
|
|
|
{
|
|
|
|
/* yes: format it as a memory value */
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(p, format_k(num));
|
1997-03-23 18:51:21 +00:00
|
|
|
|
|
|
|
/* skip over the K, since it was included by format_k */
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(p, thisname+1);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
/* is this number a ratio? */
|
|
|
|
else if (thisname[0] == ':')
|
|
|
|
{
|
2018-06-12 07:31:59 +00:00
|
|
|
(void) snprintf(rbuf, sizeof(rbuf), "%.2f",
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
(float)*(numbers - 2) / (float)num);
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(p, rbuf);
|
|
|
|
p = stpcpy(p, thisname);
|
Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)
Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead
Reviewed by: jpaetzel, smh, imp, jhb (previous version)
MFC after: 2 week
Relnotes: yes
Sponsored by: ScaleEngine Inc.
Differential Revision: https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
|
|
|
}
|
1997-03-23 18:51:21 +00:00
|
|
|
else
|
|
|
|
{
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(p, itoa(num));
|
|
|
|
p = stpcpy(p, thisname);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore negative numbers, but display corresponding string */
|
|
|
|
else if (num < 0)
|
|
|
|
{
|
2018-06-02 08:46:09 +00:00
|
|
|
p = stpcpy(p, thisname);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the last two characters in the string are ", ", delete them */
|
|
|
|
p -= 2;
|
|
|
|
if (p >= str && p[0] == ',' && p[1] == ' ')
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-02 00:02:15 +00:00
|
|
|
static void
|
|
|
|
line_update(char *old, char *new, int start, int line)
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-05-20 01:32:27 +00:00
|
|
|
int ch;
|
|
|
|
int diff;
|
|
|
|
int newcol = start + 1;
|
|
|
|
int lastcol = start;
|
2018-06-02 03:25:15 +00:00
|
|
|
char cursor_on_line = false;
|
1997-03-23 18:51:21 +00:00
|
|
|
char *current;
|
|
|
|
|
|
|
|
/* compare the two strings and only rewrite what has changed */
|
|
|
|
current = old;
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(debug, "line_update, starting at %d\n", start);
|
|
|
|
fputs(old, debug);
|
|
|
|
fputc('\n', debug);
|
|
|
|
fputs(new, debug);
|
|
|
|
fputs("\n-\n", debug);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* start things off on the right foot */
|
|
|
|
/* this is to make sure the invariants get set up right */
|
|
|
|
if ((ch = *new++) != *old)
|
|
|
|
{
|
|
|
|
if (line - lastline == 1 && start == 0)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Move_to(start, line);
|
|
|
|
}
|
2018-06-02 03:25:15 +00:00
|
|
|
cursor_on_line = true;
|
1997-03-23 18:51:21 +00:00
|
|
|
putchar(ch);
|
|
|
|
*old = ch;
|
|
|
|
lastcol = 1;
|
|
|
|
}
|
|
|
|
old++;
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/*
|
|
|
|
* main loop -- check each character. If the old and new aren't the
|
|
|
|
* same, then update the display. When the distance from the
|
|
|
|
* current cursor position to the new change is small enough,
|
|
|
|
* the characters that belong there are written to move the
|
|
|
|
* cursor over.
|
|
|
|
*
|
|
|
|
* Invariants:
|
|
|
|
* lastcol is the column where the cursor currently is sitting
|
|
|
|
* (always one beyond the end of the last mismatch).
|
|
|
|
*/
|
|
|
|
do /* yes, a do...while */
|
|
|
|
{
|
|
|
|
if ((ch = *new++) != *old)
|
|
|
|
{
|
|
|
|
/* new character is different from old */
|
|
|
|
/* make sure the cursor is on top of this character */
|
|
|
|
diff = newcol - lastcol;
|
|
|
|
if (diff > 0)
|
|
|
|
{
|
|
|
|
/* some motion is required--figure out which is shorter */
|
|
|
|
if (diff < 6 && cursor_on_line)
|
|
|
|
{
|
|
|
|
/* overwrite old stuff--get it out of the old buffer */
|
|
|
|
printf("%.*s", diff, ¤t[lastcol-start]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use cursor addressing */
|
|
|
|
Move_to(newcol, line);
|
2018-06-02 03:25:15 +00:00
|
|
|
cursor_on_line = true;
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
/* remember where the cursor is */
|
|
|
|
lastcol = newcol + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* already there, update position */
|
|
|
|
lastcol++;
|
|
|
|
}
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* write what we need to */
|
|
|
|
if (ch == '\0')
|
|
|
|
{
|
|
|
|
/* at the end--terminate with a clear-to-end-of-line */
|
|
|
|
(void) clear_eol(strlen(old));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* write the new character */
|
|
|
|
putchar(ch);
|
|
|
|
}
|
|
|
|
/* put the new character in the screen buffer */
|
|
|
|
*old = ch;
|
|
|
|
}
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
/* update working column and screen buffer pointer */
|
|
|
|
newcol++;
|
|
|
|
old++;
|
2018-06-12 07:31:59 +00:00
|
|
|
|
1997-03-23 18:51:21 +00:00
|
|
|
} while (ch != '\0');
|
|
|
|
|
|
|
|
/* zero out the rest of the line buffer -- MUST BE DONE! */
|
2018-07-06 12:07:06 +00:00
|
|
|
diff = screen_width - newcol;
|
1997-03-23 18:51:21 +00:00
|
|
|
if (diff > 0)
|
|
|
|
{
|
2018-06-04 04:59:32 +00:00
|
|
|
memset(old, 0, diff);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remember where the current line is */
|
|
|
|
if (cursor_on_line)
|
|
|
|
{
|
|
|
|
lastline = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* printable(str) - make the string pointed to by "str" into one that is
|
|
|
|
* printable (i.e.: all ascii), by converting all non-printable
|
|
|
|
* characters into '?'. Replacements are done in place and a pointer
|
|
|
|
* to the original buffer is returned.
|
|
|
|
*/
|
|
|
|
|
2018-06-02 00:02:15 +00:00
|
|
|
char *
|
|
|
|
printable(char str[])
|
1997-03-23 18:51:21 +00:00
|
|
|
{
|
2018-07-10 03:49:48 +00:00
|
|
|
char *ptr;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
ptr = str;
|
|
|
|
while ((ch = *ptr) != '\0')
|
|
|
|
{
|
|
|
|
if (!isprint(ch))
|
|
|
|
{
|
|
|
|
*ptr = '?';
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
2018-07-10 03:49:48 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
return(str);
|
1997-03-23 18:51:21 +00:00
|
|
|
}
|
1999-01-09 20:25:02 +00:00
|
|
|
|
2016-05-22 04:17:00 +00:00
|
|
|
void
|
2018-06-02 00:02:15 +00:00
|
|
|
i_uptime(struct timeval *bt, time_t *tod)
|
1999-01-09 20:25:02 +00:00
|
|
|
{
|
|
|
|
time_t uptime;
|
|
|
|
int days, hrs, mins, secs;
|
|
|
|
|
|
|
|
if (bt->tv_sec != -1) {
|
|
|
|
uptime = *tod - bt->tv_sec;
|
|
|
|
days = uptime / 86400;
|
|
|
|
uptime %= 86400;
|
|
|
|
hrs = uptime / 3600;
|
|
|
|
uptime %= 3600;
|
|
|
|
mins = uptime / 60;
|
|
|
|
secs = uptime % 60;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display the uptime.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (smart_terminal)
|
|
|
|
{
|
|
|
|
Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fputs(" ", stdout);
|
|
|
|
}
|
|
|
|
printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs);
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 12:07:06 +00:00
|
|
|
|
2018-07-10 00:19:52 +00:00
|
|
|
#define SETUPBUFFER_REQUIRED_ADDBUFSIZ 2
|
|
|
|
|
2018-07-06 12:07:06 +00:00
|
|
|
static char *
|
|
|
|
setup_buffer(char *buffer, int addlen)
|
|
|
|
{
|
|
|
|
char *b = NULL;
|
|
|
|
|
|
|
|
if (NULL == buffer) {
|
|
|
|
setup_buffer_bufsiz = screen_width;
|
2018-07-10 00:19:52 +00:00
|
|
|
b = calloc(setup_buffer_bufsiz + addlen +
|
|
|
|
SETUPBUFFER_REQUIRED_ADDBUFSIZ,
|
|
|
|
sizeof(char));
|
2018-07-06 12:07:06 +00:00
|
|
|
} else {
|
|
|
|
if (screen_width > setup_buffer_bufsiz) {
|
|
|
|
setup_buffer_bufsiz = screen_width;
|
|
|
|
free(buffer);
|
2018-07-10 00:19:52 +00:00
|
|
|
b = calloc(setup_buffer_bufsiz + addlen +
|
|
|
|
SETUPBUFFER_REQUIRED_ADDBUFSIZ,
|
2018-07-06 12:07:06 +00:00
|
|
|
sizeof(char));
|
|
|
|
} else {
|
|
|
|
b = buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == b) {
|
2018-08-22 10:07:15 +00:00
|
|
|
errx(4, "can't allocate sufficient memory");
|
2018-07-06 12:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|