mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-16 22:06:06 +03:00
Compare commits
15 Commits
3.0.0beta4
...
3.0.0beta1
Author | SHA1 | Date | |
---|---|---|---|
44b6217a39 | |||
9bc6099180 | |||
36d5018c0c | |||
f8d6560d71 | |||
fb0b5926d2 | |||
3ed877f83f | |||
2efb5a4c55 | |||
23ce25898e | |||
4148717cb9 | |||
a6946f12a6 | |||
5ea24db29c | |||
42d50f1b9f | |||
5beff29a3d | |||
d1219abc55 | |||
673f098734 |
31
Action.c
31
Action.c
@ -115,7 +115,7 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
|
|||||||
|
|
||||||
static bool changePriority(MainPanel* panel, int delta) {
|
static bool changePriority(MainPanel* panel, int delta) {
|
||||||
bool anyTagged;
|
bool anyTagged;
|
||||||
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged);
|
bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
beep();
|
beep();
|
||||||
return anyTagged;
|
return anyTagged;
|
||||||
@ -155,21 +155,6 @@ static bool expandCollapse(Panel* panel) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool collapseIntoParent(Panel* panel) {
|
|
||||||
Process* p = (Process*) Panel_getSelected(panel);
|
|
||||||
if (!p) return false;
|
|
||||||
pid_t ppid = Process_getParentPid(p);
|
|
||||||
for (int i = 0; i < Panel_size(panel); i++) {
|
|
||||||
Process* q = (Process*) Panel_get(panel, i);
|
|
||||||
if (q->pid == ppid) {
|
|
||||||
q->showChildren = false;
|
|
||||||
Panel_setSelected(panel, i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
ScreenSettings* ss = settings->ss;
|
ScreenSettings* ss = settings->ss;
|
||||||
ss->sortKey = sortKey;
|
ss->sortKey = sortKey;
|
||||||
@ -202,7 +187,6 @@ static Htop_Reaction sortBy(State* st) {
|
|||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
static Htop_Reaction actionResize(State* st) {
|
static Htop_Reaction actionResize(State* st) {
|
||||||
clear();
|
|
||||||
Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
|
Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
|
||||||
return HTOP_REDRAW_BAR;
|
return HTOP_REDRAW_BAR;
|
||||||
}
|
}
|
||||||
@ -279,14 +263,6 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
|||||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
|
||||||
if (!st->settings->ss->treeView) {
|
|
||||||
return HTOP_OK;
|
|
||||||
}
|
|
||||||
bool changed = collapseIntoParent(st->panel);
|
|
||||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||||
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||||
}
|
}
|
||||||
@ -321,7 +297,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
|
|||||||
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
void* set = Action_pickFromVector(st, affinityPanel, 15);
|
||||||
if (set) {
|
if (set) {
|
||||||
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (Arg){ .v = affinity }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
|
||||||
if (!ok) beep();
|
if (!ok) beep();
|
||||||
Affinity_delete(affinity);
|
Affinity_delete(affinity);
|
||||||
}
|
}
|
||||||
@ -338,7 +314,7 @@ static Htop_Reaction actionKill(State* st) {
|
|||||||
Panel_setHeader(st->panel, "Sending...");
|
Panel_setHeader(st->panel, "Sending...");
|
||||||
Panel_draw(st->panel, true);
|
Panel_draw(st->panel, true);
|
||||||
refresh();
|
refresh();
|
||||||
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (Arg){ .i = sgn->key }, NULL);
|
MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
|
||||||
napms(500);
|
napms(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -593,7 +569,6 @@ void Action_setBindings(Htop_Action* keys) {
|
|||||||
keys['+'] = actionExpandOrCollapse;
|
keys['+'] = actionExpandOrCollapse;
|
||||||
keys['='] = actionExpandOrCollapse;
|
keys['='] = actionExpandOrCollapse;
|
||||||
keys['-'] = actionExpandOrCollapse;
|
keys['-'] = actionExpandOrCollapse;
|
||||||
keys['\177'] = actionCollapseIntoParent;
|
|
||||||
keys['u'] = actionFilterByUser;
|
keys['u'] = actionFilterByUser;
|
||||||
keys['F'] = Action_follow;
|
keys['F'] = Action_follow;
|
||||||
keys['S'] = actionSetup;
|
keys['S'] = actionSetup;
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
|
|
||||||
Contributing Guide
|
|
||||||
==================
|
|
||||||
|
|
||||||
Hello, and thank you so much for taking your time to contribute in any way to
|
|
||||||
htop! There are many ways to contribute, and I'll try to list them below. The
|
|
||||||
support from the free software community has been amazing over the years and
|
|
||||||
it is the number one thing that keeps me going, maintaining and improving
|
|
||||||
something that started as a tiny pet project back in 2004 and that nowadays is
|
|
||||||
a piece of software used all over the world, in both reality [and
|
|
||||||
fiction!](http://hisham.hm/htop/index.php?page=sightings). Cheers!
|
|
||||||
|
|
||||||
-- Hisham Muhammad
|
|
||||||
|
|
||||||
Bug Reports
|
|
||||||
-----------
|
|
||||||
|
|
||||||
Bug reports should be posted in the [Github issue
|
|
||||||
tracker](http://github.com/hishamhm/htop/issues). (I reply to them all, but I
|
|
||||||
usually do it in batches! :) ) Bug reports are extremely important since it's
|
|
||||||
impossible for me to test htop in every possible system, distribution and
|
|
||||||
scenario. Your feedback is what keeps the tool stable and always improving!
|
|
||||||
Thank you!
|
|
||||||
|
|
||||||
Pull Requests
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Code contributions are most welcome! Just [fork the
|
|
||||||
repo](http://github.com/hishamhm/htop) and send a [pull
|
|
||||||
request](https://github.com/hishamhm/htop/pulls). Help is especially
|
|
||||||
appreciated for support of platforms other than Linux. If proposing new
|
|
||||||
features, please be mindful that htop is a system tool that needs to keep a
|
|
||||||
small footprint and perform well on systems under stress -- so unfortunately I
|
|
||||||
can't accept every new feature proposed, as I need to keep the tool slim and
|
|
||||||
maintainable. Great ideas backed by a PR are always carefully considered for
|
|
||||||
inclusion, though! Also, PRs containing bug fixes and portability tweaks are a
|
|
||||||
no-brainer, please send those in!
|
|
||||||
|
|
||||||
Feature Requests
|
|
||||||
----------------
|
|
||||||
|
|
||||||
Back when htop was hosted in SourceForge, there used to be separate Bug
|
|
||||||
Tracker and Feature Request pages. These go all lumped together under "Issues"
|
|
||||||
in Github, which is a bit confusing. For this reason, I close Feature Requests
|
|
||||||
and file them with the [`feature
|
|
||||||
request`](https://github.com/hishamhm/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+)
|
|
||||||
label, where they remain accessible, but not mixed with actual bug reports.
|
|
||||||
This doesn't mean I'm dismissing or ignoring feature requests right away! It's
|
|
||||||
just an organizational issue (with Github, really!).
|
|
||||||
|
|
||||||
Donations
|
|
||||||
---------
|
|
||||||
|
|
||||||
If you like htop, feel free to [buy the author a
|
|
||||||
beer](http://hisham.hm/htop/index.php?page=donate). :-)
|
|
||||||
|
|
32
CRT.c
32
CRT.c
@ -37,7 +37,6 @@ in the source distribution for its full text.
|
|||||||
#define White COLOR_WHITE
|
#define White COLOR_WHITE
|
||||||
|
|
||||||
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||||
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
|
|
||||||
|
|
||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
@ -719,23 +718,22 @@ void CRT_enableDelay() {
|
|||||||
|
|
||||||
void CRT_setColors(int colorScheme) {
|
void CRT_setColors(int colorScheme) {
|
||||||
CRT_colorScheme = colorScheme;
|
CRT_colorScheme = colorScheme;
|
||||||
|
if (colorScheme == COLORSCHEME_BLACKNIGHT) {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++)
|
||||||
for (int j = 0; j < 8; j++) {
|
for (int j = 0; j < 8; j++) {
|
||||||
if (ColorIndex(i,j) != ColorPairGrayBlack) {
|
if (ColorIndex(i,j) != ColorIndex(Magenta,Magenta)) {
|
||||||
int bg = (colorScheme != COLORSCHEME_BLACKNIGHT)
|
init_pair(ColorIndex(i,j), i, j);
|
||||||
? (j==0 ? -1 : j)
|
}
|
||||||
: j;
|
|
||||||
init_pair(ColorIndex(i,j), i, bg);
|
|
||||||
}
|
}
|
||||||
}
|
init_pair(ColorIndex(Magenta,Magenta), 8, 0);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
if (ColorIndex(i,j) != ColorIndex(Magenta,Magenta)) {
|
||||||
|
init_pair(ColorIndex(i,j), i, (j==0?-1:j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
init_pair(ColorIndex(Magenta,Magenta), 8, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int grayBlackFg = COLORS > 8 ? 8 : 0;
|
|
||||||
int grayBlackBg = (colorScheme != COLORSCHEME_BLACKNIGHT)
|
|
||||||
? -1
|
|
||||||
: 0;
|
|
||||||
init_pair(ColorIndexGrayBlack, grayBlackFg, grayBlackBg);
|
|
||||||
|
|
||||||
CRT_colors = CRT_colorSchemes[colorScheme];
|
CRT_colors = CRT_colorSchemes[colorScheme];
|
||||||
}
|
}
|
||||||
|
1
CRT.h
1
CRT.h
@ -26,7 +26,6 @@ in the source distribution for its full text.
|
|||||||
#define White COLOR_WHITE
|
#define White COLOR_WHITE
|
||||||
|
|
||||||
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
|
||||||
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
|
|
||||||
|
|
||||||
#define KEY_WHEELUP KEY_F(20)
|
#define KEY_WHEELUP KEY_F(20)
|
||||||
#define KEY_WHEELDOWN KEY_F(21)
|
#define KEY_WHEELDOWN KEY_F(21)
|
||||||
|
48
ChangeLog
48
ChangeLog
@ -1,51 +1,3 @@
|
|||||||
What's new in version 2.1.1
|
|
||||||
|
|
||||||
* Check for pkg-config when building with --enable-delayacct
|
|
||||||
(thanks to @florian2833z for the report)
|
|
||||||
* Use CFLAGS from ncurses*-config if present
|
|
||||||
(thanks to Michael Klein)
|
|
||||||
* Fix build failure in Glibc 2.28
|
|
||||||
(thanks to Kang-Che Sung)
|
|
||||||
* BUGFIX: fix behavior of SYSCR column
|
|
||||||
(thanks to Marc Kleine-Budde)
|
|
||||||
* BUGFIX: preserve LDFLAGS when building
|
|
||||||
(thanks to Lance Frederickson for the report)
|
|
||||||
* BUGFIX: fix issue with small terminals
|
|
||||||
(thanks to Daniel Elf for the report)
|
|
||||||
* BUGFIX: fix crash with particular keycodes
|
|
||||||
(thanks to Wellington Torrejais da Silva for the report)
|
|
||||||
* BUGFIX: fix terminal color issues
|
|
||||||
(thanks to Kang-Che Sung for the report)
|
|
||||||
|
|
||||||
What's new in version 2.1.0
|
|
||||||
|
|
||||||
* Linux: Delay accounting metrics
|
|
||||||
(thanks to André Carvalho)
|
|
||||||
* DragonFlyBSD support
|
|
||||||
(thanks to Diederik de Groot)
|
|
||||||
* Support for real-time signals
|
|
||||||
(thanks to Kang-Che Sung)
|
|
||||||
* 'c' key now works with threads as well
|
|
||||||
* Session column renamed from SESN to SID
|
|
||||||
(thanks to Kamyar Rasta)
|
|
||||||
* Improved UI for meter style selection
|
|
||||||
(thanks to Kang-Che Sung)
|
|
||||||
* Improved code for constructing process tree
|
|
||||||
(thanks to wangqr)
|
|
||||||
* Compile-time option to disable setuid
|
|
||||||
* Error checking of various standard library operations
|
|
||||||
* Replacement of sprintf with snprintf
|
|
||||||
(thanks to Tomasz Kramkowski)
|
|
||||||
* Linux: performance improvements in battery meter
|
|
||||||
* Linux: update process TTY device
|
|
||||||
* Linux: add support for sorting TASK_IDLE
|
|
||||||
(thanks to Vladimir Panteleev)
|
|
||||||
* Linux: add upper-bound to running process counter
|
|
||||||
(thanks to Lucas Correia Villa Real)
|
|
||||||
* BUGFIX: avoid crash when battery is removed
|
|
||||||
(thanks to Jan Chren)
|
|
||||||
* BUGFIX: macOS: fix infinite loop in tree view
|
|
||||||
(thanks to Wataru Ashihara)
|
|
||||||
|
|
||||||
What's new in version 2.0.2
|
What's new in version 2.0.2
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
|
|||||||
this->settings->changed = true;
|
this->settings->changed = true;
|
||||||
const Header* header = this->scr->header;
|
const Header* header = this->scr->header;
|
||||||
CRT_setColors(mark);
|
CRT_setColors(mark);
|
||||||
clear();
|
|
||||||
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
|
||||||
Header_draw(header);
|
Header_draw(header);
|
||||||
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
|
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
|
||||||
|
@ -25,12 +25,7 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef union {
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||||
int i;
|
|
||||||
void* v;
|
|
||||||
} Arg;
|
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
|
|
||||||
@ -155,7 +150,7 @@ const char* MainPanel_getValue(MainPanel* this, int i) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) {
|
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) {
|
||||||
Panel* super = (Panel*) this;
|
Panel* super = (Panel*) this;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
bool anyTagged = false;
|
bool anyTagged = false;
|
||||||
|
@ -21,12 +21,7 @@ typedef struct MainPanel_ {
|
|||||||
pid_t pidSearch;
|
pid_t pidSearch;
|
||||||
} MainPanel;
|
} MainPanel;
|
||||||
|
|
||||||
typedef union {
|
typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
|
||||||
int i;
|
|
||||||
void* v;
|
|
||||||
} Arg;
|
|
||||||
|
|
||||||
typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg);
|
|
||||||
|
|
||||||
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
#define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar)
|
||||||
|
|
||||||
@ -39,7 +34,7 @@ int MainPanel_selectedPid(MainPanel* this);
|
|||||||
|
|
||||||
const char* MainPanel_getValue(MainPanel* this, int i);
|
const char* MainPanel_getValue(MainPanel* this, int i);
|
||||||
|
|
||||||
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged);
|
bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged);
|
||||||
|
|
||||||
extern PanelClass MainPanel_class;
|
extern PanelClass MainPanel_class;
|
||||||
|
|
||||||
|
136
Makefile.am
136
Makefile.am
@ -12,8 +12,8 @@ applications_DATA = htop.desktop
|
|||||||
pixmapdir = $(datadir)/pixmaps
|
pixmapdir = $(datadir)/pixmaps
|
||||||
pixmap_DATA = htop.png
|
pixmap_DATA = htop.png
|
||||||
|
|
||||||
AM_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||||
AM_LDFLAGS =
|
htop_LDFLAGS =
|
||||||
AM_CPPFLAGS = -DNDEBUG
|
AM_CPPFLAGS = -DNDEBUG
|
||||||
|
|
||||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||||
@ -36,164 +36,66 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
|||||||
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
||||||
EnvScreen.h InfoScreen.h XAlloc.h
|
EnvScreen.h InfoScreen.h XAlloc.h
|
||||||
|
|
||||||
all_platform_headers =
|
|
||||||
|
|
||||||
# Linux
|
|
||||||
# -----
|
|
||||||
|
|
||||||
linux_platform_headers = \
|
|
||||||
linux/Platform.h \
|
|
||||||
linux/IOPriorityPanel.h \
|
|
||||||
linux/IOPriority.h \
|
|
||||||
linux/LinuxProcess.h \
|
|
||||||
linux/LinuxProcessList.h \
|
|
||||||
linux/LinuxCRT.h \
|
|
||||||
linux/Battery.h \
|
|
||||||
linux/PerfCounter.h
|
|
||||||
|
|
||||||
all_platform_headers += $(linux_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_LINUX
|
if HTOP_LINUX
|
||||||
AM_CFLAGS += -rdynamic
|
htop_CFLAGS += -rdynamic
|
||||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
||||||
linux/PerfCounter.c
|
linux/PerfCounter.c
|
||||||
|
|
||||||
myhtopplatheaders = $(linux_platform_headers)
|
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
|
||||||
|
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h \
|
||||||
|
linux/PerfCounter.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# FreeBSD
|
|
||||||
# -------
|
|
||||||
|
|
||||||
freebsd_platform_headers = \
|
|
||||||
freebsd/Platform.h \
|
|
||||||
freebsd/FreeBSDProcessList.h \
|
|
||||||
freebsd/FreeBSDProcess.h \
|
|
||||||
freebsd/FreeBSDCRT.h \
|
|
||||||
freebsd/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(freebsd_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_FREEBSD
|
if HTOP_FREEBSD
|
||||||
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
||||||
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = $(freebsd_platform_headers)
|
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
||||||
|
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# DragonFlyBSD
|
|
||||||
# ------------
|
|
||||||
|
|
||||||
dragonflybsd_platform_headers = \
|
|
||||||
dragonflybsd/Platform.h \
|
|
||||||
dragonflybsd/DragonFlyBSDProcessList.h \
|
|
||||||
dragonflybsd/DragonFlyBSDProcess.h \
|
|
||||||
dragonflybsd/DragonFlyBSDCRT.h \
|
|
||||||
dragonflybsd/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(dragonflybsd_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_DRAGONFLYBSD
|
if HTOP_DRAGONFLYBSD
|
||||||
AM_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
htop_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||||
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
||||||
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = $(dragonflybsd_platform_headers)
|
myhtopplatheaders = dragonflybsd/Platform.h dragonflybsd/DragonFlyBSDProcessList.h \
|
||||||
|
dragonflybsd/DragonFlyBSDProcess.h dragonflybsd/DragonFlyBSDCRT.h dragonflybsd/Battery.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# OpenBSD
|
|
||||||
# -------
|
|
||||||
|
|
||||||
openbsd_platform_headers = \
|
|
||||||
openbsd/Platform.h \
|
|
||||||
openbsd/OpenBSDProcessList.h \
|
|
||||||
openbsd/OpenBSDProcess.h \
|
|
||||||
openbsd/OpenBSDCRT.h \
|
|
||||||
openbsd/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(openbsd_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_OPENBSD
|
if HTOP_OPENBSD
|
||||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = $(openbsd_platform_headers)
|
myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \
|
||||||
|
openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Darwin
|
|
||||||
# ------
|
|
||||||
|
|
||||||
darwin_platform_headers = \
|
|
||||||
darwin/Platform.h \
|
|
||||||
darwin/DarwinProcess.h \
|
|
||||||
darwin/DarwinProcessList.h \
|
|
||||||
darwin/DarwinCRT.h \
|
|
||||||
darwin/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(darwin_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_DARWIN
|
if HTOP_DARWIN
|
||||||
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
htop_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = $(darwin_platform_headers)
|
myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \
|
||||||
|
darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Solaris
|
|
||||||
# -------
|
|
||||||
|
|
||||||
solaris_platform_headers = \
|
|
||||||
solaris/Platform.h \
|
|
||||||
solaris/SolarisProcess.h \
|
|
||||||
solaris/SolarisProcessList.h \
|
|
||||||
solaris/SolarisCRT.h \
|
|
||||||
solaris/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(solaris_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_SOLARIS
|
|
||||||
myhtopplatsources = solaris/Platform.c \
|
|
||||||
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
|
||||||
solaris/SolarisCRT.c solaris/Battery.c
|
|
||||||
|
|
||||||
myhtopplatheaders = $(solaris_platform_headers)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Unsupported
|
|
||||||
# -----------
|
|
||||||
|
|
||||||
unsupported_platform_headers = \
|
|
||||||
unsupported/Platform.h \
|
|
||||||
unsupported/UnsupportedProcess.h \
|
|
||||||
unsupported/UnsupportedProcessList.h \
|
|
||||||
unsupported/UnsupportedCRT.h \
|
|
||||||
unsupported/Battery.h
|
|
||||||
|
|
||||||
all_platform_headers += $(unsupported_platform_headers)
|
|
||||||
|
|
||||||
if HTOP_UNSUPPORTED
|
if HTOP_UNSUPPORTED
|
||||||
myhtopplatsources = unsupported/Platform.c \
|
myhtopplatsources = unsupported/Platform.c \
|
||||||
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
||||||
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
||||||
|
|
||||||
myhtopplatheaders = $(unsupported_platform_headers)
|
myhtopplatheaders = unsupported/Platform.h \
|
||||||
|
unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
|
||||||
|
unsupported/UnsupportedCRT.h unsupported/Battery.h
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# ----
|
|
||||||
|
|
||||||
SUFFIXES = .h
|
SUFFIXES = .h
|
||||||
|
|
||||||
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
||||||
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
||||||
|
|
||||||
.PHONY: htop-headers clean-htop-headers
|
|
||||||
|
|
||||||
htop-headers: $(myhtopheaders) $(all_platform_headers)
|
|
||||||
|
|
||||||
clean-htop-headers:
|
|
||||||
-rm -f $(myhtopheaders) $(all_platform_headers)
|
|
||||||
|
|
||||||
target:
|
target:
|
||||||
echo $(htop_SOURCES)
|
echo $(htop_SOURCES)
|
||||||
|
|
||||||
|
8
Meter.c
8
Meter.c
@ -152,7 +152,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
|
|||||||
if (value / 1024 < powi)
|
if (value / 1024 < powi)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (prefix[1] == '\0')
|
if (prefix[1] == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
powi *= 1024;
|
powi *= 1024;
|
||||||
@ -287,7 +287,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
|
|
||||||
int blockSizes[10];
|
int blockSizes[10];
|
||||||
|
|
||||||
xSnprintf(bar, w + 1, "%*.*s", w, w, buffer);
|
xSnprintf(bar, w + 1, "%*s", w, buffer);
|
||||||
|
|
||||||
// First draw in the bar[] buffer...
|
// First draw in the bar[] buffer...
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -359,7 +359,7 @@ static int GraphMeterMode_pixPerRow;
|
|||||||
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||||
|
|
||||||
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
|
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
|
||||||
GraphData* data = (GraphData*) this->drawData;
|
GraphData* data = (GraphData*) this->drawData;
|
||||||
const int nValues = METER_BUFFER_LEN;
|
const int nValues = METER_BUFFER_LEN;
|
||||||
|
|
||||||
#ifdef HAVE_LIBNCURSESW
|
#ifdef HAVE_LIBNCURSESW
|
||||||
@ -404,7 +404,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
|||||||
k = -i/2;
|
k = -i/2;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
for (; i < nValues - 1; i+=2, k++) {
|
for (; i < nValues; i+=2, k++) {
|
||||||
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
|
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
|
||||||
int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
|
int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix);
|
||||||
int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix);
|
int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix);
|
||||||
|
@ -76,35 +76,16 @@ void OpenFilesScreen_draw(InfoScreen* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||||
char buffer[1025];
|
char command[1025];
|
||||||
xSnprintf(buffer, 1024, "%d", pid);
|
xSnprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
||||||
|
FILE* fd = popen(command, "r");
|
||||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||||
OpenFiles_FileData* fdata = NULL;
|
OpenFiles_FileData* fdata = NULL;
|
||||||
OpenFiles_Data* item = &(pdata->data);
|
OpenFiles_Data* item = &(pdata->data);
|
||||||
int fdpair[2];
|
if (!fd) {
|
||||||
if (pipe(fdpair) == -1) {
|
pdata->error = 127;
|
||||||
pdata->error = 1;
|
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
pid_t child = fork();
|
|
||||||
if (child == -1) {
|
|
||||||
pdata->error = 1;
|
|
||||||
return pdata;
|
|
||||||
}
|
|
||||||
if (child == 0) {
|
|
||||||
close(fdpair[0]);
|
|
||||||
dup2(fdpair[1], STDOUT_FILENO);
|
|
||||||
close(fdpair[1]);
|
|
||||||
int fdnull = open("/dev/null", O_WRONLY);
|
|
||||||
if (fdnull < 0)
|
|
||||||
exit(1);
|
|
||||||
dup2(fdnull, STDERR_FILENO);
|
|
||||||
close(fdnull);
|
|
||||||
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
|
|
||||||
exit(127);
|
|
||||||
}
|
|
||||||
close(fdpair[1]);
|
|
||||||
FILE* fd = fdopen(fdpair[0], "r");
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* line = String_readLine(fd);
|
char* line = String_readLine(fd);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
@ -124,15 +105,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
|||||||
item->data[cmd] = xStrdup(line + 1);
|
item->data[cmd] = xStrdup(line + 1);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
int wstatus;
|
pdata->error = pclose(fd);
|
||||||
if (waitpid(child, &wstatus, 0) == -1) {
|
|
||||||
pdata->error = 1;
|
|
||||||
return pdata;
|
|
||||||
}
|
|
||||||
if (!WIFEXITED(wstatus))
|
|
||||||
pdata->error = 1;
|
|
||||||
else
|
|
||||||
pdata->error = WEXITSTATUS(wstatus);
|
|
||||||
return pdata;
|
return pdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +130,7 @@ void OpenFilesScreen_scan(InfoScreen* this) {
|
|||||||
char** data = fdata->data.data;
|
char** data = fdata->data.data;
|
||||||
int lenN = data['n'] ? strlen(data['n']) : 0;
|
int lenN = data['n'] ? strlen(data['n']) : 0;
|
||||||
int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
|
int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/;
|
||||||
char entry[sizeEntry];
|
char* entry = xMalloc(sizeEntry);
|
||||||
xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s",
|
||||||
data['f'] ? data['f'] : "",
|
data['f'] ? data['f'] : "",
|
||||||
data['t'] ? data['t'] : "",
|
data['t'] ? data['t'] : "",
|
||||||
|
2
Panel.c
2
Panel.c
@ -477,7 +477,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
|
|||||||
this->eventHandlerState = xCalloc(100, sizeof(char));
|
this->eventHandlerState = xCalloc(100, sizeof(char));
|
||||||
char* buffer = this->eventHandlerState;
|
char* buffer = this->eventHandlerState;
|
||||||
|
|
||||||
if (ch > 0 && ch < 255 && isalnum(ch)) {
|
if (ch < 255 && isalnum(ch)) {
|
||||||
int len = strlen(buffer);
|
int len = strlen(buffer);
|
||||||
if (len < 99) {
|
if (len < 99) {
|
||||||
buffer[len] = ch;
|
buffer[len] = ch;
|
||||||
|
18
Process.c
18
Process.c
@ -28,12 +28,7 @@ in the source distribution for its full text.
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#ifdef MAJOR_IN_MKDEV
|
#include <inttypes.h>
|
||||||
#include <sys/mkdev.h>
|
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#include <sys/sysmacros.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
@ -51,7 +46,6 @@ in the source distribution for its full text.
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
@ -179,12 +173,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
|
||||||
|
|
||||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
static int Process_getuid = -1;
|
static int Process_getuid = -1;
|
||||||
@ -545,11 +535,11 @@ bool Process_setPriority(Process* this, int priority) {
|
|||||||
return (err == 0);
|
return (err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, int delta) {
|
bool Process_changePriorityBy(Process* this, size_t delta) {
|
||||||
return Process_setPriority(this, this->nice + delta);
|
return Process_setPriority(this, this->nice + delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int sgn) {
|
void Process_sendSignal(Process* this, size_t sgn) {
|
||||||
CRT_dropPrivileges();
|
CRT_dropPrivileges();
|
||||||
kill(this->pid, (int) sgn);
|
kill(this->pid, (int) sgn);
|
||||||
CRT_restorePrivileges();
|
CRT_restorePrivileges();
|
||||||
@ -610,7 +600,7 @@ long Process_compare(const void* v1, const void* v2) {
|
|||||||
return (p1->starttime_ctime - p2->starttime_ctime);
|
return (p1->starttime_ctime - p2->starttime_ctime);
|
||||||
}
|
}
|
||||||
case STATE:
|
case STATE:
|
||||||
return (Process_sortState(p1->state) - Process_sortState(p2->state));
|
return (p1->state - p2->state);
|
||||||
case ST_UID:
|
case ST_UID:
|
||||||
return (p1->st_uid - p2->st_uid);
|
return (p1->st_uid - p2->st_uid);
|
||||||
case TIME:
|
case TIME:
|
||||||
|
14
Process.h
14
Process.h
@ -9,11 +9,6 @@ Released under the GNU GPL, see the COPYING file
|
|||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef MAJOR_IN_MKDEV
|
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
#define SYS_ioprio_set __NR_ioprio_set
|
#define SYS_ioprio_set __NR_ioprio_set
|
||||||
@ -29,7 +24,6 @@ in the source distribution for its full text.
|
|||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#define PROCESS_FLAG_IO 0x0001
|
#define PROCESS_FLAG_IO 0x0001
|
||||||
|
|
||||||
@ -157,12 +151,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||||
|
|
||||||
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
|
||||||
|
|
||||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||||
|
|
||||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
|
||||||
|
|
||||||
|
|
||||||
#define ONE_K 1024L
|
#define ONE_K 1024L
|
||||||
#define ONE_M (ONE_K * ONE_K)
|
#define ONE_M (ONE_K * ONE_K)
|
||||||
@ -200,9 +190,9 @@ void Process_toggleTag(Process* this);
|
|||||||
|
|
||||||
bool Process_setPriority(Process* this, int priority);
|
bool Process_setPriority(Process* this, int priority);
|
||||||
|
|
||||||
bool Process_changePriorityBy(Process* this, int delta);
|
bool Process_changePriorityBy(Process* this, size_t delta);
|
||||||
|
|
||||||
void Process_sendSignal(Process* this, int sgn);
|
void Process_sendSignal(Process* this, size_t sgn);
|
||||||
|
|
||||||
long Process_pidCompare(const void* v1, const void* v2);
|
long Process_pidCompare(const void* v1, const void* v2);
|
||||||
|
|
||||||
|
@ -229,14 +229,9 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pid_t ppid = Process_getParentPid(process);
|
pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid;
|
||||||
// Bisect the process vector to find parent
|
// Bisect the process vector to find parent
|
||||||
int l = 0, r = size;
|
int l = 0, r = size;
|
||||||
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
|
||||||
// on Mac OS X 10.11.6) cancel bisecting and regard this process as
|
|
||||||
// root.
|
|
||||||
if (process->pid == ppid)
|
|
||||||
r = 0;
|
|
||||||
while (l < r) {
|
while (l < r) {
|
||||||
int c = (l + r) / 2;
|
int c = (l + r) / 2;
|
||||||
pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid;
|
pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid;
|
||||||
|
@ -63,10 +63,6 @@ typedef struct RichString_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifndef CLAMP
|
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define charBytes(n) (sizeof(CharType) * (n))
|
#define charBytes(n) (sizeof(CharType) * (n))
|
||||||
|
|
||||||
static void RichString_extendLen(RichString* this, int len) {
|
static void RichString_extendLen(RichString* this, int len) {
|
||||||
@ -107,7 +103,6 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
|
|||||||
|
|
||||||
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
||||||
cchar_t* ch = this->chptr + start;
|
cchar_t* ch = this->chptr + start;
|
||||||
finish = CLAMP(finish, 0, this->chlen - 1);
|
|
||||||
for (int i = start; i <= finish; i++) {
|
for (int i = start; i <= finish; i++) {
|
||||||
ch->attr = attrs;
|
ch->attr = attrs;
|
||||||
ch++;
|
ch++;
|
||||||
@ -137,7 +132,6 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
|
|||||||
|
|
||||||
void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
|
||||||
chtype* ch = this->chptr + start;
|
chtype* ch = this->chptr + start;
|
||||||
finish = CLAMP(finish, 0, this->chlen - 1);
|
|
||||||
for (int i = start; i <= finish; i++) {
|
for (int i = start; i <= finish; i++) {
|
||||||
*ch = (*ch & 0xff) | attrs;
|
*ch = (*ch & 0xff) | attrs;
|
||||||
ch++;
|
ch++;
|
||||||
|
@ -59,10 +59,6 @@ typedef struct RichString_ {
|
|||||||
} RichString;
|
} RichString;
|
||||||
|
|
||||||
|
|
||||||
#ifndef CLAMP
|
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define charBytes(n) (sizeof(CharType) * (n))
|
#define charBytes(n) (sizeof(CharType) * (n))
|
||||||
|
|
||||||
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
|
#define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0)
|
||||||
|
71
Settings.c
71
Settings.c
@ -23,12 +23,6 @@ in the source distribution for its full text.
|
|||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* name;
|
|
||||||
const char* columns;
|
|
||||||
const char* sortKey;
|
|
||||||
} ScreenDefaults;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char** names;
|
char** names;
|
||||||
@ -272,11 +266,14 @@ ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char*
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Settings_defaultScreens(Settings* this) {
|
static void Settings_defaultScreens(Settings* this) {
|
||||||
for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) {
|
Settings_newScreen(this, "Default", "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command");
|
||||||
ScreenDefaults* defaults = &Platform_defaultScreens[i];
|
this->screens[0]->sortKey = toFieldIndex("PERCENT_CPU");
|
||||||
Settings_newScreen(this, defaults->name, defaults->columns);
|
Settings_newScreen(this, "I/O", "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command");
|
||||||
this->screens[0]->sortKey = toFieldIndex(defaults->sortKey);
|
this->screens[1]->sortKey = toFieldIndex("IO_RATE");
|
||||||
}
|
Settings_newScreen(this, "Perf Counters", "PID USER PERCENT_CPU PROCESSOR MCYCLE MINSTR IPC PERCENT_MISS PERCENT_BMISS Command");
|
||||||
|
this->screens[2]->sortKey = toFieldIndex("MCYCLE");
|
||||||
|
Settings_newScreen(this, "L1 Data Cache", "PID USER PERCENT_CPU L1DREADS L1DRMISSES L1DWRITES L1DWMISSES Command");
|
||||||
|
this->screens[3]->sortKey = toFieldIndex("L1DREADS");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Settings_read(Settings* this, const char* fileName) {
|
static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
@ -288,8 +285,7 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
if (!fd)
|
if (!fd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool didReadMeters = false;
|
bool readMeters = false;
|
||||||
bool didReadFields = false;
|
|
||||||
ProcessField* legacyFields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
ProcessField* legacyFields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField));
|
||||||
int legacyFlags;
|
int legacyFlags;
|
||||||
bool legacyFieldsRead = false;
|
bool legacyFieldsRead = false;
|
||||||
@ -346,16 +342,16 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
||||||
} else if (String_eq(option[0], "left_meters")) {
|
} else if (String_eq(option[0], "left_meters")) {
|
||||||
Settings_readMeters(this, option[1], 0);
|
Settings_readMeters(this, option[1], 0);
|
||||||
didReadMeters = true;
|
readMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meters")) {
|
} else if (String_eq(option[0], "right_meters")) {
|
||||||
Settings_readMeters(this, option[1], 1);
|
Settings_readMeters(this, option[1], 1);
|
||||||
didReadMeters = true;
|
readMeters = true;
|
||||||
} else if (String_eq(option[0], "left_meter_modes")) {
|
} else if (String_eq(option[0], "left_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 0);
|
Settings_readMeterModes(this, option[1], 0);
|
||||||
didReadMeters = true;
|
readMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 1);
|
Settings_readMeterModes(this, option[1], 1);
|
||||||
didReadMeters = true;
|
readMeters = true;
|
||||||
} else if (strncmp(option[0], "screen:", 7) == 0) {
|
} else if (strncmp(option[0], "screen:", 7) == 0) {
|
||||||
Settings_newScreen(this, option[0] + 7, option[1]);
|
Settings_newScreen(this, option[0] + 7, option[1]);
|
||||||
} else if (String_eq(option[0], ".tree_view")) {
|
} else if (String_eq(option[0], ".tree_view")) {
|
||||||
@ -382,10 +378,10 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
|||||||
this->screens[0]->flags = legacyFlags;
|
this->screens[0]->flags = legacyFlags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!didReadMeters) {
|
if (!readMeters) {
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultMeters(this);
|
||||||
}
|
}
|
||||||
return didReadFields;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeFields(FILE* fd, ProcessField* fields, bool byName) {
|
static void writeFields(FILE* fd, ProcessField* fields, bool byName) {
|
||||||
@ -517,8 +513,10 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
free(htopDir);
|
free(htopDir);
|
||||||
free(configDir);
|
free(configDir);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int err = lstat(legacyDotfile, &st);
|
if (lstat(legacyDotfile, &st) != 0) {
|
||||||
if (err || S_ISLNK(st.st_mode)) {
|
st.st_mode = 0;
|
||||||
|
}
|
||||||
|
if (access(legacyDotfile, R_OK) != 0 || S_ISLNK(st.st_mode)) {
|
||||||
free(legacyDotfile);
|
free(legacyDotfile);
|
||||||
legacyDotfile = NULL;
|
legacyDotfile = NULL;
|
||||||
}
|
}
|
||||||
@ -527,38 +525,33 @@ Settings* Settings_new(int cpuCount) {
|
|||||||
this->colorScheme = 0;
|
this->colorScheme = 0;
|
||||||
this->changed = false;
|
this->changed = false;
|
||||||
this->delay = DEFAULT_DELAY;
|
this->delay = DEFAULT_DELAY;
|
||||||
bool ok = false;
|
bool ok = Settings_read(this, legacyDotfile ? legacyDotfile : this->filename);
|
||||||
if (legacyDotfile) {
|
if (ok) {
|
||||||
ok = Settings_read(this, legacyDotfile);
|
if (legacyDotfile) {
|
||||||
if (ok) {
|
|
||||||
// Transition to new location and delete old configuration file
|
// Transition to new location and delete old configuration file
|
||||||
if (Settings_write(this))
|
if (Settings_write(this))
|
||||||
unlink(legacyDotfile);
|
unlink(legacyDotfile);
|
||||||
}
|
}
|
||||||
free(legacyDotfile);
|
} else {
|
||||||
}
|
|
||||||
if (!ok) {
|
|
||||||
ok = Settings_read(this, this->filename);
|
|
||||||
}
|
|
||||||
if (!ok) {
|
|
||||||
this->changed = true;
|
this->changed = true;
|
||||||
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
||||||
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
||||||
ok = Settings_read(this, systemSettings);
|
ok = Settings_read(this, systemSettings);
|
||||||
free(systemSettings);
|
free(systemSettings);
|
||||||
}
|
if (!ok) {
|
||||||
if (!ok) {
|
Settings_defaultMeters(this);
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultScreens(this);
|
||||||
Settings_defaultScreens(this);
|
this->hideKernelThreads = true;
|
||||||
this->hideKernelThreads = true;
|
this->highlightMegabytes = true;
|
||||||
this->highlightMegabytes = true;
|
this->highlightThreads = true;
|
||||||
this->highlightThreads = true;
|
this->headerMargin = true;
|
||||||
this->headerMargin = true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ssIndex = 0;
|
this->ssIndex = 0;
|
||||||
this->ss = this->screens[this->ssIndex];
|
this->ss = this->screens[this->ssIndex];
|
||||||
|
|
||||||
|
free(legacyDotfile);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,17 +9,10 @@ Released under the GNU GPL, see the COPYING file
|
|||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEFAULT_DELAY 15
|
|
||||||
|
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char* name;
|
|
||||||
const char* columns;
|
|
||||||
const char* sortKey;
|
|
||||||
} ScreenDefaults;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char** names;
|
char** names;
|
||||||
|
@ -41,10 +41,10 @@ Panel* SignalsPanel_new() {
|
|||||||
}
|
}
|
||||||
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
||||||
if (SIGRTMAX - SIGRTMIN <= 100) {
|
if (SIGRTMAX - SIGRTMIN <= 100) {
|
||||||
static char buf[16];
|
static char buf[15];
|
||||||
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
||||||
int n = sig - SIGRTMIN;
|
int n = sig - SIGRTMIN;
|
||||||
xSnprintf(buf, 16, "%2d SIGRTMIN%-+3d", sig, n);
|
xSnprintf(buf, 15, "%2d SIGRTMIN%-+3d", sig, n);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
buf[11] = '\0';
|
buf[11] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
char* String_cat(const char* s1, const char* s2) {
|
char* String_cat(const char* s1, const char* s2) {
|
||||||
size_t l1 = strlen(s1);
|
int l1 = strlen(s1);
|
||||||
size_t l2 = strlen(s2);
|
int l2 = strlen(s2);
|
||||||
char* out = xMalloc(l1 + l2 + 1);
|
char* out = xMalloc(l1 + l2 + 1);
|
||||||
strncpy(out, s1, l1);
|
strncpy(out, s1, l1);
|
||||||
strncpy(out + l1, s2, l2 + 1);
|
strncpy(out+l1, s2, l2+1);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ char* String_trim(const char* in) {
|
|||||||
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
|
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
|
||||||
in++;
|
in++;
|
||||||
}
|
}
|
||||||
size_t len = strlen(in);
|
int len = strlen(in);
|
||||||
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ char** String_split(const char* s, char sep, int* n) {
|
|||||||
s += size + 1;
|
s += size + 1;
|
||||||
}
|
}
|
||||||
if (s[0] != '\0') {
|
if (s[0] != '\0') {
|
||||||
size_t size = strlen(s);
|
int size = strlen(s);
|
||||||
char* token = xMalloc(size + 1);
|
char* token = xMalloc(size + 1);
|
||||||
strncpy(token, s, size + 1);
|
strncpy(token, s, size + 1);
|
||||||
out[ctr] = token;
|
out[ctr] = token;
|
||||||
|
@ -101,15 +101,14 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
|
|||||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||||
if (ok != -1) {
|
if (ok != -1) {
|
||||||
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
||||||
execlp("strace", "strace", "-s", "512", "-p", buffer, NULL);
|
execlp("strace", "strace", "-p", buffer, NULL);
|
||||||
}
|
}
|
||||||
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
||||||
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
||||||
(void) written;
|
(void) written;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int ok = fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK);
|
||||||
if (ok == -1) return false;
|
|
||||||
this->strace = fdopen(this->fdpair[0], "r");
|
this->strace = fdopen(this->fdpair[0], "r");
|
||||||
this->fd_strace = fileno(this->strace);
|
this->fd_strace = fileno(this->strace);
|
||||||
return true;
|
return true;
|
||||||
|
8
Vector.c
8
Vector.c
@ -284,19 +284,11 @@ inline Object* Vector_get(Vector* this, int idx) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
|
|
||||||
inline int Vector_size(Vector* this) {
|
inline int Vector_size(Vector* this) {
|
||||||
assert(Vector_isConsistent(this));
|
assert(Vector_isConsistent(this));
|
||||||
return this->items;
|
return this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define Vector_size(v_) ((v_)->items)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
static void Vector_merge(Vector* this, Vector* v2) {
|
static void Vector_merge(Vector* this, Vector* v2) {
|
||||||
|
8
Vector.h
8
Vector.h
@ -70,16 +70,8 @@ extern Object* Vector_get(Vector* this, int idx);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
|
|
||||||
extern int Vector_size(Vector* this);
|
extern int Vector_size(Vector* this);
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define Vector_size(v_) ((v_)->items)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
47
configure.ac
47
configure.ac
@ -2,7 +2,7 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ(2.65)
|
AC_PREREQ(2.65)
|
||||||
AC_INIT([htop],[3.0.0beta4],[hisham@gobolinux.org])
|
AC_INIT([htop],[2.0.2],[hisham@gobolinux.org])
|
||||||
|
|
||||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
||||||
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
||||||
@ -43,9 +43,6 @@ dragonfly*)
|
|||||||
darwin*)
|
darwin*)
|
||||||
my_htop_platform=darwin
|
my_htop_platform=darwin
|
||||||
;;
|
;;
|
||||||
solaris*)
|
|
||||||
my_htop_platform=solaris
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
my_htop_platform=unsupported
|
my_htop_platform=unsupported
|
||||||
;;
|
;;
|
||||||
@ -64,16 +61,6 @@ AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h],[
|
|||||||
])
|
])
|
||||||
AC_CHECK_HEADERS([execinfo.h],[:],[:])
|
AC_CHECK_HEADERS([execinfo.h],[:],[:])
|
||||||
|
|
||||||
AC_HEADER_MAJOR
|
|
||||||
dnl glibc 2.25 deprecates 'major' and 'minor' in <sys/types.h> and requires to
|
|
||||||
dnl include <sys/sysmacros.h>. However the logic in AC_HEADER_MAJOR has not yet
|
|
||||||
dnl been updated in Autoconf 2.69, so use a workaround:
|
|
||||||
m4_version_prereq([2.70], [],
|
|
||||||
[if test "x$ac_cv_header_sys_mkdev_h" = xno; then
|
|
||||||
AC_CHECK_HEADER(sys/sysmacros.h, [AC_DEFINE(MAJOR_IN_SYSMACROS, 1,
|
|
||||||
[Define to 1 if `major', `minor', and `makedev' are declared in <sys/sysmacros.h>.])])
|
|
||||||
fi])
|
|
||||||
|
|
||||||
# Checks for typedefs, structures, and compiler characteristics.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AC_HEADER_STDBOOL
|
AC_HEADER_STDBOOL
|
||||||
@ -167,26 +154,20 @@ m4_define([HTOP_CHECK_SCRIPT],
|
|||||||
[
|
[
|
||||||
if test ! -z "m4_toupper($HTOP_[$1]_CONFIG_SCRIPT)"; then
|
if test ! -z "m4_toupper($HTOP_[$1]_CONFIG_SCRIPT)"; then
|
||||||
# to be used to set the path to ncurses*-config when cross-compiling
|
# to be used to set the path to ncurses*-config when cross-compiling
|
||||||
htop_config_script_libs=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --libs 2> /dev/null)
|
htop_config_script=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --libs 2> /dev/null)
|
||||||
htop_config_script_cflags=$(m4_toupper($HTOP_[$1]_CONFIG_SCRIPT) --cflags 2> /dev/null)
|
|
||||||
else
|
else
|
||||||
htop_config_script_libs=$([$4] --libs 2> /dev/null)
|
htop_config_script=$([$4] --libs 2> /dev/null)
|
||||||
htop_config_script_cflags=$([$4] --cflags 2> /dev/null)
|
|
||||||
fi
|
fi
|
||||||
htop_script_success=no
|
htop_script_success=no
|
||||||
htop_save_LDFLAGS="$LDFLAGS"
|
htop_save_LDFLAGS="$LDFLAGS"
|
||||||
htop_save_CFLAGS="$CFLAGS"
|
if test ! "x$htop_config_script" = x; then
|
||||||
if test ! "x$htop_config_script_libs" = x; then
|
LDFLAGS="$htop_config_script $LDFLAGS"
|
||||||
LDFLAGS="$htop_config_script_libs $LDFLAGS"
|
|
||||||
CFLAGS="$htop_config_script_cflags $CFLAGS"
|
|
||||||
AC_CHECK_LIB([$1], [$2], [
|
AC_CHECK_LIB([$1], [$2], [
|
||||||
AC_DEFINE([$3], 1, [The library is present.])
|
AC_DEFINE([$3], 1, [The library is present.])
|
||||||
LIBS="$htop_config_script_libs $LIBS "
|
LIBS="$htop_config_script $LIBS "
|
||||||
htop_script_success=yes
|
htop_script_success=yes
|
||||||
], [
|
], [])
|
||||||
CFLAGS="$htop_save_CFLAGS"
|
LDFLAGS="$save_LDFLAGS"
|
||||||
])
|
|
||||||
LDFLAGS="$htop_save_LDFLAGS"
|
|
||||||
fi
|
fi
|
||||||
if test "x$htop_script_success" = xno; then
|
if test "x$htop_script_success" = xno; then
|
||||||
[$5]
|
[$5]
|
||||||
@ -241,12 +222,6 @@ if test "$my_htop_platform" = "openbsd"; then
|
|||||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$my_htop_platform" = "solaris"; then
|
|
||||||
AC_CHECK_LIB([kstat], [kstat_open], [], [missing_libraries="$missing_libraries libkstat"])
|
|
||||||
AC_CHECK_LIB([proc], [Pgrab_error], [], [missing_libraries="$missing_libraries libproc"])
|
|
||||||
AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||||
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||||
AC_MSG_CHECKING([for usable sched_setaffinity])
|
AC_MSG_CHECKING([for usable sched_setaffinity])
|
||||||
@ -330,11 +305,10 @@ fi
|
|||||||
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable linux delay accounting])],, enable_delayacct="no")
|
AC_ARG_ENABLE(delayacct, [AS_HELP_STRING([--enable-delayacct], [enable linux delay accounting])],, enable_delayacct="no")
|
||||||
if test "x$enable_delayacct" = xyes
|
if test "x$enable_delayacct" = xyes
|
||||||
then
|
then
|
||||||
PKG_PROG_PKG_CONFIG()
|
|
||||||
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [missing_libraries="$missing_libraries libnl-3"])
|
||||||
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
PKG_CHECK_MODULES(LIBNL3GENL, libnl-genl-3.0, [], [missing_libraries="$missing_libraries libnl-genl-3"])
|
||||||
CFLAGS="$CFLAGS $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
CFLAGS+=" $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
||||||
LIBS="$LIBS $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
LIBS+=" $LIBNL3_LIBS $LIBNL3GENL_LIBS"
|
||||||
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
AC_DEFINE(HAVE_DELAYACCT, 1, [Define if delay accounting support should be enabled.])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -357,7 +331,6 @@ AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
|||||||
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
||||||
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
||||||
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
||||||
AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
|
|
||||||
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
||||||
AC_SUBST(my_htop_platform)
|
AC_SUBST(my_htop_platform)
|
||||||
AC_CONFIG_FILES([Makefile htop.1])
|
AC_CONFIG_FILES([Makefile htop.1])
|
||||||
|
@ -18,8 +18,6 @@ in the source distribution for its full text.
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
@ -40,51 +38,19 @@ typedef struct DarwinProcessList_ {
|
|||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
typedef struct kern {
|
|
||||||
short int version[3];
|
|
||||||
} kern_;
|
|
||||||
|
|
||||||
static void getKernelVersion(struct kern *k) {
|
|
||||||
static short int version_[3] = {0};
|
|
||||||
if (!version_[0]) {
|
|
||||||
// just in case it fails someday
|
|
||||||
version_[0] = version_[1] = version_[2] = -1;
|
|
||||||
char str[256] = {0};
|
|
||||||
size_t size = sizeof(str);
|
|
||||||
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
|
|
||||||
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
|
|
||||||
}
|
|
||||||
memcpy(k->version, version_, sizeof(version_));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int compareKernelVersion(short int major, short int minor, short int component) {
|
|
||||||
/*
|
|
||||||
compare the given os version with the one installed returns:
|
|
||||||
0 if equals the installed version
|
|
||||||
positive value if less than the installed version
|
|
||||||
negative value if more than the installed version
|
|
||||||
*/
|
|
||||||
struct kern k;
|
|
||||||
getKernelVersion(&k);
|
|
||||||
if ( k.version[0] != major) return k.version[0] - major;
|
|
||||||
if ( k.version[1] != minor) return k.version[1] - minor;
|
|
||||||
if ( k.version[2] != component) return k.version[2] - component;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||||
CRT_fatalError("Unable to retrieve host info\n");
|
CRT_fatalError("Unable to retrieve host info\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
if (NULL != p && NULL != *p) {
|
if(NULL != p && NULL != *p) {
|
||||||
if (0 != munmap(*p, vm_page_size)) {
|
if(0 != munmap(*p, vm_page_size)) {
|
||||||
CRT_fatalError("Unable to free old CPU load information\n");
|
CRT_fatalError("Unable to free old CPU load information\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
@ -95,7 +61,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
|||||||
unsigned cpu_count;
|
unsigned cpu_count;
|
||||||
|
|
||||||
// TODO Improving the accuracy of the load counts woule help a lot.
|
// TODO Improving the accuracy of the load counts woule help a lot.
|
||||||
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||||
CRT_fatalError("Unable to retrieve CPU info\n");
|
CRT_fatalError("Unable to retrieve CPU info\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +69,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_getVMStats(vm_statistics_t p) {
|
void ProcessList_getVMStats(vm_statistics_t p) {
|
||||||
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
||||||
|
|
||||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
||||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||||
@ -161,65 +127,60 @@ void ProcessList_delete(ProcessList* this) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||||
bool preExisting = true;
|
bool preExisting = true;
|
||||||
struct kinfo_proc *ps;
|
struct kinfo_proc *ps;
|
||||||
size_t count;
|
size_t count;
|
||||||
DarwinProcess *proc;
|
DarwinProcess *proc;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL); /* Start processing time */
|
gettimeofday(&tv, NULL); /* Start processing time */
|
||||||
|
|
||||||
/* Update the global data (CPU times and VM stats) */
|
/* Update the global data (CPU times and VM stats) */
|
||||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||||
dpl->prev_load = dpl->curr_load;
|
dpl->prev_load = dpl->curr_load;
|
||||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||||
ProcessList_getVMStats(&dpl->vm_stats);
|
ProcessList_getVMStats(&dpl->vm_stats);
|
||||||
|
|
||||||
/* Get the time difference */
|
/* Get the time difference */
|
||||||
dpl->global_diff = 0;
|
dpl->global_diff = 0;
|
||||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the thread counts */
|
/* Clear the thread counts */
|
||||||
super->kernelThreads = 0;
|
super->kernelThreads = 0;
|
||||||
super->userlandThreads = 0;
|
super->userlandThreads = 0;
|
||||||
super->totalTasks = 0;
|
super->totalTasks = 0;
|
||||||
super->runningTasks = 0;
|
super->runningTasks = 0;
|
||||||
|
|
||||||
/* We use kinfo_procs for initial data since :
|
/* We use kinfo_procs for initial data since :
|
||||||
*
|
*
|
||||||
* 1) They always succeed.
|
* 1) They always succeed.
|
||||||
* 2) The contain the basic information.
|
* 2) The contain the basic information.
|
||||||
*
|
*
|
||||||
* We attempt to fill-in additional information with libproc.
|
* We attempt to fill-in additional information with libproc.
|
||||||
*/
|
*/
|
||||||
ps = ProcessList_getKInfoProcs(&count);
|
ps = ProcessList_getKInfoProcs(&count);
|
||||||
|
|
||||||
for(size_t i = 0; i < count; ++i) {
|
for(size_t i = 0; i < count; ++i) {
|
||||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||||
|
|
||||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||||
|
|
||||||
|
DarwinProcess_scanThreads(proc);
|
||||||
|
|
||||||
// Disabled for High Sierra due to bug in macOS High Sierra
|
super->totalTasks += 1;
|
||||||
bool isScanThreadSupported = ! ( compareKernelVersion(17, 0, 0) >= 0 && compareKernelVersion(17, 5, 0) < 0);
|
|
||||||
|
|
||||||
if (isScanThreadSupported){
|
if(!preExisting) {
|
||||||
DarwinProcess_scanThreads(proc);
|
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||||
}
|
|
||||||
|
|
||||||
super->totalTasks += 1;
|
ProcessList_add(super, &proc->super);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!preExisting) {
|
free(ps);
|
||||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
|
||||||
|
|
||||||
ProcessList_add(super, &proc->super);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(ps);
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ typedef struct DarwinProcessList_ {
|
|||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||||
|
|
||||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
||||||
|
@ -25,26 +25,13 @@ in the source distribution for its full text.
|
|||||||
#include "CPUMeter.h"
|
#include "CPUMeter.h"
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
|
|
||||||
typedef enum DarwinProcessFields {
|
|
||||||
LAST_PROCESSFIELD = 100,
|
|
||||||
} DarwinProcessField;
|
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
const SignalItem Platform_signals[] = {
|
const SignalItem Platform_signals[] = {
|
||||||
{ .name = " 0 Cancel", .number = 0 },
|
{ .name = " 0 Cancel", .number = 0 },
|
||||||
@ -110,7 +97,7 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
MeterClass* Platform_meterTypes[] = {
|
MeterClass* Platform_meterTypes[] = {
|
||||||
|
@ -16,18 +16,11 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "DarwinProcess.h"
|
#include "DarwinProcess.h"
|
||||||
|
|
||||||
typedef enum DarwinProcessFields {
|
|
||||||
LAST_PROCESSFIELD = 100,
|
|
||||||
} DarwinProcessField;
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
|
@ -40,15 +40,7 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
@ -39,16 +39,6 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
@ -20,10 +20,6 @@ extern ProcessFieldData Process_fields[];
|
|||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern ProcessField Platform_defaultFields[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
@ -49,11 +49,11 @@ The following commands are supported while in htop:
|
|||||||
.LP
|
.LP
|
||||||
.TP 5
|
.TP 5
|
||||||
.B Up, Alt-k
|
.B Up, Alt-k
|
||||||
Select (highlight) the previous process in the process list. Scroll the list
|
Select (hightlight) the previous process in the process list. Scroll the list
|
||||||
if necessary.
|
if necessary.
|
||||||
.TP
|
.TP
|
||||||
.B Down, Alt-j
|
.B Down, Alt-j
|
||||||
Select (highlight) the next process in the process list. Scroll the list if
|
Select (hightlight) the next process in the process list. Scroll the list if
|
||||||
necessary.
|
necessary.
|
||||||
.TP
|
.TP
|
||||||
.B Left, Alt-h
|
.B Left, Alt-h
|
||||||
|
11
htop.c
11
htop.c
@ -42,7 +42,6 @@ static void printHelpFlag() {
|
|||||||
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
||||||
"-h --help Print this help screen\n"
|
"-h --help Print this help screen\n"
|
||||||
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
||||||
"-t --tree Show the tree view by default\n"
|
|
||||||
"-u --user=USERNAME Show only processes of a given user\n"
|
"-u --user=USERNAME Show only processes of a given user\n"
|
||||||
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
||||||
"-v --version Print version info\n"
|
"-v --version Print version info\n"
|
||||||
@ -62,7 +61,6 @@ typedef struct CommandLineSettings_ {
|
|||||||
int sortKey;
|
int sortKey;
|
||||||
int delay;
|
int delay;
|
||||||
bool useColors;
|
bool useColors;
|
||||||
bool treeView;
|
|
||||||
} CommandLineSettings;
|
} CommandLineSettings;
|
||||||
|
|
||||||
static CommandLineSettings parseArguments(int argc, char** argv) {
|
static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||||
@ -73,7 +71,6 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
.sortKey = 0,
|
.sortKey = 0,
|
||||||
.delay = -1,
|
.delay = -1,
|
||||||
.useColors = true,
|
.useColors = true,
|
||||||
.treeView = false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option long_opts[] =
|
static struct option long_opts[] =
|
||||||
@ -85,7 +82,6 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
{"user", required_argument, 0, 'u'},
|
{"user", required_argument, 0, 'u'},
|
||||||
{"no-color", no_argument, 0, 'C'},
|
{"no-color", no_argument, 0, 'C'},
|
||||||
{"no-colour",no_argument, 0, 'C'},
|
{"no-colour",no_argument, 0, 'C'},
|
||||||
{"tree", no_argument, 0, 't'},
|
|
||||||
{"pid", required_argument, 0, 'p'},
|
{"pid", required_argument, 0, 'p'},
|
||||||
{"io", no_argument, 0, 'i'},
|
{"io", no_argument, 0, 'i'},
|
||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
@ -93,7 +89,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
|
|
||||||
int opt, opti=0;
|
int opt, opti=0;
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((opt = getopt_long(argc, argv, "hvCst::d:u:p:i", long_opts, &opti))) {
|
while ((opt = getopt_long(argc, argv, "hvCs:d:u:p:i", long_opts, &opti))) {
|
||||||
if (opt == EOF) break;
|
if (opt == EOF) break;
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -131,9 +127,6 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
|||||||
case 'C':
|
case 'C':
|
||||||
flags.useColors = false;
|
flags.useColors = false;
|
||||||
break;
|
break;
|
||||||
case 't':
|
|
||||||
flags.treeView = true;
|
|
||||||
break;
|
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char* argCopy = xStrdup(optarg);
|
char* argCopy = xStrdup(optarg);
|
||||||
char* saveptr;
|
char* saveptr;
|
||||||
@ -204,8 +197,6 @@ int main(int argc, char** argv) {
|
|||||||
settings->delay = flags.delay;
|
settings->delay = flags.delay;
|
||||||
if (!flags.useColors)
|
if (!flags.useColors)
|
||||||
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
||||||
if (flags.treeView)
|
|
||||||
settings->screens[0]->treeView = true;
|
|
||||||
|
|
||||||
CRT_init(settings->delay, settings->colorScheme);
|
CRT_init(settings->delay, settings->colorScheme);
|
||||||
|
|
||||||
|
@ -72,8 +72,6 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
|
|||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
if (!line) break;
|
|
||||||
|
|
||||||
char *foundNumStr = String_getToken(line, wordNum);
|
char *foundNumStr = String_getToken(line, wordNum);
|
||||||
const unsigned long int foundNum = atoi(foundNumStr);
|
const unsigned long int foundNum = atoi(foundNumStr);
|
||||||
free(foundNumStr);
|
free(foundNumStr);
|
||||||
@ -110,14 +108,17 @@ static ACPresence procAcpiCheck() {
|
|||||||
char statePath[50];
|
char statePath[50];
|
||||||
xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
|
xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
|
||||||
FILE* file = fopen(statePath, "r");
|
FILE* file = fopen(statePath, "r");
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
isOn = AC_ERROR;
|
isOn = AC_ERROR;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* line = String_readLine(file);
|
char* line = String_readLine(file);
|
||||||
fclose(file);
|
|
||||||
if (!line) continue;
|
if (!line) continue;
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
const char *isOnline = String_getToken(line, 2);
|
const char *isOnline = String_getToken(line, 2);
|
||||||
free(line);
|
free(line);
|
||||||
|
|
||||||
|
@ -117,7 +117,6 @@ typedef enum LinuxProcessFields {
|
|||||||
|
|
||||||
typedef struct LinuxProcess_ {
|
typedef struct LinuxProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
bool isKernelThread;
|
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
unsigned long int cminflt;
|
unsigned long int cminflt;
|
||||||
unsigned long int cmajflt;
|
unsigned long int cmajflt;
|
||||||
@ -186,7 +185,7 @@ typedef struct LinuxProcess_ {
|
|||||||
} LinuxProcess;
|
} LinuxProcess;
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
#ifndef Process_isKernelThread
|
||||||
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
#ifndef Process_isUserlandThread
|
||||||
@ -199,7 +198,7 @@ ProcessFieldData Process_fields[] = {
|
|||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||||
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging, I idle)", .flags = 0, },
|
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
|
||||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||||
|
@ -109,7 +109,6 @@ typedef enum LinuxProcessFields {
|
|||||||
|
|
||||||
typedef struct LinuxProcess_ {
|
typedef struct LinuxProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
bool isKernelThread;
|
|
||||||
IOPriority ioPriority;
|
IOPriority ioPriority;
|
||||||
unsigned long int cminflt;
|
unsigned long int cminflt;
|
||||||
unsigned long int cmajflt;
|
unsigned long int cmajflt;
|
||||||
@ -178,7 +177,7 @@ typedef struct LinuxProcess_ {
|
|||||||
} LinuxProcess;
|
} LinuxProcess;
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
#ifndef Process_isKernelThread
|
||||||
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
#ifndef Process_isUserlandThread
|
||||||
|
@ -26,12 +26,6 @@ in the source distribution for its full text.
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#ifdef MAJOR_IN_MKDEV
|
|
||||||
#include <sys/mkdev.h>
|
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#include <sys/sysmacros.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
#include <netlink/attr.h>
|
#include <netlink/attr.h>
|
||||||
@ -442,7 +436,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (line[4] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) {
|
if (line[5] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) {
|
||||||
process->io_syscr = strtoull(line+7, NULL, 10);
|
process->io_syscr = strtoull(line+7, NULL, 10);
|
||||||
} else if (strncmp(line+1, "yscw: ", 6) == 0) {
|
} else if (strncmp(line+1, "yscw: ", 6) == 0) {
|
||||||
process->io_syscw = strtoull(line+7, NULL, 10);
|
process->io_syscw = strtoull(line+7, NULL, 10);
|
||||||
@ -601,36 +595,36 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn
|
|||||||
|
|
||||||
static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) {
|
static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) {
|
||||||
struct nlmsghdr *nlhdr;
|
struct nlmsghdr *nlhdr;
|
||||||
struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1];
|
struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1];
|
||||||
struct nlattr *nlattr;
|
struct nlattr *nlattr;
|
||||||
struct taskstats *stats;
|
struct taskstats *stats;
|
||||||
int rem;
|
int rem;
|
||||||
unsigned long long int timeDelta;
|
unsigned long long int timeDelta;
|
||||||
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
||||||
|
|
||||||
nlhdr = nlmsg_hdr(nlmsg);
|
nlhdr = nlmsg_hdr(nlmsg);
|
||||||
|
|
||||||
if (genlmsg_parse(nlhdr, 0, nlattrs, TASKSTATS_TYPE_MAX, NULL) < 0) {
|
if (genlmsg_parse(nlhdr, 0, nlattrs, TASKSTATS_TYPE_MAX, NULL) < 0) {
|
||||||
return NL_SKIP;
|
return NL_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) {
|
if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) {
|
||||||
stats = nla_data(nla_next(nla_data(nlattr), &rem));
|
stats = nla_data(nla_next(nla_data(nlattr), &rem));
|
||||||
assert(lp->super.pid == stats->ac_pid);
|
assert(lp->super.pid == stats->ac_pid);
|
||||||
timeDelta = (stats->ac_etime*1000 - lp->delay_read_time);
|
timeDelta = (stats->ac_etime*1000 - lp->delay_read_time);
|
||||||
#define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x;
|
#define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x;
|
||||||
#define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100);
|
#define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100);
|
||||||
lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total);
|
lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total);
|
||||||
lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total);
|
lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total);
|
||||||
lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total);
|
lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total);
|
||||||
#undef DELTAPERC
|
#undef DELTAPERC
|
||||||
#undef BOUNDS
|
#undef BOUNDS
|
||||||
lp->swapin_delay_total = stats->swapin_delay_total;
|
lp->swapin_delay_total = stats->swapin_delay_total;
|
||||||
lp->blkio_delay_total = stats->blkio_delay_total;
|
lp->blkio_delay_total = stats->blkio_delay_total;
|
||||||
lp->cpu_delay_total = stats->cpu_delay_total;
|
lp->cpu_delay_total = stats->cpu_delay_total;
|
||||||
lp->delay_read_time = stats->ac_etime*1000;
|
lp->delay_read_time = stats->ac_etime*1000;
|
||||||
}
|
}
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) {
|
static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) {
|
||||||
@ -748,6 +742,9 @@ static void setCommand(Process* process, const char* command, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
||||||
|
if (Process_isKernelThread(process))
|
||||||
|
return true;
|
||||||
|
|
||||||
char filename[MAX_NAME+1];
|
char filename[MAX_NAME+1];
|
||||||
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = open(filename, O_RDONLY);
|
||||||
@ -759,10 +756,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
|||||||
close(fd);
|
close(fd);
|
||||||
int tokenEnd = 0;
|
int tokenEnd = 0;
|
||||||
int lastChar = 0;
|
int lastChar = 0;
|
||||||
if (amtRead == 0) {
|
if (amtRead <= 0) {
|
||||||
((LinuxProcess*)process)->isKernelThread = true;
|
|
||||||
return true;
|
|
||||||
} else if (amtRead < 0) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < amtRead; i++) {
|
for (int i = 0; i < amtRead; i++) {
|
||||||
|
@ -9,11 +9,6 @@ Released under the GNU GPL, see the COPYING file
|
|||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef MAJOR_IN_MKDEV
|
|
||||||
#elif defined(MAJOR_IN_SYSMACROS) || \
|
|
||||||
(defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_DELAYACCT
|
#ifdef HAVE_DELAYACCT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is based on tiptop.
|
|
||||||
* by Erven ROHOU
|
|
||||||
* Copyright (c) 2011, 2012, 2014 Inria
|
|
||||||
* License: GNU General Public License version 2.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "PerfCounter.h"
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "XAlloc.h"
|
|
||||||
|
|
||||||
/*{
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <asm/unistd.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
// The sys_perf_counter_open syscall and header files changed names
|
|
||||||
// between Linux 2.6.31 and 2.6.32. Do the mangling here.
|
|
||||||
#ifdef HAVE_LINUX_PERF_COUNTER_H
|
|
||||||
#include <linux/perf_counter.h>
|
|
||||||
#define STRUCT_NAME perf_counter_attr
|
|
||||||
#define SYSCALL_NUM __NR_perf_counter_open
|
|
||||||
|
|
||||||
#elif HAVE_LINUX_PERF_EVENT_H
|
|
||||||
#include <linux/perf_event.h>
|
|
||||||
#define STRUCT_NAME perf_event_attr
|
|
||||||
#define SYSCALL_NUM __NR_perf_event_open
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Sorry, performance counters not supported on this system.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct PerfCounter_ {
|
|
||||||
struct STRUCT_NAME events;
|
|
||||||
pid_t pid;
|
|
||||||
int fd;
|
|
||||||
uint64_t prevValue;
|
|
||||||
uint64_t value;
|
|
||||||
} PerfCounter;
|
|
||||||
|
|
||||||
#define PerfCounter_delta(pc_) ((pc_)->value - (pc_)->prevValue)
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int PerfCounter_openFds = 0;
|
|
||||||
static int PerfCounter_fdLimit = -1;
|
|
||||||
|
|
||||||
static void PerfCounter_initFdLimit() {
|
|
||||||
char name[100] = { 0 }; /* needs to fit the name /proc/xxxx/limits */
|
|
||||||
snprintf(name, sizeof(name) - 1, "/proc/%d/limits", getpid());
|
|
||||||
FILE* f = fopen(name, "r");
|
|
||||||
if (f) {
|
|
||||||
char line[100];
|
|
||||||
while (fgets(line, 100, f)) {
|
|
||||||
int n = sscanf(line, "Max open files %d", &PerfCounter_fdLimit);
|
|
||||||
if (n) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
PerfCounter_fdLimit -= 20; /* keep some slack */
|
|
||||||
if (PerfCounter_fdLimit == 0) { /* something went wrong */
|
|
||||||
PerfCounter_fdLimit = 200; /* reasonable default? */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static long perf_event_open(struct STRUCT_NAME *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags) {
|
|
||||||
int ret = syscall(SYSCALL_NUM, hw_event, pid, cpu, group_fd, flags);
|
|
||||||
#if defined(__x86_64__) || defined(__i386__)
|
|
||||||
if (ret < 0 && ret > -4096) {
|
|
||||||
errno = -ret;
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
PerfCounter* PerfCounter_new(pid_t pid, uint32_t type, uint64_t config) {
|
|
||||||
if (PerfCounter_fdLimit == -1) {
|
|
||||||
PerfCounter_initFdLimit();
|
|
||||||
}
|
|
||||||
PerfCounter* this = xCalloc(sizeof(PerfCounter), 1);
|
|
||||||
this->pid = pid;
|
|
||||||
this->events.disabled = 0;
|
|
||||||
this->events.pinned = 1;
|
|
||||||
this->events.exclude_hv = 1;
|
|
||||||
this->events.exclude_kernel = 1;
|
|
||||||
this->events.type = type;
|
|
||||||
this->events.config = config;
|
|
||||||
if (PerfCounter_openFds < PerfCounter_fdLimit) {
|
|
||||||
this->fd = perf_event_open(&this->events, pid, -1, -1, 0);
|
|
||||||
} else {
|
|
||||||
this->fd = -1;
|
|
||||||
}
|
|
||||||
if (this->fd != -1) {
|
|
||||||
PerfCounter_openFds++;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PerfCounter_delete(PerfCounter* this) {
|
|
||||||
if (!this) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this->fd != -1) {
|
|
||||||
PerfCounter_openFds--;
|
|
||||||
}
|
|
||||||
close(this->fd);
|
|
||||||
free(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PerfCounter_read(PerfCounter* this) {
|
|
||||||
if (this->fd == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
uint64_t value;
|
|
||||||
int r = read(this->fd, &value, sizeof(value));
|
|
||||||
if (r != sizeof(value)) {
|
|
||||||
close(this->fd);
|
|
||||||
this->fd = perf_event_open(&this->events, this->pid, -1, -1, 0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this->prevValue = this->value;
|
|
||||||
this->value = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_PerfCounter
|
|
||||||
#define HEADER_PerfCounter
|
|
||||||
/*
|
|
||||||
* This file is based on tiptop.
|
|
||||||
* by Erven ROHOU
|
|
||||||
* Copyright (c) 2011, 2012, 2014 Inria
|
|
||||||
* License: GNU General Public License version 2.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <asm/unistd.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
// The sys_perf_counter_open syscall and header files changed names
|
|
||||||
// between Linux 2.6.31 and 2.6.32. Do the mangling here.
|
|
||||||
#ifdef HAVE_LINUX_PERF_COUNTER_H
|
|
||||||
#include <linux/perf_counter.h>
|
|
||||||
#define STRUCT_NAME perf_counter_attr
|
|
||||||
#define SYSCALL_NUM __NR_perf_counter_open
|
|
||||||
|
|
||||||
#elif HAVE_LINUX_PERF_EVENT_H
|
|
||||||
#include <linux/perf_event.h>
|
|
||||||
#define STRUCT_NAME perf_event_attr
|
|
||||||
#define SYSCALL_NUM __NR_perf_event_open
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Sorry, performance counters not supported on this system.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct PerfCounter_ {
|
|
||||||
struct STRUCT_NAME events;
|
|
||||||
pid_t pid;
|
|
||||||
int fd;
|
|
||||||
uint64_t prevValue;
|
|
||||||
uint64_t value;
|
|
||||||
} PerfCounter;
|
|
||||||
|
|
||||||
#define PerfCounter_delta(pc_) ((pc_)->value - (pc_)->prevValue)
|
|
||||||
|
|
||||||
|
|
||||||
extern int PerfCounter_openFds;
|
|
||||||
PerfCounter* PerfCounter_new(pid_t pid, uint32_t type, uint64_t config);
|
|
||||||
|
|
||||||
void PerfCounter_delete(PerfCounter* this);
|
|
||||||
|
|
||||||
bool PerfCounter_read(PerfCounter* this);
|
|
||||||
|
|
||||||
#endif
|
|
@ -36,13 +36,16 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
#include "Settings.h"
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
|
|
||||||
|
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
const SignalItem Platform_signals[] = {
|
const SignalItem Platform_signals[] = {
|
||||||
@ -82,31 +85,6 @@ const SignalItem Platform_signals[] = {
|
|||||||
{ .name = "31 SIGSYS", .number = 31 },
|
{ .name = "31 SIGSYS", .number = 31 },
|
||||||
};
|
};
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "I/O",
|
|
||||||
.columns = "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command",
|
|
||||||
.sortKey = "IO_RATE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Perf Counters",
|
|
||||||
.columns = "PID USER PERCENT_CPU PROCESSOR MCYCLE MINSTR IPC PERCENT_MISS PERCENT_BMISS Command",
|
|
||||||
.sortKey = "MCYCLE",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "L1 Data Cache",
|
|
||||||
.columns = "PID USER PERCENT_CPU L1DREADS L1DRMISSES L1DWRITES L1DWMISSES Command",
|
|
||||||
.sortKey = "LD1READS",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||||
@ -119,7 +97,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
|||||||
void* set = Action_pickFromVector(st, ioprioPanel, 21);
|
void* set = Action_pickFromVector(st, ioprioPanel, 21);
|
||||||
if (set) {
|
if (set) {
|
||||||
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||||
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL);
|
bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
@ -14,20 +14,17 @@ in the source distribution for its full text.
|
|||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include "LinuxProcess.h"
|
#include "LinuxProcess.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
#include "Settings.h"
|
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
extern const SignalItem Platform_signals[];
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfSignals;
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
void Platform_setBindings(Htop_Action* keys);
|
void Platform_setBindings(Htop_Action* keys);
|
||||||
|
@ -7,65 +7,10 @@ in the source distribution for its full text.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BatteryMeter.h"
|
#include "BatteryMeter.h"
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <sys/sensors.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
|
|
||||||
for (int devn = 0;; devn++) {
|
|
||||||
mib[2] = devn;
|
|
||||||
if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) {
|
|
||||||
if (errno == ENXIO)
|
|
||||||
continue;
|
|
||||||
if (errno == ENOENT)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(name, snsrdev->xname) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||||
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
// TODO
|
||||||
struct sensor s;
|
|
||||||
size_t slen = sizeof(struct sensor);
|
|
||||||
struct sensordev snsrdev;
|
|
||||||
size_t sdlen = sizeof(struct sensordev);
|
|
||||||
|
|
||||||
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
|
||||||
|
|
||||||
*level = -1;
|
*level = -1;
|
||||||
if (found) {
|
|
||||||
/* last full capacity */
|
|
||||||
mib[3] = 7;
|
|
||||||
mib[4] = 0;
|
|
||||||
double last_full_capacity = 0;
|
|
||||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
|
||||||
last_full_capacity = s.value;
|
|
||||||
}
|
|
||||||
if (last_full_capacity > 0) {
|
|
||||||
/* remaining capacity */
|
|
||||||
mib[3] = 7;
|
|
||||||
mib[4] = 3;
|
|
||||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
|
||||||
double charge = s.value;
|
|
||||||
*level = 100*(charge / last_full_capacity);
|
|
||||||
if (charge >= last_full_capacity) {
|
|
||||||
*level = 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
|
|
||||||
|
|
||||||
*isOnAC = AC_ERROR;
|
*isOnAC = AC_ERROR;
|
||||||
if (found) {
|
|
||||||
mib[3] = 9;
|
|
||||||
mib[4] = 0;
|
|
||||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
|
||||||
*isOnAC = s.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,4 +12,5 @@ in the source distribution for its full text.
|
|||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -92,15 +92,7 @@ static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_
|
|||||||
return (total_change);
|
return (total_change);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ extern ProcessFieldData Process_fields[];
|
|||||||
* The routine assumes modulo arithmetic. This function is especially
|
* The routine assumes modulo arithmetic. This function is especially
|
||||||
* useful on BSD machines for calculating cpu state percentages.
|
* useful on BSD machines for calculating cpu state percentages.
|
||||||
*/
|
*/
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
#include "BatteryMeter.h"
|
|
||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
|
||||||
*level = -1;
|
|
||||||
*isOnAC = AC_ERROR;
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_Battery
|
|
||||||
#define HEADER_Battery
|
|
||||||
|
|
||||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,265 +0,0 @@
|
|||||||
/*
|
|
||||||
htop - solaris/Platform.c
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2015 David C. Hunt
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "Meter.h"
|
|
||||||
#include "CPUMeter.h"
|
|
||||||
#include "MemoryMeter.h"
|
|
||||||
#include "SwapMeter.h"
|
|
||||||
#include "TasksMeter.h"
|
|
||||||
#include "LoadAverageMeter.h"
|
|
||||||
#include "ClockMeter.h"
|
|
||||||
#include "HostnameMeter.h"
|
|
||||||
#include "UptimeMeter.h"
|
|
||||||
#include "SolarisProcess.h"
|
|
||||||
#include "SolarisProcessList.h"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <utmpx.h>
|
|
||||||
#include <sys/loadavg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <kstat.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <sys/var.h>
|
|
||||||
|
|
||||||
/*{
|
|
||||||
#include "Action.h"
|
|
||||||
#include "BatteryMeter.h"
|
|
||||||
#include "SignalsPanel.h"
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/mkdev.h>
|
|
||||||
#include <sys/proc.h>
|
|
||||||
#include <libproc.h>
|
|
||||||
|
|
||||||
#define kill(pid, signal) kill(pid / 1024, signal)
|
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
|
||||||
typedef struct var kvar_t;
|
|
||||||
|
|
||||||
typedef struct envAccum_ {
|
|
||||||
size_t capacity;
|
|
||||||
size_t size;
|
|
||||||
size_t bytes;
|
|
||||||
char *env;
|
|
||||||
} envAccum;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
double plat_loadavg[3] = {0};
|
|
||||||
|
|
||||||
const SignalItem Platform_signals[] = {
|
|
||||||
{ .name = " 0 Cancel", .number = 0 },
|
|
||||||
{ .name = " 1 SIGHUP", .number = 1 },
|
|
||||||
{ .name = " 2 SIGINT", .number = 2 },
|
|
||||||
{ .name = " 3 SIGQUIT", .number = 3 },
|
|
||||||
{ .name = " 4 SIGILL", .number = 4 },
|
|
||||||
{ .name = " 5 SIGTRAP", .number = 5 },
|
|
||||||
{ .name = " 6 SIGABRT/IOT", .number = 6 },
|
|
||||||
{ .name = " 7 SIGEMT", .number = 7 },
|
|
||||||
{ .name = " 8 SIGFPE", .number = 8 },
|
|
||||||
{ .name = " 9 SIGKILL", .number = 9 },
|
|
||||||
{ .name = "10 SIGBUS", .number = 10 },
|
|
||||||
{ .name = "11 SIGSEGV", .number = 11 },
|
|
||||||
{ .name = "12 SIGSYS", .number = 12 },
|
|
||||||
{ .name = "13 SIGPIPE", .number = 13 },
|
|
||||||
{ .name = "14 SIGALRM", .number = 14 },
|
|
||||||
{ .name = "15 SIGTERM", .number = 15 },
|
|
||||||
{ .name = "16 SIGUSR1", .number = 16 },
|
|
||||||
{ .name = "17 SIGUSR2", .number = 17 },
|
|
||||||
{ .name = "18 SIGCHLD/CLD", .number = 18 },
|
|
||||||
{ .name = "19 SIGPWR", .number = 19 },
|
|
||||||
{ .name = "20 SIGWINCH", .number = 20 },
|
|
||||||
{ .name = "21 SIGURG", .number = 21 },
|
|
||||||
{ .name = "22 SIGPOLL/IO", .number = 22 },
|
|
||||||
{ .name = "23 SIGSTOP", .number = 23 },
|
|
||||||
{ .name = "24 SIGTSTP", .number = 24 },
|
|
||||||
{ .name = "25 SIGCONT", .number = 25 },
|
|
||||||
{ .name = "26 SIGTTIN", .number = 26 },
|
|
||||||
{ .name = "27 SIGTTOU", .number = 27 },
|
|
||||||
{ .name = "28 SIGVTALRM", .number = 28 },
|
|
||||||
{ .name = "29 SIGPROF", .number = 29 },
|
|
||||||
{ .name = "30 SIGXCPU", .number = 30 },
|
|
||||||
{ .name = "31 SIGXFSZ", .number = 31 },
|
|
||||||
{ .name = "32 SIGWAITING", .number = 32 },
|
|
||||||
{ .name = "33 SIGLWP", .number = 33 },
|
|
||||||
{ .name = "34 SIGFREEZE", .number = 34 },
|
|
||||||
{ .name = "35 SIGTHAW", .number = 35 },
|
|
||||||
{ .name = "36 SIGCANCEL", .number = 36 },
|
|
||||||
{ .name = "37 SIGLOST", .number = 37 },
|
|
||||||
{ .name = "38 SIGXRES", .number = 38 },
|
|
||||||
{ .name = "39 SIGJVM1", .number = 39 },
|
|
||||||
{ .name = "40 SIGJVM2", .number = 40 },
|
|
||||||
{ .name = "41 SIGINFO", .number = 41 },
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
MeterClass* Platform_meterTypes[] = {
|
|
||||||
&CPUMeter_class,
|
|
||||||
&ClockMeter_class,
|
|
||||||
&LoadAverageMeter_class,
|
|
||||||
&LoadMeter_class,
|
|
||||||
&MemoryMeter_class,
|
|
||||||
&SwapMeter_class,
|
|
||||||
&TasksMeter_class,
|
|
||||||
&BatteryMeter_class,
|
|
||||||
&HostnameMeter_class,
|
|
||||||
&UptimeMeter_class,
|
|
||||||
&AllCPUsMeter_class,
|
|
||||||
&AllCPUs2Meter_class,
|
|
||||||
&LeftCPUsMeter_class,
|
|
||||||
&RightCPUsMeter_class,
|
|
||||||
&LeftCPUs2Meter_class,
|
|
||||||
&RightCPUs2Meter_class,
|
|
||||||
&BlankMeter_class,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
void Platform_setBindings(Htop_Action* keys) {
|
|
||||||
(void) keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
|
||||||
|
|
||||||
extern char Process_pidFormat[20];
|
|
||||||
|
|
||||||
int Platform_getUptime() {
|
|
||||||
int boot_time = 0;
|
|
||||||
int curr_time = time(NULL);
|
|
||||||
struct utmpx * ent;
|
|
||||||
|
|
||||||
while (( ent = getutxent() )) {
|
|
||||||
if ( !strcmp("system boot", ent->ut_line )) {
|
|
||||||
boot_time = ent->ut_tv.tv_sec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endutxent();
|
|
||||||
|
|
||||||
return (curr_time-boot_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
|
||||||
getloadavg( plat_loadavg, 3 );
|
|
||||||
*one = plat_loadavg[LOADAVG_1MIN];
|
|
||||||
*five = plat_loadavg[LOADAVG_5MIN];
|
|
||||||
*fifteen = plat_loadavg[LOADAVG_15MIN];
|
|
||||||
}
|
|
||||||
|
|
||||||
int Platform_getMaxPid() {
|
|
||||||
kstat_ctl_t *kc = NULL;
|
|
||||||
kstat_t *kshandle = NULL;
|
|
||||||
kvar_t *ksvar = NULL;
|
|
||||||
int vproc = 32778; // Reasonable Solaris default
|
|
||||||
kc = kstat_open();
|
|
||||||
if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); }
|
|
||||||
if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); }
|
|
||||||
ksvar = kshandle->ks_data;
|
|
||||||
if (ksvar->v_proc > 0 ) {
|
|
||||||
vproc = ksvar->v_proc;
|
|
||||||
}
|
|
||||||
if (kc != NULL) { kstat_close(kc); }
|
|
||||||
return vproc;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* this, int cpu) {
|
|
||||||
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
|
|
||||||
int cpus = this->pl->cpuCount;
|
|
||||||
CPUData* cpuData = NULL;
|
|
||||||
|
|
||||||
if (cpus == 1) {
|
|
||||||
// single CPU box has everything in spl->cpus[0]
|
|
||||||
cpuData = &(spl->cpus[0]);
|
|
||||||
} else {
|
|
||||||
cpuData = &(spl->cpus[cpu]);
|
|
||||||
}
|
|
||||||
|
|
||||||
double percent;
|
|
||||||
double* v = this->values;
|
|
||||||
|
|
||||||
v[CPU_METER_NICE] = cpuData->nicePercent;
|
|
||||||
v[CPU_METER_NORMAL] = cpuData->userPercent;
|
|
||||||
if (this->pl->settings->detailedCPUTime) {
|
|
||||||
v[CPU_METER_KERNEL] = cpuData->systemPercent;
|
|
||||||
v[CPU_METER_IRQ] = cpuData->irqPercent;
|
|
||||||
Meter_setItems(this, 4);
|
|
||||||
percent = v[0]+v[1]+v[2]+v[3];
|
|
||||||
} else {
|
|
||||||
v[2] = cpuData->systemAllPercent;
|
|
||||||
Meter_setItems(this, 3);
|
|
||||||
percent = v[0]+v[1]+v[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
percent = CLAMP(percent, 0.0, 100.0);
|
|
||||||
if (isnan(percent)) percent = 0.0;
|
|
||||||
return percent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* this) {
|
|
||||||
ProcessList* pl = (ProcessList*) this->pl;
|
|
||||||
this->total = pl->totalMem;
|
|
||||||
this->values[0] = pl->usedMem;
|
|
||||||
this->values[1] = pl->buffersMem;
|
|
||||||
this->values[2] = pl->cachedMem;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* this) {
|
|
||||||
ProcessList* pl = (ProcessList*) this->pl;
|
|
||||||
this->total = pl->totalSwap;
|
|
||||||
this->values[0] = pl->usedSwap;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) {
|
|
||||||
envAccum *accump = accum;
|
|
||||||
(void) Phandle;
|
|
||||||
(void) addr;
|
|
||||||
size_t thissz = strlen(str);
|
|
||||||
if ((thissz + 2) > (accump->capacity - accump->size))
|
|
||||||
accump->env = xRealloc(accump->env, accump->capacity *= 2);
|
|
||||||
if ((thissz + 2) > (accump->capacity - accump->size))
|
|
||||||
return 1;
|
|
||||||
strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size));
|
|
||||||
strncpy( accump->env + accump->size + thissz + 1, "\n", 1);
|
|
||||||
accump->size = accump->size + thissz + 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid) {
|
|
||||||
envAccum envBuilder;
|
|
||||||
pid_t realpid = pid / 1024;
|
|
||||||
int graberr;
|
|
||||||
struct ps_prochandle *Phandle;
|
|
||||||
|
|
||||||
if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL)
|
|
||||||
return "Unable to read process environment.";
|
|
||||||
|
|
||||||
envBuilder.capacity = 4096;
|
|
||||||
envBuilder.size = 0;
|
|
||||||
envBuilder.env = xMalloc(envBuilder.capacity);
|
|
||||||
|
|
||||||
(void) Penv_iter(Phandle,Platform_buildenv,&envBuilder);
|
|
||||||
|
|
||||||
Prelease(Phandle, 0);
|
|
||||||
|
|
||||||
strncpy( envBuilder.env + envBuilder.size, "\0", 1);
|
|
||||||
return envBuilder.env;
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_Platform
|
|
||||||
#define HEADER_Platform
|
|
||||||
/*
|
|
||||||
htop - solaris/Platform.h
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2015 David C. Hunt
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Action.h"
|
|
||||||
#include "BatteryMeter.h"
|
|
||||||
#include "SignalsPanel.h"
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/mkdev.h>
|
|
||||||
#include <sys/proc.h>
|
|
||||||
#include <libproc.h>
|
|
||||||
|
|
||||||
#define kill(pid, signal) kill(pid / 1024, signal)
|
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
|
||||||
typedef struct var kvar_t;
|
|
||||||
|
|
||||||
typedef struct envAccum_ {
|
|
||||||
size_t capacity;
|
|
||||||
size_t size;
|
|
||||||
size_t bytes;
|
|
||||||
char *env;
|
|
||||||
} envAccum;
|
|
||||||
|
|
||||||
|
|
||||||
extern double plat_loadavg[3];
|
|
||||||
|
|
||||||
extern const SignalItem Platform_signals[];
|
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfSignals;
|
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern MeterClass* Platform_meterTypes[];
|
|
||||||
|
|
||||||
void Platform_setBindings(Htop_Action* keys);
|
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
|
||||||
|
|
||||||
extern char Process_pidFormat[20];
|
|
||||||
|
|
||||||
int Platform_getUptime();
|
|
||||||
|
|
||||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
|
||||||
|
|
||||||
int Platform_getMaxPid();
|
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* this, int cpu);
|
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* this);
|
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* this);
|
|
||||||
|
|
||||||
char* Platform_getProcessEnv(pid_t pid);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
htop - SolarisCRT.c
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "CRT.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifdef HAVE_EXECINFO_H
|
|
||||||
#include <execinfo.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn) {
|
|
||||||
(void) sgn;
|
|
||||||
CRT_done();
|
|
||||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
|
||||||
#ifdef HAVE_EXECINFO_H
|
|
||||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
|
||||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
|
||||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
|
||||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
|
||||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
|
||||||
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
|
|
||||||
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
|
|
||||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
|
||||||
#endif
|
|
||||||
abort();
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_SolarisCRT
|
|
||||||
#define HEADER_SolarisCRT
|
|
||||||
/*
|
|
||||||
htop - SolarisCRT.h
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_EXECINFO_H
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void CRT_handleSIGSEGV(int sgn);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,214 +0,0 @@
|
|||||||
/*
|
|
||||||
htop - SolarisProcess.c
|
|
||||||
(C) 2015 Hisham H. Muhammad
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Process.h"
|
|
||||||
#include "ProcessList.h"
|
|
||||||
#include "SolarisProcess.h"
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "CRT.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
|
|
||||||
/*{
|
|
||||||
#include "Settings.h"
|
|
||||||
#include <zone.h>
|
|
||||||
#include <sys/proc.h>
|
|
||||||
#include <libproc.h>
|
|
||||||
|
|
||||||
typedef enum SolarisProcessFields {
|
|
||||||
// Add platform-specific fields here, with ids >= 100
|
|
||||||
ZONEID = 100,
|
|
||||||
ZONE = 101,
|
|
||||||
PROJID = 102,
|
|
||||||
TASKID = 103,
|
|
||||||
POOLID = 104,
|
|
||||||
CONTID = 105,
|
|
||||||
LWPID = 106,
|
|
||||||
LAST_PROCESSFIELD = 107,
|
|
||||||
} SolarisProcessField;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct SolarisProcess_ {
|
|
||||||
Process super;
|
|
||||||
int kernel;
|
|
||||||
zoneid_t zoneid;
|
|
||||||
char* zname;
|
|
||||||
taskid_t taskid;
|
|
||||||
projid_t projid;
|
|
||||||
poolid_t poolid;
|
|
||||||
ctid_t contid;
|
|
||||||
bool is_lwp;
|
|
||||||
pid_t realpid;
|
|
||||||
pid_t realppid;
|
|
||||||
pid_t lwpid;
|
|
||||||
} SolarisProcess;
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
|
||||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
|
||||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
ProcessClass SolarisProcess_class = {
|
|
||||||
.super = {
|
|
||||||
.extends = Class(Process),
|
|
||||||
.display = Process_display,
|
|
||||||
.delete = Process_delete,
|
|
||||||
.compare = SolarisProcess_compare
|
|
||||||
},
|
|
||||||
.writeField = (Process_WriteField) SolarisProcess_writeField,
|
|
||||||
};
|
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
|
||||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
|
||||||
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
|
||||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, O onproc, Z zombie, T stopped, W waiting)", .flags = 0, },
|
|
||||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
|
||||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
|
||||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
|
||||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
|
||||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
|
||||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
|
||||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
|
||||||
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
|
||||||
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
|
||||||
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
|
||||||
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
|
||||||
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
|
||||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
|
||||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
|
||||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
|
||||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
|
||||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
|
||||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
|
||||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
|
||||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
|
||||||
[ZONEID] = { .name = "ZONEID", .title = " ZONEID ", .description = "Zone ID", .flags = 0, },
|
|
||||||
[ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, },
|
|
||||||
[PROJID] = { .name = "PROJID", .title = " PRJID ", .description = "Project ID", .flags = 0, },
|
|
||||||
[TASKID] = { .name = "TASKID", .title = " TSKID ", .description = "Task ID", .flags = 0, },
|
|
||||||
[POOLID] = { .name = "POOLID", .title = " POLID ", .description = "Pool ID", .flags = 0, },
|
|
||||||
[CONTID] = { .name = "CONTID", .title = " CNTID ", .description = "Contract ID", .flags = 0, },
|
|
||||||
[LWPID] = { .name = "LWPID", .title = " LWPID ", .description = "LWP ID", .flags = 0, },
|
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
|
||||||
};
|
|
||||||
|
|
||||||
ProcessPidColumn Process_pidColumns[] = {
|
|
||||||
{ .id = ZONEID, .label = "ZONEID" },
|
|
||||||
{ .id = TASKID, .label = "TSKID" },
|
|
||||||
{ .id = PROJID, .label = "PRJID" },
|
|
||||||
{ .id = POOLID, .label = "POLID" },
|
|
||||||
{ .id = CONTID, .label = "CNTID" },
|
|
||||||
{ .id = PID, .label = "PID" },
|
|
||||||
{ .id = PPID, .label = "PPID" },
|
|
||||||
{ .id = LWPID, .label = "LWPID" },
|
|
||||||
{ .id = TPGID, .label = "TPGID" },
|
|
||||||
{ .id = TGID, .label = "TGID" },
|
|
||||||
{ .id = PGRP, .label = "PGRP" },
|
|
||||||
{ .id = SESSION, .label = "SID" },
|
|
||||||
{ .id = 0, .label = NULL },
|
|
||||||
};
|
|
||||||
|
|
||||||
SolarisProcess* SolarisProcess_new(Settings* settings) {
|
|
||||||
SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess));
|
|
||||||
Object_setClass(this, Class(SolarisProcess));
|
|
||||||
Process_init(&this->super, settings);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Process_delete(Object* cast) {
|
|
||||||
SolarisProcess* sp = (SolarisProcess*) cast;
|
|
||||||
Process_done((Process*)cast);
|
|
||||||
free(sp->zname);
|
|
||||||
free(sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
|
||||||
SolarisProcess* sp = (SolarisProcess*) this;
|
|
||||||
char buffer[256]; buffer[255] = '\0';
|
|
||||||
int attr = CRT_colors[DEFAULT_COLOR];
|
|
||||||
int n = sizeof(buffer) - 1;
|
|
||||||
switch ((int) field) {
|
|
||||||
// add Solaris-specific fields here
|
|
||||||
case ZONEID: xSnprintf(buffer, n, Process_pidFormat, sp->zoneid); break;
|
|
||||||
case PROJID: xSnprintf(buffer, n, Process_pidFormat, sp->projid); break;
|
|
||||||
case TASKID: xSnprintf(buffer, n, Process_pidFormat, sp->taskid); break;
|
|
||||||
case POOLID: xSnprintf(buffer, n, Process_pidFormat, sp->poolid); break;
|
|
||||||
case CONTID: xSnprintf(buffer, n, Process_pidFormat, sp->contid); break;
|
|
||||||
case ZONE:{
|
|
||||||
xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break;
|
|
||||||
if (buffer[ZONENAME_MAX/4] != '\0') {
|
|
||||||
buffer[ZONENAME_MAX/4] = ' ';
|
|
||||||
buffer[(ZONENAME_MAX/4)+1] = '\0';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PID: xSnprintf(buffer, n, Process_pidFormat, sp->realpid); break;
|
|
||||||
case PPID: xSnprintf(buffer, n, Process_pidFormat, sp->realppid); break;
|
|
||||||
case LWPID: xSnprintf(buffer, n, Process_pidFormat, sp->lwpid); break;
|
|
||||||
default:
|
|
||||||
Process_writeField(this, str, field);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
RichString_append(str, attr, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
long SolarisProcess_compare(const void* v1, const void* v2) {
|
|
||||||
SolarisProcess *p1, *p2;
|
|
||||||
Settings* settings = ((Process*)v1)->settings;
|
|
||||||
if (settings->direction == 1) {
|
|
||||||
p1 = (SolarisProcess*)v1;
|
|
||||||
p2 = (SolarisProcess*)v2;
|
|
||||||
} else {
|
|
||||||
p2 = (SolarisProcess*)v1;
|
|
||||||
p1 = (SolarisProcess*)v2;
|
|
||||||
}
|
|
||||||
switch ((int) settings->sortKey) {
|
|
||||||
case ZONEID:
|
|
||||||
return (p1->zoneid - p2->zoneid);
|
|
||||||
case PROJID:
|
|
||||||
return (p1->projid - p2->projid);
|
|
||||||
case TASKID:
|
|
||||||
return (p1->taskid - p2->taskid);
|
|
||||||
case POOLID:
|
|
||||||
return (p1->poolid - p2->poolid);
|
|
||||||
case CONTID:
|
|
||||||
return (p1->contid - p2->contid);
|
|
||||||
case ZONE:
|
|
||||||
return strcmp(p1->zname ? p1->zname : "global", p2->zname ? p2->zname : "global");
|
|
||||||
case PID:
|
|
||||||
return (p1->realpid - p2->realpid);
|
|
||||||
case PPID:
|
|
||||||
return (p1->realppid - p2->realppid);
|
|
||||||
case LWPID:
|
|
||||||
return (p1->lwpid - p2->lwpid);
|
|
||||||
default:
|
|
||||||
return Process_compare(v1, v2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Process_isThread(Process* this) {
|
|
||||||
SolarisProcess* fp = (SolarisProcess*) this;
|
|
||||||
|
|
||||||
if (fp->kernel == 1 ) {
|
|
||||||
return 1;
|
|
||||||
} else if (fp->is_lwp) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_SolarisProcess
|
|
||||||
#define HEADER_SolarisProcess
|
|
||||||
/*
|
|
||||||
htop - SolarisProcess.h
|
|
||||||
(C) 2015 Hisham H. Muhammad
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Settings.h"
|
|
||||||
#include <zone.h>
|
|
||||||
#include <sys/proc.h>
|
|
||||||
#include <libproc.h>
|
|
||||||
|
|
||||||
typedef enum SolarisProcessFields {
|
|
||||||
// Add platform-specific fields here, with ids >= 100
|
|
||||||
ZONEID = 100,
|
|
||||||
ZONE = 101,
|
|
||||||
PROJID = 102,
|
|
||||||
TASKID = 103,
|
|
||||||
POOLID = 104,
|
|
||||||
CONTID = 105,
|
|
||||||
LWPID = 106,
|
|
||||||
LAST_PROCESSFIELD = 107,
|
|
||||||
} SolarisProcessField;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct SolarisProcess_ {
|
|
||||||
Process super;
|
|
||||||
int kernel;
|
|
||||||
zoneid_t zoneid;
|
|
||||||
char* zname;
|
|
||||||
taskid_t taskid;
|
|
||||||
projid_t projid;
|
|
||||||
poolid_t poolid;
|
|
||||||
ctid_t contid;
|
|
||||||
bool is_lwp;
|
|
||||||
pid_t realpid;
|
|
||||||
pid_t realppid;
|
|
||||||
pid_t lwpid;
|
|
||||||
} SolarisProcess;
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef Process_isKernelThread
|
|
||||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef Process_isUserlandThread
|
|
||||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern ProcessClass SolarisProcess_class;
|
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
|
||||||
|
|
||||||
extern ProcessPidColumn Process_pidColumns[];
|
|
||||||
|
|
||||||
SolarisProcess* SolarisProcess_new(Settings* settings);
|
|
||||||
|
|
||||||
void Process_delete(Object* cast);
|
|
||||||
|
|
||||||
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field);
|
|
||||||
|
|
||||||
long SolarisProcess_compare(const void* v1, const void* v2);
|
|
||||||
|
|
||||||
bool Process_isThread(Process* this);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,373 +0,0 @@
|
|||||||
/*
|
|
||||||
htop - SolarisProcessList.c
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ProcessList.h"
|
|
||||||
#include "SolarisProcess.h"
|
|
||||||
#include "SolarisProcessList.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/user.h>
|
|
||||||
#include <err.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <procfs.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define MAXCMDLINE 255
|
|
||||||
|
|
||||||
/*{
|
|
||||||
|
|
||||||
#include <kstat.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <sys/sysconf.h>
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#include <sys/swap.h>
|
|
||||||
|
|
||||||
#define ZONE_ERRMSGLEN 1024
|
|
||||||
char zone_errmsg[ZONE_ERRMSGLEN];
|
|
||||||
|
|
||||||
typedef struct CPUData_ {
|
|
||||||
double userPercent;
|
|
||||||
double nicePercent;
|
|
||||||
double systemPercent;
|
|
||||||
double irqPercent;
|
|
||||||
double idlePercent;
|
|
||||||
double systemAllPercent;
|
|
||||||
uint64_t luser;
|
|
||||||
uint64_t lkrnl;
|
|
||||||
uint64_t lintr;
|
|
||||||
uint64_t lidle;
|
|
||||||
} CPUData;
|
|
||||||
|
|
||||||
typedef struct SolarisProcessList_ {
|
|
||||||
ProcessList super;
|
|
||||||
kstat_ctl_t* kd;
|
|
||||||
CPUData* cpus;
|
|
||||||
} SolarisProcessList;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
|
|
||||||
char* zname;
|
|
||||||
if ( sproc->zoneid == 0 ) {
|
|
||||||
zname = xStrdup("global ");
|
|
||||||
} else if ( kd == NULL ) {
|
|
||||||
zname = xStrdup("unknown ");
|
|
||||||
} else {
|
|
||||||
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
|
|
||||||
zname = xStrdup(ks->ks_name);
|
|
||||||
}
|
|
||||||
return zname;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
|
||||||
SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList));
|
|
||||||
ProcessList* pl = (ProcessList*) spl;
|
|
||||||
ProcessList_init(pl, Class(SolarisProcess), usersTable, pidWhiteList, userId);
|
|
||||||
|
|
||||||
spl->kd = kstat_open();
|
|
||||||
|
|
||||||
pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
|
|
||||||
if (pl->cpuCount == 1 ) {
|
|
||||||
spl->cpus = xRealloc(spl->cpus, sizeof(CPUData));
|
|
||||||
} else {
|
|
||||||
spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
|
|
||||||
}
|
|
||||||
|
|
||||||
return pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
|
|
||||||
const SolarisProcessList* spl = (SolarisProcessList*) pl;
|
|
||||||
int cpus = pl->cpuCount;
|
|
||||||
kstat_t *cpuinfo = NULL;
|
|
||||||
int kchain = 0;
|
|
||||||
kstat_named_t *idletime = NULL;
|
|
||||||
kstat_named_t *intrtime = NULL;
|
|
||||||
kstat_named_t *krnltime = NULL;
|
|
||||||
kstat_named_t *usertime = NULL;
|
|
||||||
double idlebuf = 0;
|
|
||||||
double intrbuf = 0;
|
|
||||||
double krnlbuf = 0;
|
|
||||||
double userbuf = 0;
|
|
||||||
uint64_t totaltime = 0;
|
|
||||||
int arrskip = 0;
|
|
||||||
|
|
||||||
assert(cpus > 0);
|
|
||||||
|
|
||||||
if (cpus > 1) {
|
|
||||||
// Store values for the stats loop one extra element up in the array
|
|
||||||
// to leave room for the average to be calculated afterwards
|
|
||||||
arrskip++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate per-CPU statistics first
|
|
||||||
for (int i = 0; i < cpus; i++) {
|
|
||||||
if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); }
|
|
||||||
if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); }
|
|
||||||
if (kchain != -1 ) {
|
|
||||||
idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
|
|
||||||
intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
|
|
||||||
krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel");
|
|
||||||
usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user");
|
|
||||||
}
|
|
||||||
|
|
||||||
assert( (idletime != NULL) && (intrtime != NULL)
|
|
||||||
&& (krnltime != NULL) && (usertime != NULL) );
|
|
||||||
|
|
||||||
CPUData* cpuData = &(spl->cpus[i+arrskip]);
|
|
||||||
totaltime = (idletime->value.ui64 - cpuData->lidle)
|
|
||||||
+ (intrtime->value.ui64 - cpuData->lintr)
|
|
||||||
+ (krnltime->value.ui64 - cpuData->lkrnl)
|
|
||||||
+ (usertime->value.ui64 - cpuData->luser);
|
|
||||||
// Calculate percentages of deltas since last reading
|
|
||||||
cpuData->userPercent = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
|
|
||||||
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
|
||||||
cpuData->systemPercent = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
|
|
||||||
cpuData->irqPercent = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
|
|
||||||
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
|
||||||
cpuData->idlePercent = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
|
|
||||||
// Store current values to use for the next round of deltas
|
|
||||||
cpuData->luser = usertime->value.ui64;
|
|
||||||
cpuData->lkrnl = krnltime->value.ui64;
|
|
||||||
cpuData->lintr = intrtime->value.ui64;
|
|
||||||
cpuData->lidle = idletime->value.ui64;
|
|
||||||
// Accumulate the current percentages into buffers for later average calculation
|
|
||||||
if (cpus > 1) {
|
|
||||||
userbuf += cpuData->userPercent;
|
|
||||||
krnlbuf += cpuData->systemPercent;
|
|
||||||
intrbuf += cpuData->irqPercent;
|
|
||||||
idlebuf += cpuData->idlePercent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cpus > 1) {
|
|
||||||
CPUData* cpuData = &(spl->cpus[0]);
|
|
||||||
cpuData->userPercent = userbuf / cpus;
|
|
||||||
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
|
||||||
cpuData->systemPercent = krnlbuf / cpus;
|
|
||||||
cpuData->irqPercent = intrbuf / cpus;
|
|
||||||
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
|
||||||
cpuData->idlePercent = idlebuf / cpus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
|
|
||||||
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
|
||||||
kstat_t *meminfo = NULL;
|
|
||||||
int ksrphyserr = -1;
|
|
||||||
kstat_named_t *totalmem_pgs = NULL;
|
|
||||||
kstat_named_t *lockedmem_pgs = NULL;
|
|
||||||
kstat_named_t *pages = NULL;
|
|
||||||
struct swaptable *sl = NULL;
|
|
||||||
struct swapent *swapdev = NULL;
|
|
||||||
uint64_t totalswap = 0;
|
|
||||||
uint64_t totalfree = 0;
|
|
||||||
int nswap = 0;
|
|
||||||
char *spath = NULL;
|
|
||||||
char *spathbase = NULL;
|
|
||||||
|
|
||||||
// Part 1 - physical memory
|
|
||||||
if (spl->kd != NULL) { meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); }
|
|
||||||
if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); }
|
|
||||||
if (ksrphyserr != -1) {
|
|
||||||
totalmem_pgs = kstat_data_lookup( meminfo, "physmem" );
|
|
||||||
lockedmem_pgs = kstat_data_lookup( meminfo, "pageslocked" );
|
|
||||||
pages = kstat_data_lookup( meminfo, "pagestotal" );
|
|
||||||
|
|
||||||
pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
|
||||||
pl->usedMem = lockedmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
|
||||||
// Not sure how to implement this on Solaris - suggestions welcome!
|
|
||||||
pl->cachedMem = 0;
|
|
||||||
// Not really "buffers" but the best Solaris analogue that I can find to
|
|
||||||
// "memory in use but not by programs or the kernel itself"
|
|
||||||
pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * PAGE_SIZE_KB;
|
|
||||||
} else {
|
|
||||||
// Fall back to basic sysconf if kstat isn't working
|
|
||||||
pl->totalMem = sysconf(_SC_PHYS_PAGES) * PAGE_SIZE;
|
|
||||||
pl->buffersMem = 0;
|
|
||||||
pl->cachedMem = 0;
|
|
||||||
pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Part 2 - swap
|
|
||||||
nswap = swapctl(SC_GETNSWP, NULL);
|
|
||||||
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); }
|
|
||||||
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); }
|
|
||||||
if (spathbase != NULL) {
|
|
||||||
spath = spathbase;
|
|
||||||
swapdev = sl->swt_ent;
|
|
||||||
for (int i = 0; i < nswap; i++, swapdev++) {
|
|
||||||
swapdev->ste_path = spath;
|
|
||||||
spath += MAXPATHLEN;
|
|
||||||
}
|
|
||||||
sl->swt_n = nswap;
|
|
||||||
}
|
|
||||||
nswap = swapctl(SC_LIST, sl);
|
|
||||||
if (nswap > 0) {
|
|
||||||
swapdev = sl->swt_ent;
|
|
||||||
for (int i = 0; i < nswap; i++, swapdev++) {
|
|
||||||
totalswap += swapdev->ste_pages;
|
|
||||||
totalfree += swapdev->ste_free;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(spathbase);
|
|
||||||
free(sl);
|
|
||||||
pl->totalSwap = totalswap * PAGE_SIZE_KB;
|
|
||||||
pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessList_delete(ProcessList* pl) {
|
|
||||||
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
|
||||||
ProcessList_done(pl);
|
|
||||||
free(spl->cpus);
|
|
||||||
if (spl->kd) kstat_close(spl->kd);
|
|
||||||
free(spl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: the following is a callback function of type proc_walk_f
|
|
||||||
* and MUST conform to the appropriate definition in order
|
|
||||||
* to work. See libproc(3LIB) on a Solaris or Illumos
|
|
||||||
* system for more info.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) {
|
|
||||||
struct timeval tv;
|
|
||||||
struct tm date;
|
|
||||||
bool preExisting;
|
|
||||||
pid_t getpid;
|
|
||||||
|
|
||||||
// Setup process list
|
|
||||||
ProcessList *pl = (ProcessList*) listptr;
|
|
||||||
SolarisProcessList *spl = (SolarisProcessList*) listptr;
|
|
||||||
|
|
||||||
id_t lwpid_real = _lwpsinfo->pr_lwpid;
|
|
||||||
if (lwpid_real > 1023) return 0;
|
|
||||||
pid_t lwpid = (_psinfo->pr_pid * 1024) + lwpid_real;
|
|
||||||
bool onMasterLWP = (_lwpsinfo->pr_lwpid == _psinfo->pr_lwp.pr_lwpid);
|
|
||||||
if (onMasterLWP) {
|
|
||||||
getpid = _psinfo->pr_pid * 1024;
|
|
||||||
} else {
|
|
||||||
getpid = lwpid;
|
|
||||||
}
|
|
||||||
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new);
|
|
||||||
SolarisProcess *sproc = (SolarisProcess*) proc;
|
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
|
|
||||||
// Common code pass 1
|
|
||||||
proc->show = false;
|
|
||||||
sproc->taskid = _psinfo->pr_taskid;
|
|
||||||
sproc->projid = _psinfo->pr_projid;
|
|
||||||
sproc->poolid = _psinfo->pr_poolid;
|
|
||||||
sproc->contid = _psinfo->pr_contract;
|
|
||||||
proc->priority = _lwpsinfo->pr_pri;
|
|
||||||
proc->nice = _lwpsinfo->pr_nice;
|
|
||||||
proc->processor = _lwpsinfo->pr_onpro;
|
|
||||||
proc->state = _lwpsinfo->pr_sname;
|
|
||||||
// NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000
|
|
||||||
// Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html
|
|
||||||
// (accessed on 18 November 2017)
|
|
||||||
proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem/(double)32768)*(double)100.0;
|
|
||||||
proc->st_uid = _psinfo->pr_euid;
|
|
||||||
proc->pgrp = _psinfo->pr_pgid;
|
|
||||||
proc->nlwp = _psinfo->pr_nlwp;
|
|
||||||
proc->tty_nr = _psinfo->pr_ttydev;
|
|
||||||
proc->m_resident = _psinfo->pr_rssize/PAGE_SIZE_KB;
|
|
||||||
proc->m_size = _psinfo->pr_size/PAGE_SIZE_KB;
|
|
||||||
|
|
||||||
if (!preExisting) {
|
|
||||||
sproc->realpid = _psinfo->pr_pid;
|
|
||||||
sproc->lwpid = lwpid_real;
|
|
||||||
sproc->zoneid = _psinfo->pr_zoneid;
|
|
||||||
sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
|
|
||||||
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
|
||||||
proc->comm = xStrdup(_psinfo->pr_fname);
|
|
||||||
proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
// End common code pass 1
|
|
||||||
|
|
||||||
if (onMasterLWP) { // Are we on the representative LWP?
|
|
||||||
proc->ppid = (_psinfo->pr_ppid * 1024);
|
|
||||||
proc->tgid = (_psinfo->pr_ppid * 1024);
|
|
||||||
sproc->realppid = _psinfo->pr_ppid;
|
|
||||||
// See note above (in common section) about this BINARY FRACTION
|
|
||||||
proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
|
||||||
proc->time = _psinfo->pr_time.tv_sec;
|
|
||||||
if(!preExisting) { // Tasks done only for NEW processes
|
|
||||||
sproc->is_lwp = false;
|
|
||||||
proc->starttime_ctime = _psinfo->pr_start.tv_sec;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update proc and thread counts based on settings
|
|
||||||
if (sproc->kernel && !pl->settings->hideKernelThreads) {
|
|
||||||
pl->kernelThreads += proc->nlwp;
|
|
||||||
pl->totalTasks += proc->nlwp+1;
|
|
||||||
if (proc->state == 'O') pl->runningTasks++;
|
|
||||||
} else if (!sproc->kernel) {
|
|
||||||
if (proc->state == 'O') pl->runningTasks++;
|
|
||||||
if (pl->settings->hideUserlandThreads) {
|
|
||||||
pl->totalTasks++;
|
|
||||||
} else {
|
|
||||||
pl->userlandThreads += proc->nlwp;
|
|
||||||
pl->totalTasks += proc->nlwp+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
proc->show = !(pl->settings->hideKernelThreads && sproc->kernel);
|
|
||||||
} else { // We are not in the master LWP, so jump to the LWP handling code
|
|
||||||
proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
|
||||||
proc->time = _lwpsinfo->pr_time.tv_sec;
|
|
||||||
if (!preExisting) { // Tasks done only for NEW LWPs
|
|
||||||
sproc->is_lwp = true;
|
|
||||||
proc->basenameOffset = -1;
|
|
||||||
proc->ppid = _psinfo->pr_pid * 1024;
|
|
||||||
proc->tgid = _psinfo->pr_pid * 1024;
|
|
||||||
sproc->realppid = _psinfo->pr_pid;
|
|
||||||
proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top-level process only gets this for the representative LWP
|
|
||||||
if (sproc->kernel && !pl->settings->hideKernelThreads) proc->show = true;
|
|
||||||
if (!sproc->kernel && !pl->settings->hideUserlandThreads) proc->show = true;
|
|
||||||
} // Top-level LWP or subordinate LWP
|
|
||||||
|
|
||||||
// Common code pass 2
|
|
||||||
|
|
||||||
if (!preExisting) {
|
|
||||||
if ((sproc->realppid <= 0) && !(sproc->realpid <= 1)) {
|
|
||||||
sproc->kernel = true;
|
|
||||||
} else {
|
|
||||||
sproc->kernel = false;
|
|
||||||
}
|
|
||||||
(void) localtime_r((time_t*) &proc->starttime_ctime, &date);
|
|
||||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
|
|
||||||
ProcessList_add(pl, proc);
|
|
||||||
}
|
|
||||||
proc->updated = true;
|
|
||||||
|
|
||||||
// End common code pass 2
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* this) {
|
|
||||||
SolarisProcessList_scanCPUTime(this);
|
|
||||||
SolarisProcessList_scanMemoryInfo(this);
|
|
||||||
this->kernelThreads = 1;
|
|
||||||
proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP);
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
|||||||
/* Do not edit this file. It was automatically generated. */
|
|
||||||
|
|
||||||
#ifndef HEADER_SolarisProcessList
|
|
||||||
#define HEADER_SolarisProcessList
|
|
||||||
/*
|
|
||||||
htop - SolarisProcessList.h
|
|
||||||
(C) 2014 Hisham H. Muhammad
|
|
||||||
(C) 2017,2018 Guy M. Broome
|
|
||||||
Released under the GNU GPL, see the COPYING file
|
|
||||||
in the source distribution for its full text.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MAXCMDLINE 255
|
|
||||||
|
|
||||||
|
|
||||||
#include <kstat.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <sys/sysconf.h>
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#include <sys/swap.h>
|
|
||||||
|
|
||||||
#define ZONE_ERRMSGLEN 1024
|
|
||||||
char zone_errmsg[ZONE_ERRMSGLEN];
|
|
||||||
|
|
||||||
typedef struct CPUData_ {
|
|
||||||
double userPercent;
|
|
||||||
double nicePercent;
|
|
||||||
double systemPercent;
|
|
||||||
double irqPercent;
|
|
||||||
double idlePercent;
|
|
||||||
double systemAllPercent;
|
|
||||||
uint64_t luser;
|
|
||||||
uint64_t lkrnl;
|
|
||||||
uint64_t lintr;
|
|
||||||
uint64_t lidle;
|
|
||||||
} CPUData;
|
|
||||||
|
|
||||||
typedef struct SolarisProcessList_ {
|
|
||||||
ProcessList super;
|
|
||||||
kstat_ctl_t* kd;
|
|
||||||
CPUData* cpus;
|
|
||||||
} SolarisProcessList;
|
|
||||||
|
|
||||||
|
|
||||||
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc);
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
|
||||||
|
|
||||||
void ProcessList_delete(ProcessList* pl);
|
|
||||||
|
|
||||||
/* NOTE: the following is a callback function of type proc_walk_f
|
|
||||||
* and MUST conform to the appropriate definition in order
|
|
||||||
* to work. See libproc(3LIB) on a Solaris or Illumos
|
|
||||||
* system for more info.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr);
|
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* this);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -29,15 +29,7 @@ const SignalItem Platform_signals[] = {
|
|||||||
|
|
||||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||||
|
|
||||||
ScreenDefaults Platform_defaultScreens[] = {
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||||
{
|
|
||||||
.name = "Default",
|
|
||||||
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
|
||||||
.sortKey = "PERCENT_CPU",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
|
||||||
|
|
||||||
ProcessFieldData Process_fields[] = {
|
ProcessFieldData Process_fields[] = {
|
||||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
|
@ -19,9 +19,7 @@ extern const SignalItem Platform_signals[];
|
|||||||
|
|
||||||
extern const unsigned int Platform_numberOfSignals;
|
extern const unsigned int Platform_numberOfSignals;
|
||||||
|
|
||||||
extern ScreenDefaults Platform_defaultScreens[];
|
extern ProcessField Platform_defaultFields[];
|
||||||
|
|
||||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
|
@ -68,3 +68,8 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
proc->minflt = 20;
|
proc->minflt = 20;
|
||||||
proc->majflt = 20;
|
proc->majflt = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnsupportedProcessList_scan(ProcessList* this) {
|
||||||
|
(void) this;
|
||||||
|
// stub!
|
||||||
|
}
|
||||||
|
@ -17,4 +17,6 @@ void ProcessList_delete(ProcessList* this);
|
|||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* super);
|
void ProcessList_goThroughEntries(ProcessList* super);
|
||||||
|
|
||||||
|
void UnsupportedProcessList_scan(ProcessList* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user