blob: 6582328a5b8e423ccfac0fe727fe291d55bb9ca5 [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:
ncteisen3ea4e512017-10-16 14:45:24 -070029 # if we care about the line
ncteisen58b2d852017-10-16 14:30:02 -070030 if re.search(r'error.cc', line):
ncteisen3ea4e512017-10-16 14:45:24 -070031 # str manip to cut off left part of log line
ncteisen58b2d852017-10-16 14:30:02 -070032 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])
ncteisen3ea4e512017-10-16 14:45:24 -070042 # explicitly look for the last dereference
ncteisen58b2d852017-10-16 14:30:02 -070043 elif line[1] == "1" and line[3] == "0":
ncteisen58b2d852017-10-16 14:30:02 -070044 assert(err in errs)
45 errs.remove(err)
46
47print "leaked:", errs