Jump to content

SystemTap: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Fche (talk | contribs)
mNo edit summary
Fche (talk | contribs)
mNo edit summary
 
(27 intermediate revisions by 18 users not shown)
Line 1: Line 1:
{{short description|Scripting language and tool}}
{{Infobox software
{{Infobox software
| name = SystemTap
| name = SystemTap
| logo = Smileytap.svg
| logo = Smileytap.svg
| screenshot =
| screenshot =
| released = {{Start date|2005}}
| released = {{Start date|2005}}
| latest release version = 4.0
| latest release version = 5.2
| latest release date = {{Start date and age|2018|10|13}}
| latest release date = {{Start date and age|2024|11|08}}
| programming language = [[C (programming language)|C]], [[C++]]
| programming language = [[C (programming language)|C]], [[C++]]
| operating system = [[Linux]]
| operating system = [[Linux]]
| language =
| language =
| genre = [[Tracing (software)|Tracing]] [[programming language]]
| genre = [[Tracing (software)|Tracing]] [[programming language]]
| license = [[GNU General Public License]]
| license = [[GNU General Public License]]
| website = {{URL|http://sourceware.org/systemtap/}}
| website = {{URL|https://sourceware.org/systemtap/}}
}}
}}
In [[computing]], '''SystemTap''' (<code>stap</code>) is a [[scripting language]] and [[tool]] for dynamically [[Instrumentation (computer programming)|instrumenting]] running production [[Linux kernel]]-based [[operating system]]s. System administrators can use SystemTap to extract, filter and summarize data in order to enable diagnosis of complex performance or functional problems.


In [[computing]], '''SystemTap''' ({{mono|'''stap'''}}) is a [[scripting language]] and [[tool]] for dynamically [[Instrumentation (computer programming)|instrumenting]] running production [[Linux kernel|Linux]]-based [[operating system]]s. System administrators can use SystemTap to extract, filter and summarize data in order to enable diagnosis of complex performance or functional problems.
SystemTap consists of [[free and open-source software]] and includes contributions from [[Red Hat]], [[IBM]], [[Intel]], [[Hitachi, Ltd|Hitachi]], [[Oracle Corporation|Oracle]], and other community members.<ref>{{cite web|url=https://lwn.net/Articles/315022/|title=A SystemTap update|publisher=[[lwn.net]]}}</ref>

SystemTap consists of [[free and open-source software]] and includes contributions from [[Red Hat]], [[IBM]], [[Intel]], [[Hitachi, Ltd|Hitachi]], [[Oracle Corporation|Oracle]], the University of Wisconsin-Madison and other community members.<ref>{{cite web|url=https://lwn.net/Articles/315022/|title=A SystemTap update|publisher=[[LWN.net]]}}</ref>


==History==
==History==
SystemTap debuted in 2005 in [[Red Hat Enterprise Linux]] 4 Update 2 as a technology preview.<ref>{{cite web|url=http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/release-notes/as-x86/RELEASE-NOTES-U2-x86-en.html|title=Product Documentation for Red Hat Enterprise Linux|publisher=[[Red Hat]]}}</ref>
SystemTap debuted in 2005 in [[Red Hat Enterprise Linux]] 4 Update 2 as a technology preview.<ref>{{cite web|url=http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/release-notes/as-x86/RELEASE-NOTES-U2-x86-en.html|title=Product Documentation for Red Hat Enterprise Linux|publisher=[[Red Hat]]}}</ref>


After four years in development, SystemTap 1.0 was released in 2009.<ref>{{cite web|url=http://sourceware.org/ml/systemtap/2009-q3/msg00831.html|title=Josh Stone - SystemTap release 1.0|publisher=}}</ref>
After four years in development, SystemTap 1.0 was released in 2009.<ref>{{cite web|url=http://sourceware.org/ml/systemtap/2009-q3/msg00831.html|title=Josh Stone - SystemTap release 1.0}}</ref>


{{As of | 2011}} SystemTap runs fully supported in all Linux distributions including [[Red Hat Enterprise Linux|RHEL / CentOS]] 5<ref>{{cite web|url=http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.2/html/Release_Notes/x86/ar01s03.html|title=Product Documentation|publisher=[[Red Hat]]}}</ref> since update 2, SLES 10,<ref>{{cite web|url=http://support.novell.com/techcenter/psdb/f1856527fefb7f2060aeb6907f319a09.html|title=Optional update for SystemTap|author=60951|date=10 October 2006|publisher=[[Novell]]}}</ref> Fedora, Debian and Ubuntu.
{{As of|2011}}, SystemTap runs fully supported in all Linux distributions including [[Red Hat Enterprise Linux|RHEL / CentOS]] 5<ref>{{cite web|url=http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.2/html/Release_Notes/x86/ar01s03.html|title=Product Documentation|publisher=[[Red Hat]]}}</ref> since update 2, SLES 10,<ref>{{cite web|url=http://support.novell.com/techcenter/psdb/f1856527fefb7f2060aeb6907f319a09.html|title=Optional update for SystemTap|date=10 October 2006|publisher=[[Novell]]}}</ref> Fedora, Debian and Ubuntu.


Tracepoints in the [[CPython]] VM and [[JVM]] were added in SystemTap 1.2.<ref>{{cite web|url=http://fedoraproject.org/wiki/Features/SystemtapStaticProbes|title=Features/SystemtapStaticProbes - FedoraProject|publisher=Fedoraproject}}</ref>
Tracepoints in the [[CPython]] VM and [[JVM]] were added in SystemTap 1.2 in 2009.<ref>{{cite web|url=http://fedoraproject.org/wiki/Features/SystemtapStaticProbes|title=Features/SystemtapStaticProbes - FedoraProject|publisher=Fedoraproject}}</ref>

In November 2019, SystemTap 4.2 included [[prometheus (software)|prometheus]] exporter.


==Usage==
==Usage==
SystemTap files are written in the SystemTap language <ref>https://sourceware.org/systemtap/langref/</ref> (saved as <code>.stp</code> files) and run with the <code>stap</code> command-line.<ref>
SystemTap files are written in the SystemTap language<ref>{{Cite web|url=https://sourceware.org/systemtap/langref/|title = SystemTap Language Reference}}</ref> (saved as <code>.stp</code> files) and run with the <code>stap</code> command-line.<ref>Compare {{cite journal
| title = SystemTap Language Reference: A guide to the constructs and syntax used in SystemTap scripts
Compare {{cite web
| first = Robb
| url = http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.172.5186&rep=rep1&type=pdf
| last = Romans
| title = SystemTap Language Reference: A guide to the constructs and syntax used in SystemTap scripts
| first = Robb
| year = 2009
| publisher = Red Hat
| last = Romans
| year = 2009
| page = 4
| quote = SystemTap [...] requires root privileges to actually run the kernel objects it builds using the sudo command, applied to the staprun program.[...] staprun is a part of the SystemTap package, dedicated to module loading and unloading and kernel-touser data transfer.
| publisher = Red Hat
| citeseerx = 10.1.1.172.5186}}</ref>
| page = 4

| format = PDF
The system carries out a number of analysis passes on the script before allowing it to run. Scripts may be executed with one of three backends selected by the <code>--runtime=</code> option. The default is a [[loadable kernel module]], which has the fullest capability to inspect and manipulate any part of the system, and therefore requires most privilege. Another backend is based on the [[dynamic program analysis]] library DynInst to instrument the user's own user-space programs only, and requires least privilege. The newest backend<ref>{{cite web
| accessdate = 2010-12-19
|url = https://sourceware.org/ml/systemtap/2017-q4/msg00096.htmlq1/msg00097.html
| quote = SystemTap [...] requires root privileges to actually run the kernel objects it builds using the sudo command, applied to the staprun program.[...] staprun is a part of the SystemTap package, dedicated to module loading and unloading and kernel-touser data transfer.
|title = systemtap 3.2 release
}}
|last1 = Merey
</ref>
|first1 = Aaron
The system carries out a number of analysis passes on the script before allowing it to run. Scripts may be executed with one of three backends selected by the <code>--runtime=</code> option. The default is a [[loadable kernel module]], which has the fullest capability to inspect and manipulate any part of the system, and therefore requires most privilege. Another backend is based on the [[dynamic program analysis]] library DynInst to instrument the user's own user-space programs only, and requires least privilege. The newest backend<ref>
|date = 2017-10-18
{{cite web
|access-date = 2017-10-18
|url = https://sourceware.org/ml/systemtap/2017-q4/msg00096.htmlq1/msg00097.html
|quote = The systemtap team announces release 3.2 [...] early experimental eBPF (extended Berkeley Packet Filter) backend [...]
|title = systemtap 3.2 release
}}{{Dead link|date=March 2023 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> is based on [[eBPF|eBPF byte-code]], is limited to the [[Linux]] kernel interpreter's capabilities, and requires an intermediate level of privilege. In each case, the module is unloaded when the script has finished running.
|last1 = Merey
|first1 = Aaron
|date = 2017-10-18
|accessdate = 2017-10-18
|quote = The systemtap team announces release 3.2 [...] early experimental eBPF (extended Berkeley Packet Filter) backend [...]
}}
</ref> is based on [[Berkeley_Packet_Filter#EBPF|eBPF byte-code]], is limited the [[Linux]] kernel interpreter's capabilities, and requires an intermediate level of privilege. In each case, the module is unloaded when the script has finished running.


Scripts generally focus on events (such as starting or finishing a script), compiled-in probe points such as Linux "tracepoints", or the execution of functions or statements in the kernel or user-space.
Scripts generally focus on events (such as starting or finishing a script), compiled-in probe points such as Linux "tracepoints", or the execution of functions or statements in the kernel or user-space.


Some "guru mode" scripts may also have embedded C, which may run with the <code>-g</code> command-line option. However, use of guru mode is discouraged, and each SystemTap release includes more probe points designed to remove the need for guru-mode scripts. Guru mode is required in order to permit scripts to ''modify'' state in the instrumented software, such as to apply some types of emergency security fixes.
Some "guru mode" scripts may also have embedded C, which may run with the <code>-g</code> command-line option. However, use of guru mode is discouraged, and each SystemTap release includes more probe points designed to remove the need for guru-mode scripts. Guru mode is required in order to permit scripts to ''modify'' state in the instrumented software, such as to apply some types of emergency security fixes.


As of systemtap release 1.7 the software implements the new ''stapsys'' group and privilege level.<ref>
As of SystemTap version 1.7, the software implements the new ''stapsys'' group and privilege level.<ref>{{cite web
| url = http://sourceware.org/ml/systemtap/2012-q1/msg00097.html
{{cite web
|url = http://sourceware.org/ml/systemtap/2012-q1/msg00097.html
| title = systemtap 1.7 release
|title = systemtap 1.7 release
| last1 = Eigler
|last1 = Eigler
| first1 = Frank Ch.
|first1 = Frank Ch.
| date = 2012-02-01
|date = 2012-02-01
| access-date = 2013-03-26
| quote = The systemtap team announces release 1.7 [...] The new group and privilege level "stapsys" has been added [...]}}</ref>
|accessdate = 2013-03-26
|quote = The systemtap team announces release 1.7 [...] The new group and privilege level "stapsys" has been added [...]
}}
</ref>


==Simple examples==
==Simple examples==
The following script shows all applications setting [[Transmission Control Protocol|TCP]] [[network socket|socket]] options on the system, what options are being set, and whether the option is set successfully or not:
The following script shows all applications setting [[Transmission Control Protocol|TCP]] [[network socket|socket]] options on the system, what options are being set, and whether the option is set successfully or not.


<source lang="tap">
<syntaxhighlight lang="vcl">
# Show sockets setting options
# Show sockets setting options


Line 89: Line 84:
}
}


# Set a socket option
# Set a socket option
probe tcp.setsockopt
probe tcp.setsockopt
{
{
status = getstatus(user_int($optval))
status = getstatus(user_int($optval))
printf (" App '%s' (PID %d) is %s socket option %s... ", execname(), pid(), status, optstr)
printf (" App '%s' (PID %d) is %s socket option %s... ", execname(), pid(), status, optstr)
}
}

# Check setting the socket option worked
# Check setting the socket option worked
probe tcp.setsockopt.return
probe tcp.setsockopt.return
{
{
if ( ret == 0 )
if ( ret == 0 )
printf ("success")
printf ("success")
else
else
printf ("failed")
printf ("failed")
printf ("\n")
printf ("\n")
}
}


probe end
probe end
Line 110: Line 105:
print ("\nClosing down\n")
print ("\nClosing down\n")
}
}
</syntaxhighlight>
</source>


Many other examples are shipped with SystemTap.<ref>{{cite web|url=http://sourceware.org/systemtap/examples/|title=SystemTap Examples|publisher=}}</ref> There are also real-world examples of SystemTap use at the War Stories page.<ref>{{cite web|url=http://sourceware.org/systemtap/wiki/WarStories|title=WarStories - Systemtap Wiki|publisher=}}</ref>
Many other examples are shipped with SystemTap.<ref>{{cite web|url=https://sourceware.org/systemtap/examples/|title=SystemTap Examples}}</ref> There are also real-world examples of SystemTap use at the War Stories page.<ref>{{cite web|url=https://sourceware.org/systemtap/wiki/WarStories|title=WarStories - Systemtap Wiki}}</ref>


==Importing scripts from other tracing technologies==
==Importing scripts from other tracing technologies==
Line 118: Line 113:


==See also==
==See also==
{{Portal|Free software}}
{{Portal|Free and open-source software}}
* [[Kernel marker]]
* [[Kernel marker]]
* [[dprobes|DProbes]]
* [[dprobes|DProbes]]
Line 129: Line 124:


==External links==
==External links==
* [http://sourceware.org/systemtap/ SystemTap Homepage]
* {{Official website|https://sourceware.org/systemtap/}}
* [http://sourceware.org/systemtap/wiki/ SystemTap Wiki]
* [https://sourceware.org/systemtap/wiki/ SystemTap Wiki]
* [http://sourceware.org/systemtap/langref/ SystemTap Language Reference] ([http://sourceware.org/systemtap/langref.pdf PDF])
* [https://sourceware.org/systemtap/langref/ SystemTap Language Reference] ([https://sourceware.org/systemtap/langref.pdf PDF])
* [http://www.ohloh.net/p/systemtap SystemTap project analysis by Ohloh]
* [http://www.ohloh.net/p/systemtap SystemTap project analysis by Ohloh]
* [https://myaut.github.io/dtrace-stap-book Dynamic Tracing with DTrace & SystemTap]
* [https://myaut.github.io/dtrace-stap-book Dynamic Tracing with DTrace & SystemTap]
* [http://sourceware.org/systemtap/tutorial.pdf ''Systemtap tutorial''] Frank Ch. Eigler
* [https://sourceware.org/systemtap/tutorial.pdf ''Systemtap tutorial''] Frank Ch. Eigler
* [http://sourceware.org/systemtap//SystemTap_Beginners_Guide.pdf ''SystemTap Beginner's Guide''] Don Domingo, William Cohen
* [https://sourceware.org/systemtap//SystemTap_Beginners_Guide.pdf ''SystemTap Beginner's Guide''] Don Domingo, William Cohen
* [https://www.kernel.org/doc/ols/2006/ols2006v1-pages-261-268.pdf ''Problem Solving With Systemtap''], [http://www.linuxsymposium.org/ Ottawa Linux Symposium] 2006
* [https://www.kernel.org/doc/ols/2006/ols2006v1-pages-261-268.pdf ''Problem Solving With Systemtap''], [http://www.linuxsymposium.org/ Ottawa Linux Symposium] {{Webarchive|url=https://web.archive.org/web/20080913185728/http://www.linuxsymposium.org/ |date=2008-09-13 }} 2006
* [http://sources.redhat.com/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTap.pdf ''Problem Solving with SystemTap''], Eugene Teo, presented at the [http://www.redhat.com/summit/ Red Hat Summit] 2007 ([http://sourceware.org/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTapScripts.bz2 scripts])
* [http://sources.redhat.com/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTap.pdf ''Problem Solving with SystemTap''] {{Webarchive|url=https://web.archive.org/web/20120222005620/http://sources.redhat.com/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTap.pdf |date=2012-02-22 }}, Eugene Teo, presented at the [http://www.redhat.com/summit/ Red Hat Summit] 2007 ([https://sourceware.org/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTapScripts.bz2 scripts])
* [http://sourceware.org/systemtap/wiki/LW2008SystemTapTutorial?action=AttachFile&do=get&target=jistone-systemtap-linuxworld08.pdf ''Dynamic Tracing and Performance Analysis Using SystemTap''], Joshua Stone, presented at the [https://web.archive.org/web/19990117025510/http://linuxworldexpo.com/ LinuxWorld Conference] 2008
* [https://sourceware.org/systemtap/wiki/LW2008SystemTapTutorial?action=AttachFile&do=get&target=jistone-systemtap-linuxworld08.pdf ''Dynamic Tracing and Performance Analysis Using SystemTap''], Joshua Stone, presented at the [https://web.archive.org/web/19990117025510/http://linuxworldexpo.com/ LinuxWorld Conference] 2008
* [http://sourceware.org/systemtap/wiki/LPC2008SystemTapTutorial?action=AttachFile&do=get&target=LPC_2008_stap.pdf SystemTap Tutorial], Jim Keniston, presented at the [http://linuxplumbersconf.org/ Linux Plumbers Conference] 2008
* [https://sourceware.org/systemtap/wiki/LPC2008SystemTapTutorial?action=AttachFile&do=get&target=LPC_2008_stap.pdf SystemTap Tutorial], Jim Keniston, presented at the [http://linuxplumbersconf.org/ Linux Plumbers Conference] 2008


{{Linux kernel}}
{{Linux kernel}}
Line 147: Line 142:
[[Category:Debuggers]]
[[Category:Debuggers]]
[[Category:Linux kernel features]]
[[Category:Linux kernel features]]
[[Category:Linux-only software]]
[[Category:Linux-only free software]]

Latest revision as of 01:22, 9 November 2024

SystemTap
Initial release2005 (2005)
Stable release
5.2 / November 8, 2024; 41 days ago (2024-11-08)
Repository
Written inC, C++
Operating systemLinux
TypeTracing programming language
LicenseGNU General Public License
Websitesourceware.org/systemtap/

In computing, SystemTap (stap) is a scripting language and tool for dynamically instrumenting running production Linux-based operating systems. System administrators can use SystemTap to extract, filter and summarize data in order to enable diagnosis of complex performance or functional problems.

SystemTap consists of free and open-source software and includes contributions from Red Hat, IBM, Intel, Hitachi, Oracle, the University of Wisconsin-Madison and other community members.[1]

History

[edit]

SystemTap debuted in 2005 in Red Hat Enterprise Linux 4 Update 2 as a technology preview.[2]

After four years in development, SystemTap 1.0 was released in 2009.[3]

As of 2011, SystemTap runs fully supported in all Linux distributions including RHEL / CentOS 5[4] since update 2, SLES 10,[5] Fedora, Debian and Ubuntu.

Tracepoints in the CPython VM and JVM were added in SystemTap 1.2 in 2009.[6]

In November 2019, SystemTap 4.2 included prometheus exporter.

Usage

[edit]

SystemTap files are written in the SystemTap language[7] (saved as .stp files) and run with the stap command-line.[8]

The system carries out a number of analysis passes on the script before allowing it to run. Scripts may be executed with one of three backends selected by the --runtime= option. The default is a loadable kernel module, which has the fullest capability to inspect and manipulate any part of the system, and therefore requires most privilege. Another backend is based on the dynamic program analysis library DynInst to instrument the user's own user-space programs only, and requires least privilege. The newest backend[9] is based on eBPF byte-code, is limited to the Linux kernel interpreter's capabilities, and requires an intermediate level of privilege. In each case, the module is unloaded when the script has finished running.

Scripts generally focus on events (such as starting or finishing a script), compiled-in probe points such as Linux "tracepoints", or the execution of functions or statements in the kernel or user-space.

Some "guru mode" scripts may also have embedded C, which may run with the -g command-line option. However, use of guru mode is discouraged, and each SystemTap release includes more probe points designed to remove the need for guru-mode scripts. Guru mode is required in order to permit scripts to modify state in the instrumented software, such as to apply some types of emergency security fixes.

As of SystemTap version 1.7, the software implements the new stapsys group and privilege level.[10]

Simple examples

[edit]

The following script shows all applications setting TCP socket options on the system, what options are being set, and whether the option is set successfully or not.

# Show sockets setting options

# Return enabled or disabled based on value of optval
function getstatus(optval)
{
    if ( optval == 1 )
        return "enabling"
    else
        return "disabling"
}

probe begin
{
	print ("\nChecking for apps setting socket options\n")
}

    # Set a socket option
    probe tcp.setsockopt
    {
        status = getstatus(user_int($optval))
    	printf ("  App '%s' (PID %d) is %s socket option %s... ", execname(), pid(), status, optstr)
    }
    
        # Check setting the socket option worked
        probe tcp.setsockopt.return
        {
            if ( ret == 0 )
                printf ("success")
            else
                printf ("failed")
            printf ("\n")
        }

probe end
{
	print ("\nClosing down\n")
}

Many other examples are shipped with SystemTap.[11] There are also real-world examples of SystemTap use at the War Stories page.[12]

Importing scripts from other tracing technologies

[edit]

SystemTap can attach to DTrace markers when they are compiled into an application using macros from the sys/sdt.h header file.

See also

[edit]

References

[edit]
  1. ^ "A SystemTap update". LWN.net.
  2. ^ "Product Documentation for Red Hat Enterprise Linux". Red Hat.
  3. ^ "Josh Stone - SystemTap release 1.0".
  4. ^ "Product Documentation". Red Hat.
  5. ^ "Optional update for SystemTap". Novell. 10 October 2006.
  6. ^ "Features/SystemtapStaticProbes - FedoraProject". Fedoraproject.
  7. ^ "SystemTap Language Reference".
  8. ^ Compare Romans, Robb (2009). "SystemTap Language Reference: A guide to the constructs and syntax used in SystemTap scripts". Red Hat: 4. CiteSeerX 10.1.1.172.5186. SystemTap [...] requires root privileges to actually run the kernel objects it builds using the sudo command, applied to the staprun program.[...] staprun is a part of the SystemTap package, dedicated to module loading and unloading and kernel-touser data transfer. {{cite journal}}: Cite journal requires |journal= (help)
  9. ^ Merey, Aaron (2017-10-18). "systemtap 3.2 release". Retrieved 2017-10-18. The systemtap team announces release 3.2 [...] early experimental eBPF (extended Berkeley Packet Filter) backend [...][permanent dead link]
  10. ^ Eigler, Frank Ch. (2012-02-01). "systemtap 1.7 release". Retrieved 2013-03-26. The systemtap team announces release 1.7 [...] The new group and privilege level "stapsys" has been added [...]
  11. ^ "SystemTap Examples".
  12. ^ "WarStories - Systemtap Wiki".
[edit]