summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Warner <james.warner@comcast.net>2012-10-05 15:15:15 -0500
committerCraig Small <csmall@enc.com.au>2012-10-11 21:13:14 +1100
commite77c8e8cf0428ed5f3498ba8b06b1936ab7c955c (patch)
tree481903ec7a5ac8eb81b14b9c3d5e667dc7e317ec
parentf00541197400e8a70649300aa1faaac56a972edb (diff)
downloadprocps-ng-e77c8e8cf0428ed5f3498ba8b06b1936ab7c955c.tar.gz
top: for performance, employ additional inlining
The 'refactor and enhance column width management' recent redesign produced many subsequent benefits, the latest of which is automatically sized fixed-width non-scalable columns. As expected, there was a cost associated with these many enhancements. That cost has now been identified as a 1-4% performance degradation, depending on which fields are being displayed. This increased cost arises principally from current drawing related function calls, whereas top-3.3.3 did most of its drawing via macros effectively inlining those duties. This commit inlines the equivalent drawing functions, thus eliminating the function call penalty, and places this top on a par with top-3.3.3. The trade off is a modest additional 4k in executable size. Signed-off-by: Jim Warner <james.warner@comcast.net>
-rw-r--r--top/top.c10
-rw-r--r--top/top.h8
2 files changed, 9 insertions, 9 deletions
diff --git a/top/top.c b/top/top.c
index 0b5e1e6..327db6c 100644
--- a/top/top.c
+++ b/top/top.c
@@ -360,7 +360,7 @@ static void bye_bye (const char *str) {
#else
"\n\t winflags = %08x, maxpflgs = %d"
#endif
- "\n\t sortindx = %d, fieldscur = %s"
+ "\n\t sortindx = %d, fieldscur = %s"
"\n\t maxtasks = %d, varcolsz = %d, winlines = %d"
"\n\t strlen(columnhdr) = %d"
"\n"
@@ -1169,7 +1169,7 @@ static inline const char *justify_pad (const char *str, int width, int justr) {
/*
* Make and then justify a single character. */
-static const char *make_chr (const char ch, int width, int justr) {
+static inline const char *make_chr (const char ch, int width, int justr) {
static char buf[SMLBUFSIZ];
snprintf(buf, sizeof(buf), "%c", ch);
@@ -1180,7 +1180,7 @@ static const char *make_chr (const char ch, int width, int justr) {
/*
* Make and then justify an integer NOT subject to scaling,
* and include a visual clue should tuncation be necessary. */
-static const char *make_num (long num, int width, int justr, int col) {
+static inline const char *make_num (long num, int width, int justr, int col) {
static char buf[SMLBUFSIZ];
if (width < snprintf(buf, sizeof(buf), "%ld", num)) {
@@ -1194,7 +1194,7 @@ static const char *make_num (long num, int width, int justr, int col) {
/*
* Make and then justify a character string,
* and include a visual clue should tuncation be necessary. */
-static const char *make_str (const char *str, int width, int justr, int col) {
+static inline const char *make_str (const char *str, int width, int justr, int col) {
static char buf[SCREENMAX];
if (width < snprintf(buf, sizeof(buf), "%s", str)) {
@@ -1207,7 +1207,7 @@ static const char *make_str (const char *str, int width, int justr, int col) {
/*
* Make and then justify a percentage, with decreasing precision. */
-static const char *scale_pcnt (float num, int width, int justr) {
+static inline const char *scale_pcnt (float num, int width, int justr) {
static char buf[SMLBUFSIZ];
#ifdef PERCENTBOOST
diff --git a/top/top.h b/top/top.h
index b90d913..3169ac8 100644
--- a/top/top.h
+++ b/top/top.h
@@ -612,10 +612,10 @@ typedef struct WIN_t {
//atic inline int user_matched (WIN_t *q, const proc_t *p);
/*------ Basic Formatting support --------------------------------------*/
//atic inline const char *justify_pad (const char *str, int width, int justr);
-//atic const char *make_chr (const char ch, int width, int justr);
-//atic const char *make_num (long num, int width, int justr, int col);
-//atic const char *make_str (const char *str, int width, int justr, int col);
-//atic const char *scale_pcnt (float num, int width, int justr);
+//atic inline const char *make_chr (const char ch, int width, int justr);
+//atic inline const char *make_num (long num, int width, int justr, int col);
+//atic inline const char *make_str (const char *str, int width, int justr, int col);
+//atic inline const char *scale_pcnt (float num, int width, int justr);
//atic const char *scale_tics (TIC_t tics, int width, int justr);
//atic const char *scale_unum (unsigned long num, int type, int width, int justr);
/*------ Fields Management support -------------------------------------*/