blob: 7e206c26b260b498ce2dab21c933df78d68cc02b [file] [log] [blame]
ncteisen3ea4e512017-10-16 14:45:24 -07001#!/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
ncteisen58b2d852017-10-16 14:30:02 -070021
22import sys
23import re
24
25data = sys.stdin.readlines()
26
27errs = []
28for line in data:
ncteisen5f8bf792017-12-11 18:09:31 -080029 # 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 Afshari87cd9942018-01-02 14:40:00 -080042 # explicitly look for the last dereference
ncteisen5f8bf792017-12-11 18:09:31 -080043 elif line[1] == "1" and line[3] == "0":
44 assert (err in errs)
45 errs.remove(err)
ncteisen58b2d852017-10-16 14:30:02 -070046
47print "leaked:", errs