%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/usr/share/doc/systemtap-client-2.9/examples/lwtools/
Upload File :
Create Path :
Current File : //proc/self/root/usr/share/doc/systemtap-client-2.9/examples/lwtools/fsslower-nd.stp

#!/usr/bin/stap
/*
 * fslower-nd.stp	Trace slow file system sync reads and writes.
 *			For Linux, uses SystemTap (non-debuginfo).
 *
 * USAGE: ./fsslower-nd.stp [min_ms]
 *
 * This script uses kernel dynamic tracing of two common file system functions:
 * do_sync_read() and do_sync_write(). This provides a view of just two file
 * system request types. There are typically many others: asynchronous I/O,
 * directory operations, file handle operations, etc, that this script does
 * not instrument.
 *
 * By default, a minimum millisecond threshold of 10 is used.
 *
 * From systemtap-lwtools: https://github.com/brendangregg/systemtap-lwtools
 *
 * See the corresponding man page (in systemtap-lwtools) for more info.
 *
 * Copyright (C) 2015 Brendan Gregg.
 *
 * This program 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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.
 *
 * 06-Feb-2015	Brendan Gregg	Created this.
 */

global ts[65536];	# 65536 is max concurrent I/O
global sz[65536];	# "
global min_ms = 10;

probe begin
{
	if (argv_1 != "") {
		min_ms = strtol(argv_1, 10);
	}
	printf("Tracing FS sync reads and writes slower than %d ms...", min_ms);
	printf(" Hit Ctrl-C to end.\n");
	printf("%-8s %-6s %-16s %-14s %-7s %8s\n", "TIME", "PID", "COMM",
	    "FUNC", "SIZE", "LAT(ms)");
}

function hhmmss() {
	return substr(ctime(gettimeofday_s()), 11, 8);
}

probe kprobe.function("do_sync_read"),
    kprobe.function("do_sync_write")
{
	sz[tid()] = int_arg(3);
	ts[tid()] = gettimeofday_ns();
}

probe kprobe.function("sock_aio_write")
{
	/* not a file system write */
	sz[tid()] = 0;
	ts[tid()] = 0;
}

probe kprobe.function("do_sync_read").return,
    kprobe.function("do_sync_write").return
{
	if (ts[tid()]) {
		lat = (gettimeofday_ns() - ts[tid()]) / 1000000;
		if (lat >= min_ms) {
			printf("%-8s %-6d %-16s %-14s %-7d %8d\n", hhmmss(),
			    pid(), execname(), ppfunc(), sz[tid()], lat);
		}
		delete sz[tid()];
		delete ts[tid()];
	}
}

Zerion Mini Shell 1.0