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()

import json
import sys
from collections import defaultdict

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

statsdump = json.dumps(results)
print('statsstart{0}statsend'.format(statsdump))
sys.stdout.flush()
exit()

Fix bug when profiling multiple fcts per module
[pylprof] Fix bug when profiling multiple fcts per module

  import json
+ import sys
+ from collections import defaultdict
+ 
  stats = lp.get_stats()
  unit = stats.unit
  results = {}
- for function, timings in stats.timings.iteritems():
+ for loc, timings in stats.timings.iteritems():
-     module, line, fname = function
+     module, line, fname = loc
-     results[module] = {}
+     if not results.get(module):
+         results[module] = defaultdict(list)
      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)
+ statsdump = json.dumps(results)
- print('statsstart' + jsondump + 'statsend')
+ print('statsstart{0}statsend'.format(statsdump))
  sys.stdout.flush()
  exit()
  
Fix bug when profiling multiple fcts per module
## Code Before:
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()

## Instruction:
Fix bug when profiling multiple fcts per module
## Code After:
import json
import sys
from collections import defaultdict

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

statsdump = json.dumps(results)
print('statsstart{0}statsend'.format(statsdump))
sys.stdout.flush()
exit()
