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