Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177555554
D61090.1794709480.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
D61090.1794709480.diff
View Options
diff --git a/usr.bin/top/commands.h b/usr.bin/top/commands.h
--- a/usr.bin/top/commands.h
+++ b/usr.bin/top/commands.h
@@ -23,6 +23,7 @@
CMD_quit,
CMD_help,
CMD_grep,
+ CMD_hl,
CMD_errors,
CMD_number,
CMD_delay,
diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c
--- a/usr.bin/top/commands.c
+++ b/usr.bin/top/commands.c
@@ -65,6 +65,7 @@
{'J', "display processes for only one jail (+ selects all jails)", false, CMD_jail},
{'j', "toggle the display of jail ID", false, CMD_jidtog},
{'k', "kill processes; send a signal to a list of processes", false, CMD_kill},
+ {'L', "highlight one process (+ clears highlighting)", false, CMD_hl},
{'m', "toggle the display between 'cpu' and 'io' modes", false, CMD_viewtog},
{'n', "change number of processes to display", false, CMD_number},
{'#', NULL, false, CMD_number},
@@ -515,4 +516,3 @@
/* return appropriate error string */
return(err_string());
}
-
diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h
--- a/usr.bin/top/display.h
+++ b/usr.bin/top/display.h
@@ -19,7 +19,7 @@
void i_loadave(int mpid, double *avenrun);
void i_memory(int *stats);
void i_message(void);
-void i_process(int line, char *thisline);
+void i_process(int line, char *thisline, int hl);
void i_procstates(int total, int *brkdn);
void i_swap(int *stats);
void i_timeofday(time_t *tod);
@@ -35,7 +35,7 @@
void u_loadave(int mpid, double *avenrun);
void u_memory(int *stats);
void u_message(void);
-void u_process(int line, char *newline);
+void u_process(int line, char *newline, int hl);
void u_procstates(int total, int *brkdn);
void u_swap(int *stats);
void z_cpustates(void);
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -64,6 +64,7 @@
/* buffer of proc information lines for display updating */
static char *screenbuf = NULL;
+static bool *screenhl = NULL;
static const char * const *procstate_names;
static const char * const *cpustate_names;
@@ -132,6 +133,8 @@
{
free(screenbuf);
}
+ free(screenhl);
+ screenhl = NULL;
/* calculate the current dimensions */
/* if operating in "dumb" mode, we only need one line */
@@ -147,6 +150,12 @@
/* oops! */
return(-1);
}
+ screenhl = calloc(lines, sizeof(*screenhl));
+ if (screenhl == NULL) {
+ free(screenbuf);
+ screenbuf = NULL;
+ return (-1);
+ }
/* return number of lines available */
/* for dumb terminals, pretend like we can show any amount */
@@ -820,7 +829,7 @@
*/
void
-i_process(int line, char *thisline)
+i_process(int line, char *thisline, int hl)
{
char *p;
char *base;
@@ -840,11 +849,16 @@
}
/* write the line out */
- fputs(thisline, stdout);
+ if (hl)
+ top_standout(thisline);
+ else
+ fputs(thisline, stdout);
/* copy it in to our buffer */
base = smart_terminal ? screenbuf + lineindex(line) : screenbuf;
p = stpcpy(base, thisline);
+ if (smart_terminal)
+ screenhl[line] = hl;
/* zero fill the rest of it */
if (p - base < screen_width)
@@ -854,7 +868,7 @@
}
void
-u_process(int line, char *newline)
+u_process(int line, char *newline, int hl)
{
char *optr;
int screen_line = line + Header_lines;
@@ -887,7 +901,10 @@
}
/* now write the line */
- fputs(newline, stdout);
+ if (hl)
+ top_standout(newline);
+ else
+ fputs(newline, stdout);
/* copy it in to the buffer */
optr = stpcpy(bufferline, newline);
@@ -897,6 +914,24 @@
{
memset(optr, 0, screen_width - (optr - bufferline));
}
+ screenhl[line] = hl;
+ } else if (hl || screenhl[line] != hl) {
+ int oldlen;
+
+ /* line_update() cannot change or preserve standout attributes */
+ oldlen = strlen(bufferline);
+ Move_to(0, screen_line);
+ lastline = screen_line;
+ if (hl)
+ top_standout(newline);
+ else
+ fputs(newline, stdout);
+ if (len < oldlen)
+ (void)clear_eol(oldlen - len);
+ optr = stpcpy(bufferline, newline);
+ if (optr - bufferline < screen_width)
+ memset(optr, 0, screen_width - (optr - bufferline));
+ screenhl[line] = hl;
}
else
{
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -82,8 +82,8 @@
struct handle;
char *format_header(const char *uname_field);
-char *format_next_process(struct handle* handle, char *(*get_userid)(int),
- int flags);
+char *format_next_process(struct handle *handle, char *(*get_userid)(int),
+ int flags, pid_t *pid);
void toggle_pcpustats(void);
void get_system_info(struct system_info *si);
int machine_init(struct statics *statics);
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1042,7 +1042,8 @@
}
char *
-format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags)
+format_next_process(struct handle *xhandle, char *(*get_userid)(int), int flags,
+ pid_t *pid)
{
struct kinfo_proc *pp;
const struct kinfo_proc *oldp;
@@ -1067,6 +1068,8 @@
pp = *(xhandle->next_proc++);
xhandle->remaining--;
+ *pid = pp->ki_pid;
+
/* get the process's command name */
if ((pp->ki_flag & P_INMEM) == 0) {
/*
diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1
--- a/usr.bin/top/top.1
+++ b/usr.bin/top/top.1
@@ -318,6 +318,13 @@
to a list of processes.
This acts similarly to the command
.Xr kill 1 .
+.It Ic L
+Highlight a specific process.
+Prompt for
+.Ar PID
+or
+.Ql Ic +
+to clear highlighting.
.It Ic m
Toggle the display between 'cpu' and 'io' modes.
.It Ic n No or Ic #
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -69,6 +69,7 @@
/* miscellaneous things */
struct process_select ps;
pid_t mypid;
+static pid_t hlpid = (pid_t)-1;
/* pointers to display routines */
static void (*d_loadave)(int mpid, double *avenrun) = i_loadave;
@@ -80,7 +81,7 @@
static void (*d_swap)(int *stats) = i_swap;
static void (*d_message)(void) = i_message;
static void (*d_header)(const char *text) = i_header;
-static void (*d_process)(int line, char *thisline) = i_process;
+static void (*d_process)(int line, char *thisline, int hl) = i_process;
static void reset_display(void);
@@ -163,6 +164,25 @@
}
}
+static int
+filterpid(char buf[], int hl)
+{
+ unsigned long long num;
+ const char *errstr;
+
+ num = strtonum(buf, 0, INT_MAX, &errstr);
+ if (errstr != NULL || !find_pid(num))
+ return (-1);
+ if (hl) {
+ hlpid = (pid_t)num;
+ } else {
+ ps.pid = (pid_t)num;
+ ps.system = true;
+ }
+
+ return (0);
+}
+
static int
handle_user(char *buf, size_t buflen)
{
@@ -372,19 +392,12 @@
err(1, NULL);
break;
- case 'p': {
- unsigned long long num;
- const char *errstr;
-
- num = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL || !find_pid(num)) {
+ case 'p':
+ if (filterpid(optarg, false) == -1) {
fprintf(stderr, "%s: unknown pid\n", optarg);
exit(1);
}
- ps.pid = (pid_t)num;
- ps.system = true;
break;
- }
case 's':
{
@@ -667,8 +680,12 @@
/* now show the top "n" processes. */
for (i = 0; i < active_procs; i++)
{
- (*d_process)(i, format_next_process(processes, get_userid,
- fmt_flags));
+ char *line;
+ pid_t pid;
+
+ line = format_next_process(processes, get_userid,
+ fmt_flags, &pid);
+ (*d_process)(i, line, pid == hlpid);
}
}
else
@@ -922,6 +939,27 @@
clear_message();
break;
+ case CMD_hl: /* highlight PID */
+ new_message(MT_standout,
+ "Process ID to highlight: ");
+ if (readline(tempbuf1, sizeof(tempbuf1),
+ false) > 0) {
+ if (tempbuf1[0] == '+' &&
+ tempbuf1[1] == '\0') {
+ hlpid = (pid_t)-1;
+ } else if (filterpid(tempbuf1,
+ true) == -1) {
+ new_message(MT_standout,
+ " %s: unknown pid",
+ tempbuf1);
+ no_command = true;
+ }
+ if (!no_command)
+ clear_message();
+ } else
+ clear_message();
+ break;
+
case CMD_displays: /* change display count */
new_message(MT_standout,
"Displays to show (currently %s): ",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 15, 2:24 AM (21 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41732289
Default Alt Text
D61090.1794709480.diff (8 KB)
Attached To
Mode
D61090: top: implement pid highlighting
Attached
Detach File
Event Timeline