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