diff --git a/latencytop-better-error-message-if-run-as-non-root.patch b/latencytop-better-error-message-if-run-as-non-root.patch new file mode 100644 index 0000000..7677863 --- /dev/null +++ b/latencytop-better-error-message-if-run-as-non-root.patch @@ -0,0 +1,36 @@ +From 0b92f870121bfb20ca851191525cde81b8d0f21e Mon Sep 17 00:00:00 2001 +From: Michal Schmidt +Date: Thu, 16 Feb 2012 00:04:00 +0100 +Subject: [PATCH 2/2] better error message if run as non-root + +--- + src/latencytop.c | 6 +++++- + 1 files changed, 5 insertions(+), 1 deletions(-) + +diff --git a/src/latencytop.c b/src/latencytop.c +index 0ffb7f3..43e44f0 100644 +--- a/src/latencytop.c ++++ b/src/latencytop.c +@@ -24,6 +24,7 @@ + + #define _GNU_SOURCE + ++#include + #include + #include + #include +@@ -120,7 +121,10 @@ void parse_global_list(void) + size_t dummy; + file = fopen("/proc/latency_stats","r+"); + if (!file) { +- fprintf(stderr, "Please enable the CONFIG_LATENCYTOP configuration in your kernel.\n"); ++ if (errno == ENOENT) ++ fprintf(stderr, "Please enable the CONFIG_LATENCYTOP configuration in your kernel.\n"); ++ else ++ perror("Failed to open /proc/latency_stats"); + fprintf(stderr, "Exiting...\n"); + exit(EXIT_FAILURE); + } +-- +1.7.7.6 + diff --git a/latencytop-remove-the-fsync-view.patch b/latencytop-remove-the-fsync-view.patch new file mode 100644 index 0000000..e6b97c5 --- /dev/null +++ b/latencytop-remove-the-fsync-view.patch @@ -0,0 +1,486 @@ +From a4a1eb20492773d48bd83087157149c5fb9a257a Mon Sep 17 00:00:00 2001 +From: Michal Schmidt +Date: Wed, 15 Feb 2012 23:44:18 +0100 +Subject: [PATCH 1/2] remove the fsync view + +The fsync tracer it depends on was never merged in the kernel. +It also uses 'tracing_enable' which triggers deprecation warnings in the +kernel. +--- + src/Makefile | 2 +- + src/fsync.c | 369 -------------------------------------------------- + src/latencytop.8 | 4 - + src/latencytop.c | 2 - + src/latencytop.h | 3 - + src/latencytop.trans | 2 +- + src/text_display.c | 7 - + 7 files changed, 2 insertions(+), 387 deletions(-) + delete mode 100644 src/fsync.c + +diff --git a/src/Makefile b/src/Makefile +index de24551..7b6ff68 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -6,7 +6,7 @@ SBINDIR = /usr/sbin + XCFLAGS = -W -g `pkg-config --cflags glib-2.0` -D_FORTIFY_SOURCE=2 -Wno-sign-compare + LDF = -Wl,--as-needed `pkg-config --libs glib-2.0` -lncursesw + +-OBJS= latencytop.o text_display.o translate.o fsync.o ++OBJS= latencytop.o text_display.o translate.o + + ifdef HAS_GTK_GUI + XCFLAGS += `pkg-config --cflags gtk+-2.0` -DHAS_GTK_GUI +diff --git a/src/fsync.c b/src/fsync.c +deleted file mode 100644 +index 1706571..0000000 +--- a/src/fsync.c ++++ /dev/null +@@ -1,369 +0,0 @@ +-/* +- * Copyright 2008, Intel Corporation +- * +- * This file is part of LatencyTOP +- * +- * This program file is free software; you can redistribute it and/or modify it +- * under the terms of the GNU General Public License as published by the +- * Free Software Foundation; version 2 of the License. +- * +- * This program is distributed in the hope that it will be useful, but WITHOUT +- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +- * for more details. +- * +- * You should have received a copy of the GNU General Public License +- * along with this program in a file named COPYING; if not, write to the +- * Free Software Foundation, Inc., +- * 51 Franklin Street, Fifth Floor, +- * Boston, MA 02110-1301 USA +- * +- * Authors: +- * Arjan van de Ven +- */ +- +-#define _GNU_SOURCE +- +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +- +-#include +- +-#include "latencytop.h" +- +-struct fsync_process { +- char name[PATH_MAX]; +- int fsync_count; +- GList *files; +-}; +- +-struct fsync_files { +- char name[PATH_MAX]; +- int fsync_count; +-}; +- +-static GList *fsync_data; +- +- +-static chain_file(struct fsync_process *proc, char *filename) +-{ +- struct fsync_files *file; +- GList *item; +- +- proc->fsync_count++; +- item = proc->files; +- while (item) { +- file = item->data; +- item = g_list_next(item); +- if (strcmp(file->name, filename)==0) { +- file->fsync_count++; +- return; +- } +- } +- file = malloc(sizeof(struct fsync_files)); +- if (!file) +- return; +- memset(file, 0, sizeof(struct fsync_files)); +- strncpy(file->name, filename, PATH_MAX-1); +- file->fsync_count = 1; +- proc->files = g_list_append(proc->files, file); +-} +- +-static report_file(char *process, char *file) +-{ +- struct fsync_process *proc; +- GList *item; +- +- item = fsync_data; +- while (item) { +- proc = item->data; +- item = g_list_next(item); +- if (strcmp(proc->name, process) == 0) { +- chain_file(proc, file); +- return; +- } +- } +- +- proc = malloc(sizeof(struct fsync_process)); +- if (!proc) +- return; +- memset(proc, 0, sizeof(struct fsync_process)); +- strncpy(proc->name, process, PATH_MAX-1); +- chain_file(proc, file); +- fsync_data = g_list_append(fsync_data, proc); +-} +- +-static gint sort_files(gconstpointer A, gconstpointer B) +-{ +- struct fsync_files *a = (struct fsync_files *)A; +- struct fsync_files *b = (struct fsync_files *)B; +- return a->fsync_count < b->fsync_count; +-} +- +-static gint sort_process(gconstpointer A, gconstpointer B) +-{ +- struct fsync_process *a = (struct fsync_process *)A; +- struct fsync_process *b = (struct fsync_process *)B; +- return a->fsync_count < b->fsync_count; +-} +- +-static void sort_the_lot(void) +-{ +- GList *item; +- struct fsync_process *proc; +- +- item = fsync_data = g_list_sort(fsync_data, sort_process); +- while (item) { +- proc = item->data; +- item = g_list_next(item); +- proc->files = g_list_sort(proc->files, sort_files); +- } +-} +- +- +- +-static void write_to_file(char *filename, char *value) +-{ +- FILE *file; +- file = fopen(filename, "w"); +- if (!file) +- return; +- fprintf(file,"%s\n", value); +- fclose(file); +-} +- +- +-int enable_fsync_tracer(void) +-{ +- int ret; +-/* +- * Steps to do: +- * +- * mount -t debugfs none /sys/kernel/debug/ +- * cd /sys/kernel/debug/tracing +- * echo fsync > current_tracer +- * echo ftrace_printk > iter_ctrl +- * echo 1 > tracing_enabled +- */ +- ret = system("/bin/mount -t debugfs none /sys/kernel/debug/"); +- if (!ret) +- return -1; +- write_to_file("/sys/kernel/debug/tracing/current_tracer", "fsync"); +- write_to_file("/sys/kernel/debug/tracing/iter_ctrl", "ftrace_printk"); +- write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "1"); +-} +- +-int disable_fsync_tracer(void) +-{ +- write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "0"); +-} +- +- +-static WINDOW *title_bar_window; +-static WINDOW *global_window; +- +- +-static void fsync_cleanup_curses(void) +-{ +- endwin(); +-} +- +- +-static void zap_windows(void) +-{ +- if (title_bar_window) { +- delwin(title_bar_window); +- title_bar_window = NULL; +- } +- if (global_window) { +- delwin(global_window); +- global_window = NULL; +- } +-} +- +- +-static int maxx, maxy; +- +-static void fsync_setup_windows(void) +-{ +- int midy; +- getmaxyx(stdscr, maxy, maxx); +- +- zap_windows(); +- +- title_bar_window = subwin(stdscr, 1, maxx, 0, 0); +- global_window = subwin(stdscr, maxy-3 , maxx, 2, 0); +- +- werase(stdscr); +- refresh(); +-} +- +-#if 0 /* Dead code */ +-static void fsync_initialize_curses(void) +-{ +- if (noui) +- return; +- initscr(); +- start_color(); +- keypad(stdscr, TRUE); /* enable keyboard mapping */ +- nonl(); /* tell curses not to do NL->CR/NL on output */ +- cbreak(); /* take input chars one at a time, no wait for \n */ +- noecho(); /* dont echo input */ +- curs_set(0); /* turn off cursor */ +- use_default_colors(); +- +- init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); +- init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); +- init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); +- init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED); +- init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); +- init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); +- init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); +- +- atexit(cleanup_curses); +-} +-#endif +- +-static void show_title_bar(void) +-{ +- wattrset(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR)); +- wbkgd(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR)); +- werase(title_bar_window); +- +- mvwprintw(title_bar_window, 0, 0, " LatencyTOP -- fsync() view... type 'F' to exit"); +- +- wrefresh(title_bar_window); +-} +- +- +- +-static void print_global_list(void) +-{ +- GList *item, *item2; +- struct fsync_process *proc; +- struct fsync_files *file; +- int i = 1, i2 = 0; +- int y = 1; +- +- werase(global_window); +- +- +- mvwprintw(global_window, 0, 0, "Process File"); +- item = g_list_first(fsync_data); +- while (item && i < maxy-6) { +- proc = item->data; +- item = g_list_next(item); +- +- mvwprintw(global_window, y, 0, "%s (%i)", proc->name, proc->fsync_count); +- y++; +- item2 = proc->files; +- while (item2 && i2 < 5) { +- file = item2->data; +- item2 = g_list_next(item2); +- mvwprintw(global_window, y, 10, "%s (%i)", file->name, file->fsync_count); +- y++; +- i2++; +- } +- i++; +- y++; +- } +- wrefresh(global_window); +- +-} +- +-static void parse_ftrace(void) +-{ +- FILE *file; +- char line[PATH_MAX]; +- file = fopen("/sys/kernel/debug/tracing/trace", "r"); +- if (!file) +- return; +- while (!feof(file)) { +- char *c, *c2; +- memset(line, 0, PATH_MAX); +- fgets(line, PATH_MAX-1, file); +- c = strchr(line, '\n'); +- if (c) *c = 0; +- c = strstr(line, "probe_do_fsync: Process "); +- if (!c) +- continue; +- c += 24; +- c2 = strchr(c, ' '); +- if (!c2) +- continue; +- *c2 = 0; +- c2++; +- c2 = strstr(c2, "fsync on "); +- if (!c2) +- continue; +- c2 += 9; +- report_file(c, c2); +- } +- fclose(file); +- sort_the_lot(); +-} +- +- +-int fsync_display(int duration) +-{ +- struct timeval start,end,now; +- int key; +- fd_set rfds; +- int curduration; +- +- fsync_setup_windows(); +- show_title_bar(); +- curduration = 3; +- if (curduration > duration) +- curduration = duration; +- parse_ftrace(); +- print_global_list(); +- while (1) { +- FD_ZERO(&rfds); +- FD_SET(0, &rfds); +- gettimeofday(&start, NULL); +- gettimeofday(&now, NULL); +- end.tv_sec = start.tv_sec + curduration - now.tv_sec; +- end.tv_usec = start.tv_usec - now.tv_usec; +- while (end.tv_usec < 0) { +- end.tv_sec --; +- end.tv_usec += 1000000; +- }; +- curduration = duration; +- if (curduration > 5) +- curduration = 5; +- /* clear the ftrace buffer */ +- write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "0"); +- write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "1"); +- key = select(1, &rfds, NULL, NULL, &end); +- parse_ftrace(); +- print_global_list(); +- +- if (key) { +- char keychar; +- keychar = fgetc(stdin); +- if (keychar == 27) { +- keychar = fgetc(stdin); +- if (keychar==79) +- keychar = fgetc(stdin); +- } +- keychar = toupper(keychar); +- if (keychar == 'F') { +- fsync_cleanup_curses(); +- return 1; +- } +- if (keychar == 'Q') { +- fsync_cleanup_curses(); +- return 0; +- } +- } +- } +- +- return 1; +-} +diff --git a/src/latencytop.8 b/src/latencytop.8 +index db544a5..2165d12 100644 +--- a/src/latencytop.8 ++++ b/src/latencytop.8 +@@ -42,10 +42,6 @@ followed by a letter, then only active processes starting with that lettter + are displayed and walked. If you press \fBs\fP followed by \fB0\fP then + that filter is reset. + +-If you press \fBf\fP then \fBLatencyTop\fP displays a list of all processes +-currently waiting for an \fBfsync\fP to finish. Pressing \fBf\fP again +-returns you to the normal operating mode of \fBLatencyTop\fP. +- + .SH SEE ALSO + .BR powertop (1) + .br +diff --git a/src/latencytop.c b/src/latencytop.c +index f516f53..0ffb7f3 100644 +--- a/src/latencytop.c ++++ b/src/latencytop.c +@@ -532,7 +532,6 @@ void update_list(void) + static void cleanup_sysctl(void) + { + disable_sysctl(); +- disable_fsync_tracer(); + } + + int main(int argc, char **argv) +@@ -540,7 +539,6 @@ int main(int argc, char **argv) + int i, use_gtk = 0; + + enable_sysctl(); +- enable_fsync_tracer(); + atexit(cleanup_sysctl); + + #ifdef HAS_GTK_GUI +diff --git a/src/latencytop.h b/src/latencytop.h +index 79775ac..a4712c6 100644 +--- a/src/latencytop.h ++++ b/src/latencytop.h +@@ -53,7 +53,4 @@ extern void start_text_ui(void); + + extern char *translate(char *line); + extern void init_translations(char *filename); +-extern int fsync_display(int duration); +-extern int enable_fsync_tracer(void); +-extern int disable_fsync_tracer(void); + extern void update_list(void); +diff --git a/src/latencytop.trans b/src/latencytop.trans +index c7aa2d6..7516c7f 100644 +--- a/src/latencytop.trans ++++ b/src/latencytop.trans +@@ -142,5 +142,5 @@ + 5 sys_nanosleep Application requested delay + 5 sys_pause Application requested delay + 5 evdev_read Reading keyboard/mouse input +-5 do_fsync fsync() on a file (type 'F' for details) ++5 do_fsync fsync() on a file + 5 __log_wait_for_space Waiting for EXT3 journal space +diff --git a/src/text_display.c b/src/text_display.c +index a41b0b8..25ba68d 100644 +--- a/src/text_display.c ++++ b/src/text_display.c +@@ -378,13 +378,6 @@ static int update_display(int duration, char *filterchar) + else if (keychar == '0') + *filterchar = '\0'; + } +- if (keychar == 'F') { +- endwin(); +- if (!fsync_display(duration)) +- return 0; +- setup_windows(); +- show_title_bar(); +- } + if (keychar < 32) + repaint = 0; + } +-- +1.7.7.6 + diff --git a/latencytop.spec b/latencytop.spec index 1731c12..81ffe8b 100644 --- a/latencytop.spec +++ b/latencytop.spec @@ -1,6 +1,6 @@ Name: latencytop Version: 0.5 -Release: 6%{?dist} +Release: 7%{?dist} Summary: System latency monitor (with GUI) Group: Applications/System @@ -9,6 +9,8 @@ URL: http://www.latencytop.org/ Source0: http://www.latencytop.org/download/%{name}-%{version}.tar.gz Patch0: latencytop-Makefile-fixes.patch Patch1: latencytop-Makefile-default-to-no-gtk.patch +Patch2: latencytop-remove-the-fsync-view.patch +Patch3: latencytop-better-error-message-if-run-as-non-root.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: ncurses-devel glib2-devel gtk2-devel pkgconfig @@ -50,6 +52,8 @@ This package contains files needed by both the GUI and TUI builds of LatencyTOP. %setup -q %patch0 -p1 %patch1 -p1 +%patch2 -p2 +%patch3 -p2 %build @@ -82,6 +86,10 @@ rm -rf %{buildroot} %changelog +* Thu Feb 16 2012 Michal Schmidt - 0.5-7 +- Remove the broken fsync view, stop using the obsolete 'tracing_enabled'. +- Better error message when run as non-root. + * Thu Jan 26 2012 Michal Schmidt - 0.5-6 - Build both with and without GUI to allow the use on systems where Gtk dependency is undesirable. The latencytop package is still the full-blown build.