import json
stats = lp.get_stats()
unit = stats.unit
results = {}
for function, timings in stats.timings.iteritems():
    module, line, fname = function
    results[module] = {}
    for sample in timings:
        linenumber, ncalls, timing = sample
        if not results[module].get(linenumber):
            results[module][linenumber] = []
        results[module][linenumber].append({
            'name' : '',
            'timing' : [ncalls, timing*unit, timing*unit*ncalls]
        })


jsondump = json.dumps(results)
print('statsstart' + jsondump + 'statsend')
sys.stdout.flush()
exit()

@@ -5,16 +5,64 @@
 rt json%0A
+import sys%0Afrom collections import defaultdict%0A%0A
 stats = 
@@ -111,24 +111,19 @@
  %7B%7D%0Afor 
-function
+loc
 , timing
@@ -184,17 +184,48 @@
 e = 
-function%0A
+loc%0A    if not results.get(module):%0A    
     
@@ -242,18 +242,33 @@
 dule%5D = 
-%7B%7D
+defaultdict(list)
 %0A    for
@@ -335,101 +335,8 @@
 ple%0A
-        if not results%5Bmodule%5D.get(linenumber):%0A            results%5Bmodule%5D%5Blinenumber%5D = %5B%5D%0A
     
@@ -380,33 +380,8 @@
 d(%7B%0A
-            'name' : '',%0A
     
@@ -457,13 +457,13 @@
 %7D)%0A%0A
-%0Ajson
+stats
 dump
@@ -506,33 +506,38 @@
 tart
-' + jsondump + 'statsend'
+%7B0%7Dstatsend'.format(statsdump)
 )%0Asy

Fix bug when profiling multiple fcts per module