xref: /titanic_41/usr/src/cmd/latencytop/common/latencytop.d (revision a9c12afde877c596eed286ac3f1d518246e5cd1e)
115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
215db2897SKrishnendu Sadhukhan - Sun Microsystems  * CDDL HEADER START
315db2897SKrishnendu Sadhukhan - Sun Microsystems  *
415db2897SKrishnendu Sadhukhan - Sun Microsystems  * The contents of this file are subject to the terms of the
515db2897SKrishnendu Sadhukhan - Sun Microsystems  * Common Development and Distribution License (the "License").
615db2897SKrishnendu Sadhukhan - Sun Microsystems  * You may not use this file except in compliance with the License.
715db2897SKrishnendu Sadhukhan - Sun Microsystems  *
815db2897SKrishnendu Sadhukhan - Sun Microsystems  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
915db2897SKrishnendu Sadhukhan - Sun Microsystems  * or http://www.opensolaris.org/os/licensing.
1015db2897SKrishnendu Sadhukhan - Sun Microsystems  * See the License for the specific language governing permissions
1115db2897SKrishnendu Sadhukhan - Sun Microsystems  * and limitations under the License.
1215db2897SKrishnendu Sadhukhan - Sun Microsystems  *
1315db2897SKrishnendu Sadhukhan - Sun Microsystems  * When distributing Covered Code, include this CDDL HEADER in each
1415db2897SKrishnendu Sadhukhan - Sun Microsystems  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1515db2897SKrishnendu Sadhukhan - Sun Microsystems  * If applicable, add the following below this CDDL HEADER, with the
1615db2897SKrishnendu Sadhukhan - Sun Microsystems  * fields enclosed by brackets "[]" replaced with your own identifying
1715db2897SKrishnendu Sadhukhan - Sun Microsystems  * information: Portions Copyright [yyyy] [name of copyright owner]
1815db2897SKrishnendu Sadhukhan - Sun Microsystems  *
1915db2897SKrishnendu Sadhukhan - Sun Microsystems  * CDDL HEADER END
2015db2897SKrishnendu Sadhukhan - Sun Microsystems  */
2115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
2215db2897SKrishnendu Sadhukhan - Sun Microsystems  * Copyright (c) 2008-2009, Intel Corporation.
2315db2897SKrishnendu Sadhukhan - Sun Microsystems  * All Rights Reserved.
2415db2897SKrishnendu Sadhukhan - Sun Microsystems  */
2515db2897SKrishnendu Sadhukhan - Sun Microsystems 
2615db2897SKrishnendu Sadhukhan - Sun Microsystems #define	MAX_TAG		8
2715db2897SKrishnendu Sadhukhan - Sun Microsystems #define	MAX_STACK	64
2815db2897SKrishnendu Sadhukhan - Sun Microsystems 
2915db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option aggsize=8m
3015db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option bufsize=16m
3115db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option dynvarsize=16m
3215db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option aggrate=0
3315db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option stackframes=MAX_STACK
3415db2897SKrishnendu Sadhukhan - Sun Microsystems /*
3515db2897SKrishnendu Sadhukhan - Sun Microsystems  * Our D script needs to compile even if some of the TRANSLATE probes cannot
3615db2897SKrishnendu Sadhukhan - Sun Microsystems  * be found. Missing probes can be caused by older kernel, different
3715db2897SKrishnendu Sadhukhan - Sun Microsystems  * architecture, unloaded modules etc.
3815db2897SKrishnendu Sadhukhan - Sun Microsystems  */
3915db2897SKrishnendu Sadhukhan - Sun Microsystems #pragma D option zdefs
4015db2897SKrishnendu Sadhukhan - Sun Microsystems 
4115db2897SKrishnendu Sadhukhan - Sun Microsystems #if defined(ENABLE_SCHED)
42*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #if defined(TRACE_PID)
43*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER    / pid == 0 || pid == TRACE_PID /
44*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)    / (pid == 0 || pid == TRACE_PID) && (a) /
45*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #elif defined(TRACE_PGID)
46*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER    / pid == 0 || curpsinfo->pr_pgid == TRACE_PGID /
47*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)
48*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems     / (pid == 0 || curpsinfo->pr_pgid == TRACE_PGID) && (a) /
49*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #else
5015db2897SKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER
5115db2897SKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)	/ (a) /
52*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #endif
53*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #else	/* ENABLE_SCHED */
54*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #if defined(TRACE_PID)
55*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER    / pid == TRACE_PID /
56*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)    / (pid == TRACE_PID) && (a) /
57*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #elif defined(TRACE_PGID)
58*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER    / curpsinfo->pr_pgid == TRACE_PGID /
59*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)    / (curpsinfo->pr_pgid == TRACE_PGID) && (a) /
6015db2897SKrishnendu Sadhukhan - Sun Microsystems #else
6115db2897SKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER	/ pid != 0 /
62*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #define TRACE_FILTER_COND(a)    / (pid != 0) && (a) /
6315db2897SKrishnendu Sadhukhan - Sun Microsystems #endif
64*a9c12afdSKrishnendu Sadhukhan - Sun Microsystems #endif /* ENABLE_SCHED */
6515db2897SKrishnendu Sadhukhan - Sun Microsystems 
6615db2897SKrishnendu Sadhukhan - Sun Microsystems /* Threshold to filter WAKEABLE latencies. */
6715db2897SKrishnendu Sadhukhan - Sun Microsystems #define FILTER_THRESHOLD	5000000
6815db2897SKrishnendu Sadhukhan - Sun Microsystems /* From thread.h */
6915db2897SKrishnendu Sadhukhan - Sun Microsystems #define T_WAKEABLE		2
7015db2897SKrishnendu Sadhukhan - Sun Microsystems 
7115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
7215db2897SKrishnendu Sadhukhan - Sun Microsystems  * This array is used to store timestamp of when threads are enqueued
7315db2897SKrishnendu Sadhukhan - Sun Microsystems  * to dispatch queue.
7415db2897SKrishnendu Sadhukhan - Sun Microsystems  * self-> is not accessible when enqueue happens.
7515db2897SKrishnendu Sadhukhan - Sun Microsystems  */
7615db2897SKrishnendu Sadhukhan - Sun Microsystems unsigned long long lt_timestamps[int, int];
7715db2897SKrishnendu Sadhukhan - Sun Microsystems 
7815db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned int lt_is_block_wakeable;
7915db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned long long lt_sleep_start;
8015db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned long long lt_sleep_duration;
8115db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned long long lt_sch_delay;
8215db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned int lt_counter;		/* only used in low overhead */
8315db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned long long lt_timestamp;	/* only used in low overhead */
8415db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned int lt_stackp;
8515db2897SKrishnendu Sadhukhan - Sun Microsystems self unsigned int lt_prio[int];
8615db2897SKrishnendu Sadhukhan - Sun Microsystems self string lt_cause[int];
8715db2897SKrishnendu Sadhukhan - Sun Microsystems 
8815db2897SKrishnendu Sadhukhan - Sun Microsystems this unsigned int priority;
8915db2897SKrishnendu Sadhukhan - Sun Microsystems this string cause;
9015db2897SKrishnendu Sadhukhan - Sun Microsystems 
9115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
9215db2897SKrishnendu Sadhukhan - Sun Microsystems  * Clean up everything, otherwise we will run out of memory.
9315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
9415db2897SKrishnendu Sadhukhan - Sun Microsystems proc:::lwp-exit
9515db2897SKrishnendu Sadhukhan - Sun Microsystems {
9615db2897SKrishnendu Sadhukhan - Sun Microsystems 	lt_timestamps[curpsinfo->pr_pid, curlwpsinfo->pr_lwpid] = 0;
9715db2897SKrishnendu Sadhukhan - Sun Microsystems 
9815db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_start = 0;
9915db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = 0;
10015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_counter = 0;
10115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = 0;
10215db2897SKrishnendu Sadhukhan - Sun Microsystems 
10315db2897SKrishnendu Sadhukhan - Sun Microsystems 	/*
10415db2897SKrishnendu Sadhukhan - Sun Microsystems 	 * Workaround: no way to clear associative array.
10515db2897SKrishnendu Sadhukhan - Sun Microsystems 	 * We have to manually clear 0 ~ (MAX_TAG-1).
10615db2897SKrishnendu Sadhukhan - Sun Microsystems 	 */
10715db2897SKrishnendu Sadhukhan - Sun Microsystems 
10815db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[0] = 0;
10915db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[1] = 0;
11015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[2] = 0;
11115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[3] = 0;
11215db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[4] = 0;
11315db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[5] = 0;
11415db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[6] = 0;
11515db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[7] = 0;
11615db2897SKrishnendu Sadhukhan - Sun Microsystems 
11715db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[0] = 0;
11815db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[1] = 0;
11915db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[2] = 0;
12015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[3] = 0;
12115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[4] = 0;
12215db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[5] = 0;
12315db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[6] = 0;
12415db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[7] = 0;
12515db2897SKrishnendu Sadhukhan - Sun Microsystems }
12615db2897SKrishnendu Sadhukhan - Sun Microsystems 
12715db2897SKrishnendu Sadhukhan - Sun Microsystems #if !defined(ENABLE_LOW_OVERHEAD)
12815db2897SKrishnendu Sadhukhan - Sun Microsystems /*
12915db2897SKrishnendu Sadhukhan - Sun Microsystems  * Log timestamp when a thread is taken off the CPU.
13015db2897SKrishnendu Sadhukhan - Sun Microsystems  */
13115db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:off-cpu
13215db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER_COND(curlwpsinfo->pr_state == SSLEEP)
13315db2897SKrishnendu Sadhukhan - Sun Microsystems {
13415db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_start = timestamp;
13515db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = curthread->t_flag & T_WAKEABLE;
13615db2897SKrishnendu Sadhukhan - Sun Microsystems 
13715db2897SKrishnendu Sadhukhan - Sun Microsystems 	lt_timestamps[curpsinfo->pr_pid, curlwpsinfo->pr_lwpid] =
13815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_sleep_start;
13915db2897SKrishnendu Sadhukhan - Sun Microsystems }
14015db2897SKrishnendu Sadhukhan - Sun Microsystems 
14115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
14215db2897SKrishnendu Sadhukhan - Sun Microsystems  * Log timestamp when a thread is put on a dispatch queue and becomes runnable.
14315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
14415db2897SKrishnendu Sadhukhan - Sun Microsystems sched:::enqueue
14515db2897SKrishnendu Sadhukhan - Sun Microsystems /lt_timestamps[args[1]->pr_pid, args[0]->pr_lwpid] != 0/
14615db2897SKrishnendu Sadhukhan - Sun Microsystems {
14715db2897SKrishnendu Sadhukhan - Sun Microsystems 	lt_timestamps[args[1]->pr_pid, args[0]->pr_lwpid] = timestamp;
14815db2897SKrishnendu Sadhukhan - Sun Microsystems }
14915db2897SKrishnendu Sadhukhan - Sun Microsystems 
15015db2897SKrishnendu Sadhukhan - Sun Microsystems /*
15115db2897SKrishnendu Sadhukhan - Sun Microsystems  * Calculate latency when the thread is actually on the CPU.
15215db2897SKrishnendu Sadhukhan - Sun Microsystems  * This is necessary in order to get the right stack.
15315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
15415db2897SKrishnendu Sadhukhan - Sun Microsystems this unsigned long long end;
15515db2897SKrishnendu Sadhukhan - Sun Microsystems this unsigned long long now;
15615db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
15715db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_sleep_start != 0/
15815db2897SKrishnendu Sadhukhan - Sun Microsystems {
15915db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->end = lt_timestamps[curpsinfo->pr_pid, curlwpsinfo->pr_lwpid];
16015db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->now = timestamp;
16115db2897SKrishnendu Sadhukhan - Sun Microsystems 	lt_timestamps[curpsinfo->pr_pid, curlwpsinfo->pr_lwpid] = 0;
16215db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->end = (this->end != 0 && this->end != self->lt_sleep_start)
16315db2897SKrishnendu Sadhukhan - Sun Microsystems 	    ? this->end : this->now;
16415db2897SKrishnendu Sadhukhan - Sun Microsystems 
16515db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sch_delay = this->now - this->end;
16615db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_duration = this->end - self->lt_sleep_start;
16715db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_start = 0;
16815db2897SKrishnendu Sadhukhan - Sun Microsystems }
16915db2897SKrishnendu Sadhukhan - Sun Microsystems 
17015db2897SKrishnendu Sadhukhan - Sun Microsystems /*
17115db2897SKrishnendu Sadhukhan - Sun Microsystems  * Filter: drop all "large" latency when it is interruptible, i.e., sleep()
17215db2897SKrishnendu Sadhukhan - Sun Microsystems  * etc.
17315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
17415db2897SKrishnendu Sadhukhan - Sun Microsystems #if defined(ENABLE_FILTER)
17515db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
17615db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_sleep_duration > FILTER_THRESHOLD &&
17715db2897SKrishnendu Sadhukhan - Sun Microsystems   self->lt_is_block_wakeable != 0/
17815db2897SKrishnendu Sadhukhan - Sun Microsystems {
17915db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sch_delay = 0;
18015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_duration = 0;
18115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = 0;
18215db2897SKrishnendu Sadhukhan - Sun Microsystems }
18315db2897SKrishnendu Sadhukhan - Sun Microsystems #endif /* defined(ENABLE_FILTER) */
18415db2897SKrishnendu Sadhukhan - Sun Microsystems 
18515db2897SKrishnendu Sadhukhan - Sun Microsystems /*
18615db2897SKrishnendu Sadhukhan - Sun Microsystems  * Write sleep time to the aggregation.
18715db2897SKrishnendu Sadhukhan - Sun Microsystems  * lt_sleep_duration is the duration between the time when a thread is taken
18815db2897SKrishnendu Sadhukhan - Sun Microsystems  * off the CPU and the time when it is enqueued again.
18915db2897SKrishnendu Sadhukhan - Sun Microsystems  */
19015db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
19115db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_sleep_duration != 0/
19215db2897SKrishnendu Sadhukhan - Sun Microsystems {
19315db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->cause = self->lt_stackp > 0 ?
19415db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_cause[self->lt_stackp - 1] : "";
19515db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->priority = self->lt_stackp > 0 ?
19615db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_prio[self->lt_stackp - 1] : 0;
19715db2897SKrishnendu Sadhukhan - Sun Microsystems 
19815db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_count[pid, tid, stack(), this->cause,
19915db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = count();
20015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_sum[pid, tid, stack(), this->cause,
20115db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = sum(self->lt_sleep_duration);
20215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_max[pid, tid, stack(),  this->cause,
20315db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = max(self->lt_sleep_duration);
20415db2897SKrishnendu Sadhukhan - Sun Microsystems 
20515db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = 0;	/* Clear the flag to avoid leak */
20615db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sleep_duration = 0;
20715db2897SKrishnendu Sadhukhan - Sun Microsystems }
20815db2897SKrishnendu Sadhukhan - Sun Microsystems 
20915db2897SKrishnendu Sadhukhan - Sun Microsystems /*
21015db2897SKrishnendu Sadhukhan - Sun Microsystems  * Write time spent in queue to the aggregation.
21115db2897SKrishnendu Sadhukhan - Sun Microsystems  * lt_sch_delay is the interval between the time when a thread becomes
21215db2897SKrishnendu Sadhukhan - Sun Microsystems  * runnable and the time when it is actually on the CPU.
21315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
21415db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
21515db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_sch_delay != 0/
21615db2897SKrishnendu Sadhukhan - Sun Microsystems {
21715db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_count[pid, tid, "Wait for available CPU"] = count();
21815db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_sum[pid, tid, "Wait for available CPU"] =
21915db2897SKrishnendu Sadhukhan - Sun Microsystems 	    sum(self->lt_sch_delay);
22015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_max[pid, tid, "Wait for available CPU"] =
22115db2897SKrishnendu Sadhukhan - Sun Microsystems 	    max(self->lt_sch_delay);
22215db2897SKrishnendu Sadhukhan - Sun Microsystems 
22315db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_sch_delay = 0;
22415db2897SKrishnendu Sadhukhan - Sun Microsystems }
22515db2897SKrishnendu Sadhukhan - Sun Microsystems 
22615db2897SKrishnendu Sadhukhan - Sun Microsystems /*
22715db2897SKrishnendu Sadhukhan - Sun Microsystems  * Probes to track latency caused by spinning on a lock.
22815db2897SKrishnendu Sadhukhan - Sun Microsystems  */
22915db2897SKrishnendu Sadhukhan - Sun Microsystems lockstat:::adaptive-spin
23015db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER
23115db2897SKrishnendu Sadhukhan - Sun Microsystems {
23215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_count[pid, tid, "Adapt. lock spin"] = count();
23315db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_sum[pid, tid, "Adapt. lock spin"] = sum(arg1);
23415db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_max[pid, tid, "Adapt. lock spin"] = max(arg1);
23515db2897SKrishnendu Sadhukhan - Sun Microsystems }
23615db2897SKrishnendu Sadhukhan - Sun Microsystems 
23715db2897SKrishnendu Sadhukhan - Sun Microsystems lockstat:::spin-spin
23815db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER
23915db2897SKrishnendu Sadhukhan - Sun Microsystems {
24015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_count[pid, tid, "Spinlock spin"] = count();
24115db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_sum[pid, tid, "Spinlock spin"] = sum(arg1);
24215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_max[pid, tid, "Spinlock spin"] = max(arg1);
24315db2897SKrishnendu Sadhukhan - Sun Microsystems }
24415db2897SKrishnendu Sadhukhan - Sun Microsystems 
24515db2897SKrishnendu Sadhukhan - Sun Microsystems /*
24615db2897SKrishnendu Sadhukhan - Sun Microsystems  * Probes to track latency caused by blocking on a lock.
24715db2897SKrishnendu Sadhukhan - Sun Microsystems  */
24815db2897SKrishnendu Sadhukhan - Sun Microsystems lockstat:::adaptive-block
24915db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER
25015db2897SKrishnendu Sadhukhan - Sun Microsystems {
25115db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_count[pid, tid, "#Adapt. lock block"] = count();
25215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_sum[pid, tid, "#Adapt. lock block"] = sum(arg1);
25315db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_max[pid, tid, "#Adapt. lock block"] = max(arg1);
25415db2897SKrishnendu Sadhukhan - Sun Microsystems }
25515db2897SKrishnendu Sadhukhan - Sun Microsystems 
25615db2897SKrishnendu Sadhukhan - Sun Microsystems lockstat:::rw-block
25715db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER
25815db2897SKrishnendu Sadhukhan - Sun Microsystems {
25915db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_count[pid, tid, "#RW. lock block"] = count();
26015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_sum[pid, tid, "#RW. lock block"] = sum(arg1);
26115db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_named_max[pid, tid, "#RW. lock block"] = max(arg1);
26215db2897SKrishnendu Sadhukhan - Sun Microsystems }
26315db2897SKrishnendu Sadhukhan - Sun Microsystems 
26415db2897SKrishnendu Sadhukhan - Sun Microsystems #if defined(ENABLE_SYNCOBJ)
26515db2897SKrishnendu Sadhukhan - Sun Microsystems /*
26615db2897SKrishnendu Sadhukhan - Sun Microsystems  * Probes to track latency caused by synchronization objects.
26715db2897SKrishnendu Sadhukhan - Sun Microsystems  */
26815db2897SKrishnendu Sadhukhan - Sun Microsystems this int stype;
26915db2897SKrishnendu Sadhukhan - Sun Microsystems this unsigned long long wchan;
27015db2897SKrishnendu Sadhukhan - Sun Microsystems this unsigned long long wtime;
27115db2897SKrishnendu Sadhukhan - Sun Microsystems 
27215db2897SKrishnendu Sadhukhan - Sun Microsystems sched:::wakeup
27315db2897SKrishnendu Sadhukhan - Sun Microsystems /*
27415db2897SKrishnendu Sadhukhan - Sun Microsystems  * Currently we are unable to track wakeup from sched, because all its LWP IDs
27515db2897SKrishnendu Sadhukhan - Sun Microsystems  * are zero when we trace it and that makes lt_timestamps unusable.
27615db2897SKrishnendu Sadhukhan - Sun Microsystems  */
27715db2897SKrishnendu Sadhukhan - Sun Microsystems /args[1]->pr_pid != 0 &&
27815db2897SKrishnendu Sadhukhan - Sun Microsystems     lt_timestamps[args[1]->pr_pid, args[0]->pr_lwpid] != 0/
27915db2897SKrishnendu Sadhukhan - Sun Microsystems {
28015db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->stype = args[0]->pr_stype;
28115db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->wchan = args[0]->pr_wchan;
28215db2897SKrishnendu Sadhukhan - Sun Microsystems 	/*
28315db2897SKrishnendu Sadhukhan - Sun Microsystems 	 * We can use lt_timestamps[] here, because
28415db2897SKrishnendu Sadhukhan - Sun Microsystems 	 * wakeup is always fired before enqueue.
28515db2897SKrishnendu Sadhukhan - Sun Microsystems 	 * After enqueue, lt_timestamps[] will be overwritten.
28615db2897SKrishnendu Sadhukhan - Sun Microsystems 	 */
28715db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->wtime = timestamp - lt_timestamps[args[1]->pr_pid,
28815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    args[0]->pr_lwpid];
28915db2897SKrishnendu Sadhukhan - Sun Microsystems 
29015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_sync_count[args[1]->pr_pid, args[0]->pr_lwpid, this->stype,
29115db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->wchan] = count();
29215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_sync_sum[args[1]->pr_pid, args[0]->pr_lwpid, this->stype,
29315db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->wchan] = sum(this->wtime);
29415db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_sync_max[args[1]->pr_pid, args[0]->pr_lwpid, this->stype,
29515db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->wchan] = max(this->wtime);
29615db2897SKrishnendu Sadhukhan - Sun Microsystems }
29715db2897SKrishnendu Sadhukhan - Sun Microsystems #endif /* defined(ENABLE_SYNCOBJ) */
29815db2897SKrishnendu Sadhukhan - Sun Microsystems 
29915db2897SKrishnendu Sadhukhan - Sun Microsystems #else /* !defined(ENABLE_LOW_OVERHEAD) */
30015db2897SKrishnendu Sadhukhan - Sun Microsystems 
30115db2897SKrishnendu Sadhukhan - Sun Microsystems /*
30215db2897SKrishnendu Sadhukhan - Sun Microsystems  * This is the low overhead mode.
30315db2897SKrishnendu Sadhukhan - Sun Microsystems  * In order to reduce the number of instructions executed during each
30415db2897SKrishnendu Sadhukhan - Sun Microsystems  * off-cpu and on-cpu event, we do the following:
30515db2897SKrishnendu Sadhukhan - Sun Microsystems  *
30615db2897SKrishnendu Sadhukhan - Sun Microsystems  *	1. Use sampling and update aggregations only roughly 1/100 times
30715db2897SKrishnendu Sadhukhan - Sun Microsystems  *		(SAMPLE_TIMES).
30815db2897SKrishnendu Sadhukhan - Sun Microsystems  *	2. Do not track anything other than what is needed for "main" window.
30915db2897SKrishnendu Sadhukhan - Sun Microsystems  *	3. Use as few thread local variables as possible.
31015db2897SKrishnendu Sadhukhan - Sun Microsystems  */
31115db2897SKrishnendu Sadhukhan - Sun Microsystems 
31215db2897SKrishnendu Sadhukhan - Sun Microsystems #define SAMPLE_TIMES		100
31315db2897SKrishnendu Sadhukhan - Sun Microsystems #define SAMPLE_THRESHOLD	50000000
31415db2897SKrishnendu Sadhukhan - Sun Microsystems 
31515db2897SKrishnendu Sadhukhan - Sun Microsystems /*
31615db2897SKrishnendu Sadhukhan - Sun Microsystems  * Log timestamp when a thread is off CPU.
31715db2897SKrishnendu Sadhukhan - Sun Microsystems  */
31815db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:off-cpu
31915db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER_COND(curlwpsinfo->pr_state == SSLEEP)
32015db2897SKrishnendu Sadhukhan - Sun Microsystems {
32115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = timestamp;
32215db2897SKrishnendu Sadhukhan - Sun Microsystems #if defined(ENABLE_FILTER)
32315db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = curthread->t_flag & T_WAKEABLE;
32415db2897SKrishnendu Sadhukhan - Sun Microsystems #endif /* defined(ENABLE_FILTER) */
32515db2897SKrishnendu Sadhukhan - Sun Microsystems }
32615db2897SKrishnendu Sadhukhan - Sun Microsystems 
32715db2897SKrishnendu Sadhukhan - Sun Microsystems /*
32815db2897SKrishnendu Sadhukhan - Sun Microsystems  * Calculate latency when a thread is actually on the CPU.
32915db2897SKrishnendu Sadhukhan - Sun Microsystems  */
33015db2897SKrishnendu Sadhukhan - Sun Microsystems this int need_skip;
33115db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
33215db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_timestamp != 0/
33315db2897SKrishnendu Sadhukhan - Sun Microsystems {
33415db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = timestamp - self->lt_timestamp;
33515db2897SKrishnendu Sadhukhan - Sun Microsystems 
33615db2897SKrishnendu Sadhukhan - Sun Microsystems #if defined(ENABLE_FILTER)
33715db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp =
33815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    (self->lt_timestamp > FILTER_THRESHOLD &&
33915db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_is_block_wakeable != 0) ? 0 : self->lt_timestamp;
34015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_is_block_wakeable = 0;
34115db2897SKrishnendu Sadhukhan - Sun Microsystems #endif /* defined(ENABLE_FILTER) */
34215db2897SKrishnendu Sadhukhan - Sun Microsystems 
34315db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->need_skip = (self->lt_counter < (SAMPLE_TIMES - 1) &&
34415db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_timestamp <= SAMPLE_THRESHOLD) ? 1 : 0;
34515db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = this->need_skip ? 0 : self->lt_timestamp;
34615db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_counter += this->need_skip;
34715db2897SKrishnendu Sadhukhan - Sun Microsystems }
34815db2897SKrishnendu Sadhukhan - Sun Microsystems 
34915db2897SKrishnendu Sadhukhan - Sun Microsystems /*
35015db2897SKrishnendu Sadhukhan - Sun Microsystems  * Track large latency first.
35115db2897SKrishnendu Sadhukhan - Sun Microsystems  */
35215db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
35315db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_timestamp > SAMPLE_THRESHOLD/
35415db2897SKrishnendu Sadhukhan - Sun Microsystems {
35515db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->cause = self->lt_stackp > 0 ?
35615db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_cause[self->lt_stackp - 1] : "";
35715db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->priority = self->lt_stackp > 0 ?
35815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_prio[self->lt_stackp - 1] : 0;
35915db2897SKrishnendu Sadhukhan - Sun Microsystems 
36015db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_count[pid, tid, stack(), this->cause,
36115db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = sum(1);
36215db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_sum[pid, tid, stack(), this->cause,
36315db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = sum(self->lt_timestamp);
36415db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_max[pid, tid, stack(), this->cause,
36515db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = max(self->lt_timestamp);
36615db2897SKrishnendu Sadhukhan - Sun Microsystems 
36715db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = 0;
36815db2897SKrishnendu Sadhukhan - Sun Microsystems }
36915db2897SKrishnendu Sadhukhan - Sun Microsystems 
37015db2897SKrishnendu Sadhukhan - Sun Microsystems /*
37115db2897SKrishnendu Sadhukhan - Sun Microsystems  * If we fall back to this probe, that means the latency is small and counter
37215db2897SKrishnendu Sadhukhan - Sun Microsystems  * has reached SAMPLE_TIMES.
37315db2897SKrishnendu Sadhukhan - Sun Microsystems  */
37415db2897SKrishnendu Sadhukhan - Sun Microsystems sched::resume:on-cpu
37515db2897SKrishnendu Sadhukhan - Sun Microsystems /self->lt_timestamp != 0/
37615db2897SKrishnendu Sadhukhan - Sun Microsystems {
37715db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->cause = self->lt_stackp > 0 ?
37815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_cause[self->lt_stackp - 1] : "";
37915db2897SKrishnendu Sadhukhan - Sun Microsystems 	this->priority = self->lt_stackp > 0 ?
38015db2897SKrishnendu Sadhukhan - Sun Microsystems 	    self->lt_prio[self->lt_stackp - 1] : 0;
38115db2897SKrishnendu Sadhukhan - Sun Microsystems 
38215db2897SKrishnendu Sadhukhan - Sun Microsystems 	/* Need +1 because lt_counter has not been updated in this cycle. */
38315db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_count[pid, tid, stack(), this->cause,
38415db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = sum(self->lt_counter + 1);
38515db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_sum[pid, tid, stack(), this->cause,
38615db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = sum((self->lt_counter + 1) * self->lt_timestamp);
38715db2897SKrishnendu Sadhukhan - Sun Microsystems 	@lt_call_max[pid, tid, stack(), this->cause,
38815db2897SKrishnendu Sadhukhan - Sun Microsystems 	    this->priority] = max(self->lt_timestamp);
38915db2897SKrishnendu Sadhukhan - Sun Microsystems 
39015db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_timestamp = 0;
39115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_counter = 0;
39215db2897SKrishnendu Sadhukhan - Sun Microsystems }
39315db2897SKrishnendu Sadhukhan - Sun Microsystems 
39415db2897SKrishnendu Sadhukhan - Sun Microsystems #endif /* !defined(ENABLE_LOW_OVERHEAD) */
39515db2897SKrishnendu Sadhukhan - Sun Microsystems 
39615db2897SKrishnendu Sadhukhan - Sun Microsystems #define	TRANSLATE(entryprobe, returnprobe, cause, priority)		\
39715db2897SKrishnendu Sadhukhan - Sun Microsystems entryprobe								\
39815db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER_COND(self->lt_stackp == 0 ||				\
39915db2897SKrishnendu Sadhukhan - Sun Microsystems     (self->lt_stackp < MAX_TAG &&					\
40015db2897SKrishnendu Sadhukhan - Sun Microsystems     self->lt_prio[self->lt_stackp - 1] <= priority) )			\
40115db2897SKrishnendu Sadhukhan - Sun Microsystems {									\
40215db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_prio[self->lt_stackp] = priority;			\
40315db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[self->lt_stackp] = cause;			\
40415db2897SKrishnendu Sadhukhan - Sun Microsystems 	++self->lt_stackp;						\
40515db2897SKrishnendu Sadhukhan - Sun Microsystems }									\
40615db2897SKrishnendu Sadhukhan - Sun Microsystems returnprobe								\
40715db2897SKrishnendu Sadhukhan - Sun Microsystems TRACE_FILTER_COND(self->lt_stackp > 0 &&				\
40815db2897SKrishnendu Sadhukhan - Sun Microsystems     self->lt_cause[self->lt_stackp - 1] == cause)			\
40915db2897SKrishnendu Sadhukhan - Sun Microsystems {									\
41015db2897SKrishnendu Sadhukhan - Sun Microsystems 	--self->lt_stackp;						\
41115db2897SKrishnendu Sadhukhan - Sun Microsystems 	self->lt_cause[self->lt_stackp] = NULL;				\
41215db2897SKrishnendu Sadhukhan - Sun Microsystems }
41315db2897SKrishnendu Sadhukhan - Sun Microsystems 
41415db2897SKrishnendu Sadhukhan - Sun Microsystems /*
41515db2897SKrishnendu Sadhukhan - Sun Microsystems  * Syscalls have a priority of 10. This is to make sure that latency is
41615db2897SKrishnendu Sadhukhan - Sun Microsystems  * traced to one of the syscalls only if nothing else matches.
41715db2897SKrishnendu Sadhukhan - Sun Microsystems  * We put this special probe here because it uses "probefunc" variable instead
41815db2897SKrishnendu Sadhukhan - Sun Microsystems  * of a constant string.
41915db2897SKrishnendu Sadhukhan - Sun Microsystems  */
42015db2897SKrishnendu Sadhukhan - Sun Microsystems 
42115db2897SKrishnendu Sadhukhan - Sun Microsystems TRANSLATE(syscall:::entry, syscall:::return, probefunc, 10)
422