Skip to content

Instantly share code, notes, and snippets.

@danielhams
Created April 12, 2020 20:20
Show Gist options
  • Save danielhams/c55a728d1350bead798be8059454cf16 to your computer and use it in GitHub Desktop.
Save danielhams/c55a728d1350bead798be8059454cf16 to your computer and use it in GitHub Desktop.
Program:
// Written by Ch. Tronche (http://tronche.lri.fr:8000/)
// Copyright by the author. This is unmaintained, no-warranty free software.
// Please use freely. It is appreciated (but by no means mandatory) to
// acknowledge the author's contribution. Thank you.
// Started on Thu Jun 26 23:29:03 1997
//
// Xlib tutorial: 2nd program
// Make a window appear on the screen and draw a line inside.
// If you don't understand this program, go to
// http://tronche.lri.fr:8000/gui/x/xlib-tutorial/2nd-program-anatomy.html
//
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h> // I include this to test return values the lazy way
#include <unistd.h> // So we got the profile for 10 seconds
#define NIL (0) // A name for the void pointer
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
// Get some colors
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, blackColor, blackColor);
// We want to get MapNotify events
XSelectInput(dpy, w, StructureNotifyMask);
// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);
// Create a "Graphics Context"
GC gc = XCreateGC(dpy, w, 0, NIL);
// Tell the GC we draw using the white color
XSetForeground(dpy, gc, whiteColor);
// Wait for the MapNotify event
for(;;) {
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify)
break;
}
// Draw the line
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
// Send the "DrawLine" request to the server
XFlush(dpy);
// Wait for 10 seconds
sleep(10);
}
PAR results:
0mS[ 0] (3130926): was sent signal SIGUSR1 by pid 3128320
0mS[ 0] : received signal SIGUSR1 (handler 0x10002ac8)
0mS[ 0] : END-pause() errno = 4 (Interrupted function call)
0mS[ 0] : sigreturn(0x7ffd7ae0) OK
0mS[ 0] : execve("./simpleX11thing", 0x7ffd7f48, 0x7ffd7f50)
1mS[ 0] : END-execve() OK
1mS[ 0] : sysconf(_SC_CAP) = 1
1mS[ 0] : syssgi(SGI_PROC_ATTR_GET, 0xfb3daf0, 0x7ffd7ed0, 0, 0, 0) = 0
1mS[ 0] : getuid() = 55695, euid=55695
1mS[ 0] : getuid() = 55695, euid=55695
1mS[ 0] : getgid() = 20 egid=20
1mS[ 0] : getgid() = 20 egid=20
1mS[ 0] : open("/lib32/rld", O_RDONLY, 04) = 3
1mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
1mS[ 0] : elfmap(3, 0x7ffd7d64, 2) = 0xfb60000
1mS[ 0] : close(3) OK
1mS[ 0] : getpagesize() = 16384
1mS[ 0] : syssgi(0x5c, 0, 0x3d, 0, 0xfbd61b1, 0x52) = 0
1mS[ 0] : sysinfo(_MIPS_SI_PROCESSORS, 0x7ffd7db0, 257) = 23
1mS[ 0] : open("/dev/zero", O_RDONLY, 01757300000) = 3
1mS[ 0] : mmap(0xfbd8000, 32768, PROT_WRITE|PROT_READ, MAP_PRIVATE, 3, 0) = 0xfbd8000
1mS[ 0] : close(3) OK
2mS[ 0] : open("/usr/sgug/lib32/libX11.so.6", O_RDONLY, 05) = 3
2mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
2mS[ 0] : elfmap(3, 0x7ffd5ed0, 2) = 0x5ffe0000
2mS[ 0] : close(3) OK
2mS[ 0] : syssgi(SGI_USE_FP_BCOPY, 0, 0x2ad0, 0xffffffff, 0x2ac0, 0x1) = 0
2mS[ 0] : open("/usr/sgug/lib32/libm.so", O_RDONLY, 05) errno = 2 (No such file or directory)
2mS[ 0] : open("/usr/lib32/libm.so", O_RDONLY, 05) = 3
2mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
2mS[ 0] : elfmap(3, 0x7ffd5f50, 2) = 0x12a0000
2mS[ 0] : close(3) OK
2mS[ 0] : open("/usr/sgug/lib32/libc.so.1", O_RDONLY, 05) errno = 2 (No such file or directory)
2mS[ 0] : open("/usr/sgug/lib32/libgcc_s.so.1", O_RDONLY, 05) = 3
3mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
3mS[ 0] : elfmap(3, 0x7ffd5f50, 2) = 0x4000000
3mS[ 0] : close(3) OK
3mS[ 0] : open("/usr/sgug/lib32/libxcb.so.1", O_RDONLY, 05) = 3
3mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
3mS[ 0] : elfmap(3, 0x7ffd5f30, 2) = 0x4040000
3mS[ 0] : close(3) OK
3mS[ 0] : open("/usr/sgug/lib32/libXau.so.6", O_RDONLY, 05) = 3
3mS[ 0] : read(3, <7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00>..., 512) = 512
3mS[ 0] : elfmap(3, 0x7ffd5ea0, 2) = 0x4080000
3mS[ 0] : close(3) OK
3mS[ 0] : open("/dev/zero", O_RDONLY, 01757400000) = 3
3mS[ 0] : mmap(0xfbe0000, 32768, PROT_WRITE|PROT_READ, MAP_PRIVATE, 3, 0) = 0xfbe0000
3mS[ 0] : close(3) OK
8mS[ 0] : syssgi(SGI_TOSSTSAVE) OK
8mS[ 0] : getpagesize() = 16384
8mS[ 0] : brk(0x10018000) OK
8mS[ 0] : syssgi(SGI_USE_FP_BCOPY, 0, 0x950, 0xffffffff, 0x940, 0x1) = 0
8mS[ 0] : stat("/etc/ipnodes", 0x7ffd6d30) errno = 2 (No such file or directory)
8mS[ 0] : open("/var/ns/cache/ipnodes.byname", O_RDONLY, 0400) = 3
8mS[ 0] : fstat(3, 0x7ffd6240) OK
8mS[ 0] : mmap(0, 65536, PROT_READ, MAP_SHARED, 3, 0) = 0x40a4000
8mS[ 0] : close(3) OK
8mS[ 0] : time() = 1586722701
8mS[ 0] : stat("/etc/hosts", 0x7ffd6d30) OK
8mS[ 0] : open("/var/ns/cache/hosts.byname", O_RDONLY, 0400) = 3
8mS[ 0] : fstat(3, 0x7ffd6240) OK
8mS[ 0] : mmap(0, 65536, PROT_READ, MAP_SHARED, 3, 0) = 0x40b4000
9mS[ 0] : close(3) OK
9mS[ 0] : time() = 1586722701
9mS[ 0] : socket(PF_INET, SOCK_STREAM, 6) = 3
9mS[ 0] : fcntl(3, F_SETFD, 1) OK
9mS[ 0] : setsockopt(3, IPPROTO_TCP, SO_DEBUG|IP_OPTIONS|TCP_NODELAY(0x1), 0x7ffd7c38, 0x4) OK
9mS[ 0] : setsockopt(3, SOL_SOCKET, SO_KEEPALIVE|IP_RETOPTS(0x8), 0x7ffd7c38, 0x4) OK
9mS[ 0] : connect(3, {sin_family=AF_INET, sin_port=6000, sin_addr=192.168.0.74}, 16)
14mS[ 0] : END-connect() OK
14mS[ 0] : getpeername(3, {sin_family=AF_INET, sin_port=6000, sin_addr=192.168.0.74}, IN:124) OK
14mS[ 0] : access("/usr/people/dan/.Xauthority", R_OK) OK
14mS[ 0] : open("/usr/people/dan/.Xauthority", O_RDONLY, 0666) = 4
14mS[ 0] : fstat(4, 0x7ffd7850) OK
14mS[ 0] : ioctl(4, __OLD_TCGETA, 0x7ffd7800) errno = 25 (Inappropriate I/O control operation)
14mS[ 0] : read(4, <00 00 00 04 c0 a8 00 56 00 01 30 00 12 4d 49 54>..., 4096) = 333
14mS[ 0] : read(4, 0x10012510, 4096) = 0
14mS[ 0] : close(4) OK
14mS[ 0] : fcntl(3, F_GETFL) = 0x202
14mS[ 0] : fcntl(3, F_SETFL, FNONBLOCK(0x282)) OK
14mS[ 0] : fcntl(3, F_SETFD, 1) OK
14mS[ 0] : shutdown(3, 2) OK
14mS[ 0] : close(3) OK
14mS[ 0] : write(2, "Assertion failed: ", 18) = 18
15mS[ 0] : write(2, "EX", 2) = 2
15mS[ 0] : write(2, ", file ", 7) = 7
15mS[ 0] : write(2, "simpleX11thing.c", 16) = 16
15mS[ 0] : write(2, ", line 25", 9) = 9
15mS[ 0] : write(2, "\n", 1) = 1
15mS[ 0] : sigaction(SIGABRT, 0, {flags=0 handler=SIG_DFL mask=[<none>]}) OK
15mS[ 0] : sigaction(SIGABRT, {flags=SA_RESETHAND|SA_NODEFER handler=SIG_DFL mask=[<none>]}, {flags=0 handler=SIG_DFL mask=[<none>]}) OK
15mS[ 0] : sigprocmask(SIG_UNBLOCK, [SIGABRT], 0) OK
15mS[ 0] : getpid() = 3130926, ppid=3129159
15mS[ 0] (3130926): was sent signal SIGABRT by pid 3130926
15mS[ 0] : kill(3130926, SIGABRT)
15mS[ 0] : received signal SIGABRT
System call summary:
Average Total
Name #Calls Time(ms) Time(ms)
-----------------------------------------
connect 1 5.23 5.23
execve 1 1.37 1.37
elfmap 6 0.17 1.05
open 13 0.05 0.60
write 6 0.04 0.23
read 8 0.02 0.18
stat 2 0.05 0.10
mmap 4 0.02 0.08
close 12 0.01 0.08
access 1 0.05 0.05
socket 1 0.05 0.05
shutdown 1 0.02 0.02
setsockopt 2 0.01 0.02
syssgi 5 0.00 0.01
fstat 3 0.00 0.01
fcntl 4 0.00 0.01
sigaction 2 0.01 0.01
getpeername 1 0.01 0.01
brk 1 0.01 0.01
sigreturn 1 0.01 0.01
getpagesize 2 0.00 0.00
sysinfo 1 0.00 0.00
time 2 0.00 0.00
ioctl 1 0.00 0.00
sigprocmask 1 0.00 0.00
sysconf 1 0.00 0.00
getuid 2 0.00 0.00
getgid 2 0.00 0.00
getpid 1 0.00 0.00
kill 1 0.00 0.00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment