ncteisen | 3ea4e51 | 2017-10-16 14:45:24 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | # |
| 3 | # Copyright 2017 gRPC authors. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Reads stdin to find error_refcount log lines, and prints reference leaks |
| 18 | # to stdout |
| 19 | |
| 20 | # usege: python error_ref_leak < logfile.txt |
ncteisen | 58b2d85 | 2017-10-16 14:30:02 -0700 | [diff] [blame] | 21 | |
| 22 | import sys |
| 23 | import re |
| 24 | |
| 25 | data = sys.stdin.readlines() |
| 26 | |
| 27 | errs = [] |
| 28 | for line in data: |
ncteisen | 5f8bf79 | 2017-12-11 18:09:31 -0800 | [diff] [blame] | 29 | # if we care about the line |
| 30 | if re.search(r'error.cc', line): |
| 31 | # str manip to cut off left part of log line |
| 32 | line = line.partition('error.cc:')[-1] |
| 33 | line = re.sub(r'\d+] ', r'', line) |
| 34 | line = line.strip().split() |
| 35 | err = line[0].strip(":") |
| 36 | if line[1] == "create": |
| 37 | assert (err not in errs) |
| 38 | errs.append(err) |
| 39 | elif line[0] == "realloc": |
| 40 | errs.remove(line[1]) |
| 41 | errs.append(line[3]) |
Mehrdad Afshari | 87cd994 | 2018-01-02 14:40:00 -0800 | [diff] [blame] | 42 | # explicitly look for the last dereference |
ncteisen | 5f8bf79 | 2017-12-11 18:09:31 -0800 | [diff] [blame] | 43 | elif line[1] == "1" and line[3] == "0": |
| 44 | assert (err in errs) |
| 45 | errs.remove(err) |
ncteisen | 58b2d85 | 2017-10-16 14:30:02 -0700 | [diff] [blame] | 46 | |
| 47 | print "leaked:", errs |