forked from luck/tmp_suning_uos_patched
49b8e2bece
An automatic const char[] variable gets initialized at runtime, just like any other automatic variable. For long strings, that uses a lot of stack and wastes time building the string; e.g. for the "No %s allocation events..." case one has: 444516: 48 b8 4e 6f 20 25 73 20 61 6c movabs $0x6c61207325206f4e,%rax # "No %s al" ... 444674: 48 89 45 80 mov %rax,-0x80(%rbp) 444678: 48 b8 6c 6f 63 61 74 69 6f 6e movabs $0x6e6f697461636f6c,%rax # "location" 444682: 48 89 45 88 mov %rax,-0x78(%rbp) 444686: 48 b8 20 65 76 65 6e 74 73 20 movabs $0x2073746e65766520,%rax # " events " 444690: 66 44 89 55 c4 mov %r10w,-0x3c(%rbp) 444695: 48 89 45 90 mov %rax,-0x70(%rbp) 444699: 48 b8 66 6f 75 6e 64 2e 20 20 movabs $0x20202e646e756f66,%rax Make them all static so that the compiler just references objects in .rodata. Committer testing: Ok, using dwarves's codiff tool: $ codiff --functions /tmp/perf.before ~/bin/perf builtin-sched.c: cmd_sched | -48 1 function changed, 48 bytes removed, diff: -48 builtin-report.c: cmd_report | -32 1 function changed, 32 bytes removed, diff: -32 builtin-kmem.c: cmd_kmem | -64 build_alloc_func_list | -50 2 functions changed, 114 bytes removed, diff: -114 builtin-c2c.c: perf_c2c__report | -390 1 function changed, 390 bytes removed, diff: -390 ui/browsers/header.c: tui__header_window | -104 1 function changed, 104 bytes removed, diff: -104 /home/acme/bin/perf: 9 functions changed, 688 bytes removed, diff: -688 Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20181102230624.20064-1-linux@rasmusvillemoes.dk Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
132 lines
2.6 KiB
C
132 lines
2.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "util/cache.h"
|
|
#include "util/debug.h"
|
|
#include "ui/browser.h"
|
|
#include "ui/keysyms.h"
|
|
#include "ui/ui.h"
|
|
#include "ui/util.h"
|
|
#include "ui/libslang.h"
|
|
#include "util/header.h"
|
|
#include "util/session.h"
|
|
|
|
#include <sys/ttydefaults.h>
|
|
|
|
static void ui_browser__argv_write(struct ui_browser *browser,
|
|
void *entry, int row)
|
|
{
|
|
char **arg = entry;
|
|
char *str = *arg;
|
|
char empty[] = " ";
|
|
bool current_entry = ui_browser__is_current_entry(browser, row);
|
|
unsigned long offset = (unsigned long)browser->priv;
|
|
|
|
if (offset >= strlen(str))
|
|
str = empty;
|
|
else
|
|
str = str + offset;
|
|
|
|
ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
|
|
HE_COLORSET_NORMAL);
|
|
|
|
ui_browser__write_nstring(browser, str, browser->width);
|
|
}
|
|
|
|
static int list_menu__run(struct ui_browser *menu)
|
|
{
|
|
int key;
|
|
unsigned long offset;
|
|
static const char help[] =
|
|
"h/?/F1 Show this window\n"
|
|
"UP/DOWN/PGUP\n"
|
|
"PGDN/SPACE\n"
|
|
"LEFT/RIGHT Navigate\n"
|
|
"q/ESC/CTRL+C Exit browser";
|
|
|
|
if (ui_browser__show(menu, "Header information", "Press 'q' to exit") < 0)
|
|
return -1;
|
|
|
|
while (1) {
|
|
key = ui_browser__run(menu, 0);
|
|
|
|
switch (key) {
|
|
case K_RIGHT:
|
|
offset = (unsigned long)menu->priv;
|
|
offset += 10;
|
|
menu->priv = (void *)offset;
|
|
continue;
|
|
case K_LEFT:
|
|
offset = (unsigned long)menu->priv;
|
|
if (offset >= 10)
|
|
offset -= 10;
|
|
menu->priv = (void *)offset;
|
|
continue;
|
|
case K_F1:
|
|
case 'h':
|
|
case '?':
|
|
ui_browser__help_window(menu, help);
|
|
continue;
|
|
case K_ESC:
|
|
case 'q':
|
|
case CTRL('c'):
|
|
key = -1;
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
ui_browser__hide(menu);
|
|
return key;
|
|
}
|
|
|
|
static int ui__list_menu(int argc, char * const argv[])
|
|
{
|
|
struct ui_browser menu = {
|
|
.entries = (void *)argv,
|
|
.refresh = ui_browser__argv_refresh,
|
|
.seek = ui_browser__argv_seek,
|
|
.write = ui_browser__argv_write,
|
|
.nr_entries = argc,
|
|
};
|
|
|
|
return list_menu__run(&menu);
|
|
}
|
|
|
|
int tui__header_window(struct perf_env *env)
|
|
{
|
|
int i, argc = 0;
|
|
char **argv;
|
|
struct perf_session *session;
|
|
char *ptr, *pos;
|
|
size_t size;
|
|
FILE *fp = open_memstream(&ptr, &size);
|
|
|
|
session = container_of(env, struct perf_session, header.env);
|
|
perf_header__fprintf_info(session, fp, true);
|
|
fclose(fp);
|
|
|
|
for (pos = ptr, argc = 0; (pos = strchr(pos, '\n')) != NULL; pos++)
|
|
argc++;
|
|
|
|
argv = calloc(argc + 1, sizeof(*argv));
|
|
if (argv == NULL)
|
|
goto out;
|
|
|
|
argv[0] = pos = ptr;
|
|
for (i = 1; (pos = strchr(pos, '\n')) != NULL; i++) {
|
|
*pos++ = '\0';
|
|
argv[i] = pos;
|
|
}
|
|
|
|
BUG_ON(i != argc + 1);
|
|
|
|
ui__list_menu(argc, argv);
|
|
|
|
out:
|
|
free(argv);
|
|
free(ptr);
|
|
return 0;
|
|
}
|