#!/usr/bin/env python
import sys
from pprint import pprint

if len(sys.argv) <= 1:
    print "Usage: %s <inputfile>" % sys.argv[0]
    exit(-1)

# from http://brokestream.com/procstat.c / man 5 proc
order = """log_ts pid tcomm state ppid pgid sid tty_nr tty_pgrp flags min_flt cmin_flt
maj_flt cmaj_flt utime stimev cutime cstime priority nicev num_threads
it_real_value start_time vsize rss rsslim start_code end_code start_stack esp
eip pending blocked sigign sigcatch wchan zero1 zero2 exit_signal cpu
rt_priority policy""".split()

keys = """
    log_ts state min_flt maj_flt utime stimev
    num_threads vsize rss
    """.split()

print ",".join(keys)
for line in open(sys.argv[1]).readlines():
    l = line.split()
    d = zip(order, l)
    #pprint(d)
    d = dict(d)

    for i, key in enumerate(keys):
        if i > 0:
            sys.stdout.write(",")
        sys.stdout.write("%s" % d[key])
    sys.stdout.write("\n")
