stats_timing.d revision 235063
1235063Snetchild#!/usr/sbin/dtrace -qs
2235063Snetchild
3235063Snetchild/*-
4235063Snetchild * Copyright (c) 2008-2012 Alexander Leidinger <netchild@FreeBSD.org>
5235063Snetchild * All rights reserved.
6235063Snetchild *
7235063Snetchild * Redistribution and use in source and binary forms, with or without
8235063Snetchild * modification, are permitted provided that the following conditions
9235063Snetchild * are met:
10235063Snetchild * 1. Redistributions of source code must retain the above copyright
11235063Snetchild *    notice, this list of conditions and the following disclaimer
12235063Snetchild *    in this position and unchanged.
13235063Snetchild * 2. Redistributions in binary form must reproduce the above copyright
14235063Snetchild *    notice, this list of conditions and the following disclaimer in the
15235063Snetchild *    documentation and/or other materials provided with the distribution.
16235063Snetchild *
17235063Snetchild * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18235063Snetchild * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19235063Snetchild * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20235063Snetchild * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21235063Snetchild * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22235063Snetchild * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23235063Snetchild * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24235063Snetchild * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25235063Snetchild * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26235063Snetchild * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27235063Snetchild *
28235063Snetchild * $FreeBSD: head/sys/compat/linux/stats_timing.d 235063 2012-05-05 19:42:38Z netchild $
29235063Snetchild */
30235063Snetchild
31235063Snetchild/**
32235063Snetchild * Some statistics (all per provider):
33235063Snetchild *  - number of calls to a function per executable binary (not per PID!)
34235063Snetchild *    - allows to see where an optimization would be beneficial for a given
35235063Snetchild *      application
36235063Snetchild *  - graph of CPU time spend in functions per executable binary
37235063Snetchild *    - together with the number of calls to this function this allows
38235063Snetchild *      to determine if a kernel optimization would be beneficial / is
39235063Snetchild *      possible for a given application
40235063Snetchild *  - graph of longest running (CPU-time!) function in total
41235063Snetchild *    - may help finding problem cases in the kernel code
42235063Snetchild * - timing statistics for the emul_lock
43235063Snetchild * - graph of longest held (CPU-time!) locks
44235063Snetchild */
45235063Snetchild
46235063Snetchild#pragma D option dynvarsize=32m
47235063Snetchild
48235063Snetchildlinuxulator*:::entry
49235063Snetchild{
50235063Snetchild	self->time[probefunc] = vtimestamp;
51235063Snetchild	@calls[probeprov, execname, probefunc] = count();
52235063Snetchild}
53235063Snetchild
54235063Snetchildlinuxulator*:::return
55235063Snetchild/self->time[probefunc] != 0/
56235063Snetchild{
57235063Snetchild	this->timediff = self->time[probefunc] - vtimestamp;
58235063Snetchild
59235063Snetchild	@stats[probeprov, execname, probefunc] = quantize(this->timediff);
60235063Snetchild	@longest[probeprov, probefunc] = max(this->timediff);
61235063Snetchild
62235063Snetchild	self->time[probefunc] = 0;
63235063Snetchild}
64235063Snetchild
65235063Snetchildlinuxulator*:::locked
66235063Snetchild{
67235063Snetchild	self->lock[arg0] = vtimestamp;
68235063Snetchild}
69235063Snetchild
70235063Snetchildlinuxulator*:::unlock
71235063Snetchild/self->lock[arg0] != 0/
72235063Snetchild{
73235063Snetchild	this->timediff = self->lock[arg0] - vtimestamp;
74235063Snetchild
75235063Snetchild	@lockstats[probefunc] = quantize(this->timediff);
76235063Snetchild	@longlock[probefunc] = max(this->timediff);
77235063Snetchild
78235063Snetchild	self->lock[arg0] = 0;
79235063Snetchild}
80235063Snetchild
81235063SnetchildEND
82235063Snetchild{
83235063Snetchild	printf("Number of calls per provider/application/kernel function:");
84235063Snetchild	printa(@calls);
85235063Snetchild	printf("CPU-timing statistics per provider/application/kernel function (in ns):");
86235063Snetchild	printa(@stats);
87235063Snetchild	printf("Longest running (CPU-time!) functions per provider (in ns):");
88235063Snetchild	printa(@longest);
89235063Snetchild	printf("Lock CPU-timing statistics:");
90235063Snetchild	printa(@lockstats);
91235063Snetchild	printf("Longest running (CPU-time!) locks:");
92235063Snetchild	printa(@longlock);
93235063Snetchild}
94235063Snetchild
95