Skip to content

Instantly share code, notes, and snippets.

@mpobrien
Created August 3, 2018 13:59
Show Gist options
  • Save mpobrien/b0a34acc0b1371026c7d0534036818fb to your computer and use it in GitHub Desktop.
Save mpobrien/b0a34acc0b1371026c7d0534036818fb to your computer and use it in GitHub Desktop.
import fileinput
import re
goroutine_hdr = re.compile('^goroutine (\d+) \[([\w\s,]+)\]:$')
funccall_params = re.compile('(.*)\([^\)]*\)$')
def main():
goroutines = []
currentgoroutine = None
for line in fileinput.input():
matchheader = goroutine_hdr.match(line)
if matchheader:
if currentgoroutine:
goroutines.append(currentgoroutine)
currentgoroutine = {
'id': matchheader.group(1),
'state': matchheader.group(2),
'lines': []
}
else:
if currentgoroutine:
line = line.strip()
currentgoroutine['lines'].append(line)
if len(currentgoroutine['lines']) == 1:
fcmatch = funccall_params.match(line)
if fcmatch:
currentgoroutine['origin'] = fcmatch.group(1)
if currentgoroutine:
goroutines.append(currentgoroutine)
for i, gr in enumerate(goroutines):
print gr['origin'], gr['state']
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment