Skip to content

Instantly share code, notes, and snippets.

@myaut
Last active August 29, 2015 14:21
Show Gist options
  • Save myaut/ab4dd51ff811bd367328 to your computer and use it in GitHub Desktop.
Save myaut/ab4dd51ff811bd367328 to your computer and use it in GitHub Desktop.
Avoiding gibberish when multiple processes print to same tty using SystemTap

Script:

stap -e '
    global lines; 
    
    probe syscall.write { 
        if(execname() == "alloc-bench" && fd == 2) { 
            line = lines[pid()] . user_string_n(buf_uaddr, count);
            if(isinstr(line, "\n")) {
                printdln(" ", pid(), lines[pid()]); 
                delete lines[pid()];
            }
            else lines[pid()] = line; } } '

Original output:

111 33 1 3359  2201d301ffffffff -> d3012201ffffffff -> 2201d301ffffffff d3012201ffffffff 

61 1fffffffffffffff -> 1fffffffffffffff
11 33 d3012201ffffffff -> d3012201ffffffff
 33 2201d301ffffffff17ffffffffffffff -> 12201d301ffffffff  -> 

Output of SystemTap:

25956 1 33 d3012201ffffffff -> d3012201ffffffff
25949 1 33 2201d301ffffffff -> 2201d301ffffffff
25945 1 59 7ffffffffffffff -> 7ffffffffffffff
25939 1 33 d3012201ffffffff -> d3012201ffffffff
25942 1 61 1fffffffffffffff -> 1fffffffffffffff
25966 1 33 2201d301ffffffff -> 2201d301ffffffff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment