Blame SOURCES/latencytop-remove-the-fsync-view.patch

b7fac5
From a4a1eb20492773d48bd83087157149c5fb9a257a Mon Sep 17 00:00:00 2001
b7fac5
From: Michal Schmidt <mschmidt@redhat.com>
b7fac5
Date: Wed, 15 Feb 2012 23:44:18 +0100
b7fac5
Subject: [PATCH 1/2] remove the fsync view
b7fac5
b7fac5
The fsync tracer it depends on was never merged in the kernel.
b7fac5
It also uses 'tracing_enable' which triggers deprecation warnings in the
b7fac5
kernel.
b7fac5
---
b7fac5
 src/Makefile         |    2 +-
b7fac5
 src/fsync.c          |  369 --------------------------------------------------
b7fac5
 src/latencytop.8     |    4 -
b7fac5
 src/latencytop.c     |    2 -
b7fac5
 src/latencytop.h     |    3 -
b7fac5
 src/latencytop.trans |    2 +-
b7fac5
 src/text_display.c   |    7 -
b7fac5
 7 files changed, 2 insertions(+), 387 deletions(-)
b7fac5
 delete mode 100644 src/fsync.c
b7fac5
b7fac5
diff --git a/src/Makefile b/src/Makefile
b7fac5
index de24551..7b6ff68 100644
b7fac5
--- a/src/Makefile
b7fac5
+++ b/src/Makefile
b7fac5
@@ -6,7 +6,7 @@ SBINDIR = /usr/sbin
b7fac5
 XCFLAGS = -W  -g `pkg-config --cflags glib-2.0` -D_FORTIFY_SOURCE=2 -Wno-sign-compare
b7fac5
 LDF = -Wl,--as-needed `pkg-config --libs glib-2.0`   -lncursesw 
b7fac5
 
b7fac5
-OBJS= latencytop.o text_display.o translate.o fsync.o
b7fac5
+OBJS= latencytop.o text_display.o translate.o
b7fac5
 
b7fac5
 ifdef HAS_GTK_GUI
b7fac5
   XCFLAGS += `pkg-config --cflags gtk+-2.0` -DHAS_GTK_GUI
b7fac5
diff --git a/src/fsync.c b/src/fsync.c
b7fac5
deleted file mode 100644
b7fac5
index 1706571..0000000
b7fac5
--- a/src/fsync.c
b7fac5
+++ /dev/null
b7fac5
@@ -1,369 +0,0 @@
b7fac5
-/*
b7fac5
- * Copyright 2008, Intel Corporation
b7fac5
- *
b7fac5
- * This file is part of LatencyTOP
b7fac5
- *
b7fac5
- * This program file is free software; you can redistribute it and/or modify it
b7fac5
- * under the terms of the GNU General Public License as published by the
b7fac5
- * Free Software Foundation; version 2 of the License.
b7fac5
- *
b7fac5
- * This program is distributed in the hope that it will be useful, but WITHOUT
b7fac5
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7fac5
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b7fac5
- * for more details.
b7fac5
- *
b7fac5
- * You should have received a copy of the GNU General Public License
b7fac5
- * along with this program in a file named COPYING; if not, write to the
b7fac5
- * Free Software Foundation, Inc.,
b7fac5
- * 51 Franklin Street, Fifth Floor,
b7fac5
- * Boston, MA 02110-1301 USA
b7fac5
- *
b7fac5
- * Authors:
b7fac5
- * 	Arjan van de Ven <arjan@linux.intel.com>
b7fac5
- */
b7fac5
-
b7fac5
-#define _GNU_SOURCE
b7fac5
-
b7fac5
-#include <stdio.h>
b7fac5
-#include <stdlib.h>
b7fac5
-#include <unistd.h>
b7fac5
-#include <string.h>
b7fac5
-#include <ncurses.h>
b7fac5
-#include <time.h>
b7fac5
-#include <wchar.h>
b7fac5
-#include <ctype.h>
b7fac5
-
b7fac5
-#include <glib.h>
b7fac5
-
b7fac5
-#include "latencytop.h"
b7fac5
-
b7fac5
-struct fsync_process { 
b7fac5
-	char name[PATH_MAX];
b7fac5
-	int fsync_count;
b7fac5
-	GList *files;
b7fac5
-};
b7fac5
-
b7fac5
-struct fsync_files {
b7fac5
-	char name[PATH_MAX];
b7fac5
-	int fsync_count;
b7fac5
-};
b7fac5
-
b7fac5
-static GList *fsync_data;
b7fac5
-
b7fac5
-
b7fac5
-static chain_file(struct fsync_process *proc, char *filename)
b7fac5
-{
b7fac5
-	struct fsync_files *file;
b7fac5
-	GList *item;
b7fac5
-
b7fac5
-	proc->fsync_count++;
b7fac5
-	item = proc->files;
b7fac5
-	while (item) {
b7fac5
-		file = item->data;
b7fac5
-		item = g_list_next(item);
b7fac5
-		if (strcmp(file->name, filename)==0) {
b7fac5
-			file->fsync_count++;
b7fac5
-			return;
b7fac5
-		}
b7fac5
-	}
b7fac5
-	file = malloc(sizeof(struct fsync_files));
b7fac5
-	if (!file)
b7fac5
-		return;
b7fac5
-	memset(file, 0, sizeof(struct fsync_files));
b7fac5
-	strncpy(file->name, filename, PATH_MAX-1);
b7fac5
-	file->fsync_count = 1;
b7fac5
-	proc->files = g_list_append(proc->files, file);
b7fac5
-}
b7fac5
-
b7fac5
-static report_file(char *process, char *file)
b7fac5
-{
b7fac5
-	struct fsync_process *proc;
b7fac5
-	GList *item;
b7fac5
-
b7fac5
-	item = fsync_data;
b7fac5
-	while (item) {
b7fac5
-		proc = item->data;
b7fac5
-		item = g_list_next(item);
b7fac5
-		if (strcmp(proc->name, process) == 0) {
b7fac5
-			chain_file(proc, file);
b7fac5
-			return;
b7fac5
-		}
b7fac5
-	}
b7fac5
-
b7fac5
-	proc = malloc(sizeof(struct fsync_process));
b7fac5
-	if (!proc)
b7fac5
-		return;
b7fac5
-	memset(proc, 0, sizeof(struct fsync_process));
b7fac5
-	strncpy(proc->name, process, PATH_MAX-1);
b7fac5
-	chain_file(proc, file);
b7fac5
-	fsync_data = g_list_append(fsync_data, proc);
b7fac5
-}
b7fac5
-
b7fac5
-static gint sort_files(gconstpointer A, gconstpointer B)
b7fac5
-{
b7fac5
-	struct fsync_files *a = (struct fsync_files *)A;
b7fac5
-	struct fsync_files *b = (struct fsync_files *)B;
b7fac5
-	return a->fsync_count < b->fsync_count;
b7fac5
-}
b7fac5
-
b7fac5
-static gint sort_process(gconstpointer A, gconstpointer B)
b7fac5
-{
b7fac5
-	struct fsync_process *a = (struct fsync_process *)A;
b7fac5
-	struct fsync_process *b = (struct fsync_process *)B;
b7fac5
-	return a->fsync_count < b->fsync_count;
b7fac5
-}
b7fac5
-
b7fac5
-static void sort_the_lot(void)
b7fac5
-{
b7fac5
-	GList *item;
b7fac5
-	struct fsync_process *proc;
b7fac5
-
b7fac5
-	item = fsync_data = g_list_sort(fsync_data, sort_process);
b7fac5
-	while (item) {
b7fac5
-		proc = item->data;
b7fac5
-		item = g_list_next(item);
b7fac5
-		proc->files = g_list_sort(proc->files, sort_files);
b7fac5
-	}
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-
b7fac5
-static void write_to_file(char *filename, char *value)
b7fac5
-{
b7fac5
-	FILE *file;
b7fac5
-	file = fopen(filename, "w");
b7fac5
-	if (!file)
b7fac5
-		return;
b7fac5
-	fprintf(file,"%s\n", value);
b7fac5
-	fclose(file);
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-int enable_fsync_tracer(void)
b7fac5
-{
b7fac5
-	int ret;
b7fac5
-/*
b7fac5
- * Steps to do:
b7fac5
- *
b7fac5
- * mount -t debugfs none /sys/kernel/debug/
b7fac5
- * cd /sys/kernel/debug/tracing
b7fac5
- * echo fsync > current_tracer
b7fac5
- * echo ftrace_printk > iter_ctrl 
b7fac5
- * echo 1 > tracing_enabled
b7fac5
- */
b7fac5
-	ret = system("/bin/mount -t debugfs none /sys/kernel/debug/");
b7fac5
-	if (!ret) 
b7fac5
-		return -1;
b7fac5
-	write_to_file("/sys/kernel/debug/tracing/current_tracer", "fsync");	
b7fac5
-	write_to_file("/sys/kernel/debug/tracing/iter_ctrl", "ftrace_printk");	
b7fac5
-	write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "1");
b7fac5
-}
b7fac5
-
b7fac5
-int disable_fsync_tracer(void)
b7fac5
-{
b7fac5
-	write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "0");
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-static WINDOW *title_bar_window;
b7fac5
-static WINDOW *global_window;
b7fac5
-
b7fac5
-
b7fac5
-static void fsync_cleanup_curses(void) 
b7fac5
-{
b7fac5
-	endwin();
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-static void zap_windows(void)
b7fac5
-{
b7fac5
-	if (title_bar_window) {
b7fac5
-		delwin(title_bar_window);
b7fac5
-		title_bar_window = NULL;
b7fac5
-	}
b7fac5
-	if (global_window) {
b7fac5
-		delwin(global_window);
b7fac5
-		global_window = NULL;
b7fac5
-	}
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-static int maxx, maxy;
b7fac5
-
b7fac5
-static void fsync_setup_windows(void) 
b7fac5
-{
b7fac5
-	int midy;
b7fac5
-	getmaxyx(stdscr, maxy, maxx);
b7fac5
-
b7fac5
-	zap_windows();	
b7fac5
-
b7fac5
-	title_bar_window = subwin(stdscr, 1, maxx, 0, 0);
b7fac5
-	global_window = subwin(stdscr, maxy-3 , maxx, 2, 0);
b7fac5
-
b7fac5
-	werase(stdscr);
b7fac5
-	refresh();
b7fac5
-}
b7fac5
-
b7fac5
-#if 0 /* Dead code */
b7fac5
-static void fsync_initialize_curses(void) 
b7fac5
-{
b7fac5
-	if (noui)
b7fac5
-		return;
b7fac5
-	initscr();
b7fac5
-	start_color();
b7fac5
-	keypad(stdscr, TRUE);	/* enable keyboard mapping */
b7fac5
-	nonl();			/* tell curses not to do NL->CR/NL on output */
b7fac5
-	cbreak();		/* take input chars one at a time, no wait for \n */
b7fac5
-	noecho();		/* dont echo input */
b7fac5
-	curs_set(0);		/* turn off cursor */
b7fac5
-	use_default_colors();
b7fac5
-
b7fac5
-	init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
b7fac5
-	init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
b7fac5
-	init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
b7fac5
-	init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
b7fac5
-	init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
b7fac5
-	init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
b7fac5
-	init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
b7fac5
-	
b7fac5
-	atexit(cleanup_curses);
b7fac5
-}
b7fac5
-#endif
b7fac5
-
b7fac5
-static void show_title_bar(void) 
b7fac5
-{
b7fac5
-	wattrset(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR));
b7fac5
-	wbkgd(title_bar_window, COLOR_PAIR(PT_COLOR_HEADER_BAR));   
b7fac5
-	werase(title_bar_window);
b7fac5
-
b7fac5
-	mvwprintw(title_bar_window, 0, 0,  "   LatencyTOP -- fsync() view... type 'F' to exit");
b7fac5
-
b7fac5
-	wrefresh(title_bar_window);
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-
b7fac5
-static void print_global_list(void)
b7fac5
-{
b7fac5
-	GList *item, *item2;
b7fac5
-	struct fsync_process *proc;
b7fac5
-	struct fsync_files *file;
b7fac5
-	int i = 1, i2 = 0;
b7fac5
-	int y = 1;
b7fac5
-
b7fac5
-	werase(global_window);
b7fac5
-
b7fac5
-
b7fac5
-	mvwprintw(global_window, 0, 0, "Process        File");
b7fac5
-	item = g_list_first(fsync_data);
b7fac5
-	while (item && i < maxy-6) {
b7fac5
-		proc = item->data;
b7fac5
-		item = g_list_next(item);
b7fac5
-		
b7fac5
-		mvwprintw(global_window, y, 0, "%s (%i)", proc->name, proc->fsync_count);
b7fac5
-		y++;
b7fac5
-		item2 = proc->files;
b7fac5
-		while (item2 && i2 < 5) {
b7fac5
-			file = item2->data;
b7fac5
-			item2 = g_list_next(item2);
b7fac5
-			mvwprintw(global_window, y, 10, "%s (%i)", file->name, file->fsync_count);
b7fac5
-			y++;
b7fac5
-			i2++;
b7fac5
-		}
b7fac5
-		i++;
b7fac5
-		y++;
b7fac5
-	}
b7fac5
-	wrefresh(global_window);
b7fac5
-
b7fac5
-}
b7fac5
-
b7fac5
-static void parse_ftrace(void)
b7fac5
-{
b7fac5
-	FILE *file;
b7fac5
-	char line[PATH_MAX];
b7fac5
-	file = fopen("/sys/kernel/debug/tracing/trace", "r");
b7fac5
-	if (!file)
b7fac5
-		return;
b7fac5
-	while (!feof(file)) {
b7fac5
-		char *c, *c2;
b7fac5
-		memset(line, 0, PATH_MAX);
b7fac5
-		fgets(line, PATH_MAX-1, file);
b7fac5
-		c = strchr(line, '\n');
b7fac5
-		if (c) *c = 0;
b7fac5
-		c = strstr(line, "probe_do_fsync: Process ");
b7fac5
-		if (!c)
b7fac5
-			continue;
b7fac5
-		c += 24;
b7fac5
-		c2 = strchr(c, ' ');
b7fac5
-		if (!c2)
b7fac5
-			continue;
b7fac5
-		*c2 = 0;
b7fac5
-		c2++;
b7fac5
-		c2 = strstr(c2, "fsync on ");
b7fac5
-		if (!c2)
b7fac5
-			continue;
b7fac5
-		c2 += 9;
b7fac5
-		report_file(c, c2);
b7fac5
-	}
b7fac5
-	fclose(file);
b7fac5
-	sort_the_lot();
b7fac5
-}
b7fac5
-
b7fac5
-
b7fac5
-int fsync_display(int duration)
b7fac5
-{
b7fac5
-	struct timeval start,end,now;
b7fac5
-	int key;
b7fac5
-	fd_set rfds;
b7fac5
-	int curduration;
b7fac5
-
b7fac5
-	fsync_setup_windows();
b7fac5
-	show_title_bar();
b7fac5
-	curduration = 3;
b7fac5
-	if (curduration > duration)
b7fac5
-		curduration = duration;
b7fac5
-	parse_ftrace();
b7fac5
-	print_global_list();
b7fac5
-	while (1) {
b7fac5
-		FD_ZERO(&rfds);
b7fac5
-		FD_SET(0, &rfds);
b7fac5
-		gettimeofday(&start, NULL);
b7fac5
-		gettimeofday(&now, NULL);
b7fac5
-		end.tv_sec = start.tv_sec + curduration - now.tv_sec;
b7fac5
-		end.tv_usec = start.tv_usec - now.tv_usec;
b7fac5
-		while (end.tv_usec < 0) {
b7fac5
-			end.tv_sec --;
b7fac5
-			end.tv_usec += 1000000;
b7fac5
-		};
b7fac5
-		curduration = duration;
b7fac5
-		if (curduration > 5)
b7fac5
-			curduration = 5;
b7fac5
-		/* clear the ftrace buffer */
b7fac5
-		write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "0");
b7fac5
-		write_to_file("/sys/kernel/debug/tracing/tracing_enabled", "1");
b7fac5
-		key = select(1, &rfds, NULL, NULL, &end;;
b7fac5
-		parse_ftrace();
b7fac5
-		print_global_list();
b7fac5
-
b7fac5
-		if (key) {
b7fac5
-			char keychar;
b7fac5
-			keychar = fgetc(stdin);		
b7fac5
-			if (keychar == 27) {
b7fac5
-				keychar = fgetc(stdin);	
b7fac5
-				if (keychar==79)
b7fac5
-					keychar = fgetc(stdin);	
b7fac5
-			}
b7fac5
-			keychar = toupper(keychar);
b7fac5
-			if (keychar == 'F') {
b7fac5
-				fsync_cleanup_curses();
b7fac5
-				return 1;
b7fac5
-			}
b7fac5
-			if (keychar == 'Q') {
b7fac5
-				fsync_cleanup_curses();
b7fac5
-				return 0;
b7fac5
-			}
b7fac5
-		}
b7fac5
-	}
b7fac5
-
b7fac5
-	return 1;
b7fac5
-}
b7fac5
diff --git a/src/latencytop.8 b/src/latencytop.8
b7fac5
index db544a5..2165d12 100644
b7fac5
--- a/src/latencytop.8
b7fac5
+++ b/src/latencytop.8
b7fac5
@@ -42,10 +42,6 @@ followed by a letter, then only active processes starting with that lettter
b7fac5
 are displayed and walked. If you press \fBs\fP followed by \fB0\fP then
b7fac5
 that filter is reset.
b7fac5
 
b7fac5
-If you press \fBf\fP then \fBLatencyTop\fP displays a list of all processes
b7fac5
-currently waiting for an \fBfsync\fP to finish. Pressing \fBf\fP again
b7fac5
-returns you to the normal operating mode of \fBLatencyTop\fP.
b7fac5
-
b7fac5
 .SH SEE ALSO
b7fac5
 .BR powertop (1)
b7fac5
 .br
b7fac5
diff --git a/src/latencytop.c b/src/latencytop.c
b7fac5
index f516f53..0ffb7f3 100644
b7fac5
--- a/src/latencytop.c
b7fac5
+++ b/src/latencytop.c
b7fac5
@@ -532,7 +532,6 @@ void update_list(void)
b7fac5
 static void cleanup_sysctl(void) 
b7fac5
 {
b7fac5
 	disable_sysctl();
b7fac5
-	disable_fsync_tracer();
b7fac5
 }
b7fac5
 
b7fac5
 int main(int argc, char **argv)
b7fac5
@@ -540,7 +539,6 @@ int main(int argc, char **argv)
b7fac5
 	int i, use_gtk = 0;
b7fac5
 
b7fac5
 	enable_sysctl();
b7fac5
-	enable_fsync_tracer();
b7fac5
 	atexit(cleanup_sysctl);
b7fac5
 
b7fac5
 #ifdef HAS_GTK_GUI
b7fac5
diff --git a/src/latencytop.h b/src/latencytop.h
b7fac5
index 79775ac..a4712c6 100644
b7fac5
--- a/src/latencytop.h
b7fac5
+++ b/src/latencytop.h
b7fac5
@@ -53,7 +53,4 @@ extern void start_text_ui(void);
b7fac5
 
b7fac5
 extern char *translate(char *line);
b7fac5
 extern void init_translations(char *filename);
b7fac5
-extern int fsync_display(int duration);
b7fac5
-extern int enable_fsync_tracer(void);
b7fac5
-extern int disable_fsync_tracer(void);
b7fac5
 extern void update_list(void);
b7fac5
diff --git a/src/latencytop.trans b/src/latencytop.trans
b7fac5
index c7aa2d6..7516c7f 100644
b7fac5
--- a/src/latencytop.trans
b7fac5
+++ b/src/latencytop.trans
b7fac5
@@ -142,5 +142,5 @@
b7fac5
 5	sys_nanosleep		Application requested delay
b7fac5
 5	sys_pause		Application requested delay
b7fac5
 5	evdev_read		Reading keyboard/mouse input
b7fac5
-5	do_fsync		fsync() on a file (type 'F' for details)
b7fac5
+5	do_fsync		fsync() on a file
b7fac5
 5	__log_wait_for_space	Waiting for EXT3 journal space
b7fac5
diff --git a/src/text_display.c b/src/text_display.c
b7fac5
index a41b0b8..25ba68d 100644
b7fac5
--- a/src/text_display.c
b7fac5
+++ b/src/text_display.c
b7fac5
@@ -378,13 +378,6 @@ static int update_display(int duration, char *filterchar)
b7fac5
 				else if (keychar == '0')
b7fac5
 					*filterchar = '\0';
b7fac5
 			}
b7fac5
-			if (keychar == 'F') {
b7fac5
-				endwin();
b7fac5
-				if (!fsync_display(duration))
b7fac5
-					return 0;
b7fac5
-				setup_windows();
b7fac5
-				show_title_bar();
b7fac5
-			}
b7fac5
 			if (keychar < 32)
b7fac5
 				repaint = 0;
b7fac5
 		}
b7fac5
-- 
b7fac5
1.7.7.6
b7fac5