diff options
Diffstat (limited to 'tools/perf/util/util.c')
| -rw-r--r-- | tools/perf/util/util.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 47b1e36c7ea0..ead9509835d2 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
| @@ -16,12 +16,14 @@ | |||
| 16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| 17 | #include <unistd.h> | 17 | #include <unistd.h> |
| 18 | #include "callchain.h" | 18 | #include "callchain.h" |
| 19 | #include "strlist.h" | ||
| 19 | 20 | ||
| 20 | struct callchain_param callchain_param = { | 21 | struct callchain_param callchain_param = { |
| 21 | .mode = CHAIN_GRAPH_ABS, | 22 | .mode = CHAIN_GRAPH_ABS, |
| 22 | .min_percent = 0.5, | 23 | .min_percent = 0.5, |
| 23 | .order = ORDER_CALLEE, | 24 | .order = ORDER_CALLEE, |
| 24 | .key = CCKEY_FUNCTION | 25 | .key = CCKEY_FUNCTION, |
| 26 | .value = CCVAL_PERCENT, | ||
| 25 | }; | 27 | }; |
| 26 | 28 | ||
| 27 | /* | 29 | /* |
| @@ -351,41 +353,8 @@ void sighandler_dump_stack(int sig) | |||
| 351 | { | 353 | { |
| 352 | psignal(sig, "perf"); | 354 | psignal(sig, "perf"); |
| 353 | dump_stack(); | 355 | dump_stack(); |
| 354 | exit(sig); | 356 | signal(sig, SIG_DFL); |
| 355 | } | 357 | raise(sig); |
| 356 | |||
| 357 | void get_term_dimensions(struct winsize *ws) | ||
| 358 | { | ||
| 359 | char *s = getenv("LINES"); | ||
| 360 | |||
| 361 | if (s != NULL) { | ||
| 362 | ws->ws_row = atoi(s); | ||
| 363 | s = getenv("COLUMNS"); | ||
| 364 | if (s != NULL) { | ||
| 365 | ws->ws_col = atoi(s); | ||
| 366 | if (ws->ws_row && ws->ws_col) | ||
| 367 | return; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | #ifdef TIOCGWINSZ | ||
| 371 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && | ||
| 372 | ws->ws_row && ws->ws_col) | ||
| 373 | return; | ||
| 374 | #endif | ||
| 375 | ws->ws_row = 25; | ||
| 376 | ws->ws_col = 80; | ||
| 377 | } | ||
| 378 | |||
| 379 | void set_term_quiet_input(struct termios *old) | ||
| 380 | { | ||
| 381 | struct termios tc; | ||
| 382 | |||
| 383 | tcgetattr(0, old); | ||
| 384 | tc = *old; | ||
| 385 | tc.c_lflag &= ~(ICANON | ECHO); | ||
| 386 | tc.c_cc[VMIN] = 0; | ||
| 387 | tc.c_cc[VTIME] = 0; | ||
| 388 | tcsetattr(0, TCSANOW, &tc); | ||
| 389 | } | 358 | } |
| 390 | 359 | ||
| 391 | int parse_nsec_time(const char *str, u64 *ptime) | 360 | int parse_nsec_time(const char *str, u64 *ptime) |
| @@ -695,3 +664,30 @@ fetch_kernel_version(unsigned int *puint, char *str, | |||
| 695 | *puint = (version << 16) + (patchlevel << 8) + sublevel; | 664 | *puint = (version << 16) + (patchlevel << 8) + sublevel; |
| 696 | return 0; | 665 | return 0; |
| 697 | } | 666 | } |
| 667 | |||
| 668 | const char *perf_tip(const char *dirpath) | ||
| 669 | { | ||
| 670 | struct strlist *tips; | ||
| 671 | struct str_node *node; | ||
| 672 | char *tip = NULL; | ||
| 673 | struct strlist_config conf = { | ||
| 674 | .dirname = dirpath, | ||
| 675 | .file_only = true, | ||
| 676 | }; | ||
| 677 | |||
| 678 | tips = strlist__new("tips.txt", &conf); | ||
| 679 | if (tips == NULL) | ||
| 680 | return errno == ENOENT ? NULL : "Tip: get more memory! ;-p"; | ||
| 681 | |||
| 682 | if (strlist__nr_entries(tips) == 0) | ||
| 683 | goto out; | ||
| 684 | |||
| 685 | node = strlist__entry(tips, random() % strlist__nr_entries(tips)); | ||
| 686 | if (asprintf(&tip, "Tip: %s", node->s) < 0) | ||
| 687 | tip = (char *)"Tip: get more memory! ;-)"; | ||
| 688 | |||
| 689 | out: | ||
| 690 | strlist__delete(tips); | ||
| 691 | |||
| 692 | return tip; | ||
| 693 | } | ||
