| 1 |
#! /usr/bin/python3 |
| 2 |
|
| 3 |
import os |
| 4 |
import sys |
| 5 |
import subprocess |
| 6 |
import datetime |
| 7 |
|
| 8 |
SYSCALLS_DESC = """Following is an overview of available syscall probes and |
| 9 |
convenience variables they offer. By default, each syscall probe has name and |
| 10 |
argstr convenience variables, which are not included in the overview in order |
| 11 |
to keep it short. Non dwarf-based nd_syscall probes are supposed to have the |
| 12 |
same convenience variables. """ |
| 13 |
|
| 14 |
DESTDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../doc/SystemTap_Tapset_Reference') |
| 15 |
|
| 16 |
def getManContent(body): |
| 17 |
return """.\" -*- nroff -*- |
| 18 |
.TH TAPSET::SYSCALLS 3stap \"""" + datetime.date.today().strftime("%B %Y") + """\" "Systemtap Tapset Reference" |
| 19 |
.SH NAME |
| 20 |
tapset::syscalls - systemtap syscall tapset |
| 21 |
|
| 22 |
.SH DESCRIPTION |
| 23 |
{0} |
| 24 |
.TP |
| 25 |
.P |
| 26 |
.TP |
| 27 |
{1} |
| 28 |
.SH SEE ALSO |
| 29 |
.BR |
| 30 |
.IR stap (1), |
| 31 |
.IR stapprobes (3stap) |
| 32 |
""".format(SYSCALLS_DESC, body) |
| 33 |
|
| 34 |
def getXmlContent(body): |
| 35 |
return """ |
| 36 |
<chapter id="syscalls"> |
| 37 |
<title>syscalls</title> |
| 38 |
<para> |
| 39 |
{0} |
| 40 |
</para> |
| 41 |
<para> |
| 42 |
<table frame='all'><title>Syscalls list</title> |
| 43 |
<tgroup cols='2' align='left' colsep='1' rowsep='1'> |
| 44 |
<colspec colname='c1' colwidth='1.5in' /> |
| 45 |
<colspec colname='c2' colwidth='5in' /> |
| 46 |
<thead> |
| 47 |
<row> |
| 48 |
<entry>syscall</entry> |
| 49 |
<entry>params</entry> |
| 50 |
</row> |
| 51 |
</thead> |
| 52 |
<tbody> |
| 53 |
{1} |
| 54 |
</tbody> |
| 55 |
</tgroup> |
| 56 |
</table> |
| 57 |
</para> |
| 58 |
</chapter> |
| 59 |
""".format(SYSCALLS_DESC, body) |
| 60 |
|
| 61 |
def execShellCmd(cmd): |
| 62 |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 63 |
stderr=subprocess.PIPE) |
| 64 |
out, err = p.communicate() |
| 65 |
sys.stderr.write(str(err)) |
| 66 |
return [line for line in str(out.decode('utf-8')).split('\n') if line] |
| 67 |
|
| 68 |
def getSyscallsList(output_type): |
| 69 |
cmd = ['stap', '-L', 'nd_syscall.*'] |
| 70 |
out = execShellCmd(cmd) |
| 71 |
print("got",out) |
| 72 |
retval = "" |
| 73 |
for line in sorted(out): |
| 74 |
print("line",line) |
| 75 |
tokens = line.split(' ') |
| 76 |
tokens.reverse() |
| 77 |
scname = tokens.pop().replace('nd_syscall.', '') |
| 78 |
tokens = [t.split(':')[0] for t in sorted(tokens)] |
| 79 |
tokens = [t for t in tokens if t not in ['argstr', 'name']] |
| 80 |
tokens = [t for t in tokens if t[:1] != '_'] |
| 81 |
scargs = ", ".join(tokens) |
| 82 |
if output_type=="xml": |
| 83 |
retval += """<row><entry> |
| 84 |
{0} |
| 85 |
</entry><entry> |
| 86 |
{1} |
| 87 |
</entry></row> |
| 88 |
""".format(scname, scargs) |
| 89 |
else: # OUTPUT_TYPE=="man" |
| 90 |
retval += """.P |
| 91 |
.TP |
| 92 |
.B syscall.{0} |
| 93 |
{1} |
| 94 |
""".format(scname, scargs) |
| 95 |
return retval |
| 96 |
|
| 97 |
def main(): |
| 98 |
xmlfile = os.path.join(DESTDIR, 'syscalls.xmlpart') |
| 99 |
print ("Re-generating {0}...".format(xmlfile)) |
| 100 |
xml = open(xmlfile, 'w') |
| 101 |
xml.write(getXmlContent(getSyscallsList("xml"))) |
| 102 |
xml.close() |
| 103 |
|
| 104 |
manfile = os.path.join(DESTDIR, 'syscalls.3stap') |
| 105 |
print ("Re-generating {0}...".format(manfile)) |
| 106 |
man = open(manfile, 'w') |
| 107 |
man.write(getManContent(getSyscallsList("man"))) |
| 108 |
man.close() |
| 109 |
|
| 110 |
print ("Done.") |
| 111 |
|
| 112 |
if __name__ == "__main__": |
| 113 |
main() |
| 114 |
|