Created
August 3, 2018 13:59
-
-
Save mpobrien/b0a34acc0b1371026c7d0534036818fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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