File: 010intro-external-variables.d

package info (click to toggle)
dtrace 2.0.5-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 24,408 kB
  • sloc: ansic: 61,247; sh: 17,997; asm: 1,717; lex: 947; awk: 754; yacc: 695; perl: 37; sed: 17; makefile: 15
file content (60 lines) | stat: -rwxr-xr-x 2,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Linux DTrace
 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */

#!/usr/sbin/dtrace -s

#pragma D option quiet
#pragma D option strsize=64

/*
 *  SYNOPSIS
 *    sudo ./010intro-external-variables.d
 *
 *  DESCRIPTION
 *    We can examine external variables -- that is, variables from outside
 *    the D program, such as kernel variables.  They are distinguished by
 *    a back quote ` and constitute a different name space from that of
 *    the D variables.  When such a variables is named, the kernel and all
 *    loaded modules are searched for the name.  Or, you can specify a
 *    module before the back quote.  The kernel itself is module "vmlinux".
 *    D scripts cannot modify values of kernel variables.
 *
 *    Such external variables are not part of D and are subject to change.
 */

dtrace:::BEGIN
{

	printf("\n==== print some kernel variables ====\n\n");

	printf("cad_pid->level: %d\n", ((struct pid *)`cad_pid)->level);
	printf("crashing_cpu: %d\n", `crashing_cpu);
	printf("linux_banner: %s\n", (string)`linux_banner);
	printf("linux_proc_banner: %s\n", (string)`linux_proc_banner);
	printf("load averages: %d.%02d, %d.%02d, %d.%02d\n",
	    `avenrun[0] / 2048, ((`avenrun[0] % 2048) * 100) / 2048,
	    `avenrun[1] / 2048, ((`avenrun[1] % 2048) * 100) / 2048,
	    `avenrun[2] / 2048, ((`avenrun[2] % 2048) * 100) / 2048);
	printf("max_pvn: %d\n", `max_pfn);
	printf("nr_cpu_ids: %d\n", `nr_cpu_ids);
	printf("saved_command_line: %s\n", (string)`saved_command_line);

	printf("\n==== reprint some of them, explicitly naming vmlinux ====\n\n");

	printf("crashing_cpu: %d\n", vmlinux`crashing_cpu);
	printf("linux_banner: %s\n", (string)vmlinux`linux_banner);
	printf("linux_proc_banner: %s\n", (string)vmlinux`linux_proc_banner);
	printf("max_pvn: %d\n", vmlinux`max_pfn);
	printf("nr_cpu_ids: %d\n", vmlinux`nr_cpu_ids);

	printf("\n==== refer to a data type in a module ====\n\n");

	printf("offset of atomic in struct rds_message: %d\n",
	    offsetof(struct rds`rds_message, atomic));

	exit(0);
}