mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 21:44:36 +03:00
Compare commits
33 Commits
3.0.0beta1
...
3.0.0beta2
Author | SHA1 | Date | |
---|---|---|---|
805546e291 | |||
4aba5d878d | |||
e48b63b585 | |||
1748abfb4e | |||
d0fc93d82c | |||
0cbdf8ba27 | |||
cf0c074cc8 | |||
9c40c9a0e7 | |||
c55c8c2316 | |||
eb8ca9be84 | |||
401d19be37 | |||
bcf4a30ee6 | |||
86fea8facd | |||
d145a3bfdd | |||
b63d0d04db | |||
117cc515fc | |||
187a035a76 | |||
ece89b8df0 | |||
52b5beb4e4 | |||
df9922a67e | |||
fcdff59f4c | |||
b544c22c72 | |||
f37a050d3d | |||
03f17688ad | |||
a32d7528f6 | |||
ac2dff2881 | |||
c50440f165 | |||
b0588d90ff | |||
b84ebfd4e8 | |||
b86e14d3cf | |||
b34d76cd41 | |||
87be623eac | |||
b27712181a |
32
CRT.c
32
CRT.c
@ -37,6 +37,7 @@ 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)
|
||||||
@ -718,22 +719,23 @@ 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) != ColorIndex(Magenta,Magenta)) {
|
if (ColorIndex(i,j) != ColorPairGrayBlack) {
|
||||||
init_pair(ColorIndex(i,j), i, j);
|
int bg = (colorScheme != COLORSCHEME_BLACKNIGHT)
|
||||||
}
|
? (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,6 +26,7 @@ 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)
|
||||||
|
42
ChangeLog
42
ChangeLog
@ -1,3 +1,45 @@
|
|||||||
|
What's new in version 2.1.1
|
||||||
|
|
||||||
|
* Check for pkg-config when building with --enable-delayacct
|
||||||
|
(thanks to @florian2833z for the report)
|
||||||
|
* 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,6 +78,7 @@ 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]);
|
||||||
|
4
Meter.c
4
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, buffer);
|
xSnprintf(bar, w + 1, "%*.*s", w, w, buffer);
|
||||||
|
|
||||||
// First draw in the bar[] buffer...
|
// First draw in the bar[] buffer...
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
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 < 255 && isalnum(ch)) {
|
if (ch > 0 && ch < 255 && isalnum(ch)) {
|
||||||
int len = strlen(buffer);
|
int len = strlen(buffer);
|
||||||
if (len < 99) {
|
if (len < 99) {
|
||||||
buffer[len] = ch;
|
buffer[len] = ch;
|
||||||
|
@ -28,7 +28,6 @@ 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>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
@ -46,6 +45,7 @@ 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
|
||||||
|
|
||||||
@ -175,6 +175,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#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;
|
||||||
@ -600,7 +602,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 (p1->state - p2->state);
|
return (Process_sortState(p1->state) - Process_sortState(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:
|
||||||
|
@ -24,6 +24,7 @@ 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
|
||||||
|
|
||||||
@ -153,6 +154,8 @@ typedef struct ProcessClass_ {
|
|||||||
|
|
||||||
#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)
|
||||||
|
@ -232,6 +232,11 @@ void ProcessList_sort(ProcessList* this) {
|
|||||||
pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid;
|
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;
|
||||||
|
8
Vector.c
8
Vector.c
@ -284,11 +284,19 @@ 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,8 +70,16 @@ 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
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -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],[2.0.2],[hisham@gobolinux.org])
|
AC_INIT([htop],[3.0.0beta2],[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")
|
||||||
@ -167,7 +167,7 @@ m4_define([HTOP_CHECK_SCRIPT],
|
|||||||
LIBS="$htop_config_script $LIBS "
|
LIBS="$htop_config_script $LIBS "
|
||||||
htop_script_success=yes
|
htop_script_success=yes
|
||||||
], [])
|
], [])
|
||||||
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]
|
||||||
@ -305,6 +305,7 @@ 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+=" $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
CFLAGS+=" $LIBNL3_CFLAGS $LIBNL3GENL_CFLAGS"
|
||||||
|
@ -171,7 +171,8 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
|||||||
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 due to bug in macOS High Sierra
|
||||||
|
// DarwinProcess_scanThreads(proc);
|
||||||
|
|
||||||
super->totalTasks += 1;
|
super->totalTasks += 1;
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ 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
|
||||||
@ -97,7 +102,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, },
|
||||||
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
MeterClass* Platform_meterTypes[] = {
|
MeterClass* Platform_meterTypes[] = {
|
||||||
|
@ -16,6 +16,10 @@ 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
|
||||||
|
@ -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 (hightlight) the previous process in the process list. Scroll the list
|
Select (highlight) 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 (hightlight) the next process in the process list. Scroll the list if
|
Select (highlight) the next process in the process list. Scroll the list if
|
||||||
necessary.
|
necessary.
|
||||||
.TP
|
.TP
|
||||||
.B Left, Alt-h
|
.B Left, Alt-h
|
||||||
|
@ -72,6 +72,8 @@ 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);
|
||||||
|
@ -198,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)", .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, },
|
||||||
[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, },
|
||||||
|
135
linux/PerfCounter.c
Normal file
135
linux/PerfCounter.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
54
linux/PerfCounter.h
Normal file
54
linux/PerfCounter.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* 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
|
Reference in New Issue
Block a user