#!/usr/bin/env python

import sys
import os
import struct

if len(sys.argv) != 2:
    print "usage: %s closed-calls-filename" % sys.argv[0]
    sys.exit(1)

file_size = os.path.getsize(sys.argv[1])
block_size = 4096
# The closed-calls file is a sequence of 8-bytes unsigned long long (Q)
marshaller = struct.Struct("Q")
count = 0

with open(sys.argv[1], "r") as f:
    print "count,call-id"
    while file_size > 0:
        if block_size > file_size:
            block_size = file_size
        block = f.read(block_size)
        offset = 0
        while offset < block_size:
            if (block_size - offset) < marshaller.size:
                break
            (call_id, ) = marshaller.unpack_from(block, offset)
            print "%d,%d" % (count, call_id)
            offset += marshaller.size
            count += 1
        file_size -= block_size
