Skip to content

Instantly share code, notes, and snippets.

View myaut's full-sized avatar

Sergey Klyaus myaut

  • Yandex
  • Serbia, Belgrade
View GitHub Profile
@myaut
myaut / stderrbuf.md
Last active August 29, 2015 14:21
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")) {
@myaut
myaut / scsisupport.py
Created April 12, 2015 16:58
Crunching linux kernel modules to find supported pci ids
import subprocess
import os
import re
PCIIDS = '/usr/share/pci.ids'
DRVDIR = 'drivers/scsi'
# Build pci ids database
pci_ids = {}
@myaut
myaut / mplog.py
Created April 9, 2015 15:12
Multiprocess grep in Python
from multiprocessing import Pool
from itertools import chain
import re
import sys
PROC_COUNT = 8
LINES_PER_PROC = 40
if len(sys.argv) != 3:
@myaut
myaut / Makefile
Created April 9, 2015 14:43
Small multithreaded malloc() benchmark
CFLAGS = -g
CC = gcc
LDFLAGS = -lrt
OBJS = common.o algorithm.o libptmalloc3.a
algorithm.o: algorithm.c algorithm.h
$(CC) $(CFLAGS) -o $@ -c algorithm.c
common.o: common.c common.h
@myaut
myaut / schedstat.py
Created April 3, 2015 07:56
schedstat reads data from /proc/schedstat on Linux, compares values and prints difference to terminal
import time
import os
import math
cpu_stats = ['yld_count',
'sched_count', 'sched_goidle',
'ttwu_count', 'ttwu_local',
'rq_cpu_time',
'rq_sched_info.run_delay', 'rq_sched_info.pcount']
cpu_idle_types = ['CPU_IDLE', 'CPU_NOT_IDLE', 'CPU_NEWLY_IDLE']
@myaut
myaut / stap-debian.txt
Created March 30, 2015 07:22
Example of usage of SystemTap in Debian
root@r520:~# apt-get update
Hit http://mirror.yandex.ru wheezy Release.gpg
Hit http://mirror.yandex.ru wheezy Release
Hit http://mirror.yandex.ru wheezy/main Sources
Hit http://mirror.yandex.ru wheezy/main amd64 Packages
Hit http://mirror.yandex.ru wheezy/main i386 Packages
Hit http://mirror.yandex.ru wheezy/main Translation-en
Reading package lists... Done
root@r520:~# stap -e 'probe kprocess.exec { println(argstr); }'
@myaut
myaut / sol11-dupip.md
Created March 17, 2015 20:38
How to create duplicate IP addresses on network interface in Solaris 11

Consider following configuration (Solaris 11):

root@sol112:~# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000 
net0: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 2
        inet 192.168.24.33 netmask ffffff00 broadcast 192.168.24.255
        ether 8:0:27:75:c9:5d 
net1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
#include <unordered_map>
#include <mutex>
#include <list>
#include <future>
#include <iostream>
#include <chrono>
#include <algorithm>
#include <atomic>
#include "tbb/concurrent_unordered_map.h"
@myaut
myaut / nodemem.c
Created March 10, 2015 10:10
nodemem.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <linux/perf_event.h>
#include <sys/syscall.h>
#include <asm/unistd.h>
#include <sys/mman.h>
#include <numaif.h>
@myaut
myaut / aas.c
Created March 6, 2015 19:28
Auto-allocated strings
#include <stdlib.h>
#include <string.h>
#ifdef AAS_STRICT
typedef struct { char a; } *aas_t;
#else
typedef char *aas_t;
#endif
#define AAS_DYNAMIC 'D'