为什么valgrind在我的测试脚本上不输出任何内容

时间:2019-07-09 14:40:50

标签: python ubuntu memory-leaks

我看不到valgrind输出

我使用valgrind来检测另一个大型程序上的内存泄漏,所以我发现了它在哪里(至少我以为是这样),但是当我使用valgrind时,它甚至不输出任何内容,即使是HEAD Summary。

我希望能够运行该程序,并查看valgrind通常给出的日志记录消息

#!/usr/bin/env python2
import logging, time
import yang as ly
import libsysrepoPython2 as sysrepo

if __name__ == "__main__":
    app_name = "unknown"
    active_datastore = "running"
    connection = None
    session = None
    lock_file = "/tmp/sysrepo_lock"
    yang_folder = "/etc/sysrepo/yang"
    data_folder = "/etc/sysrepo/data"
    module_name = "ucpe"
    ctx = None
    priority = 0

    root = None
    data_list = None
    xpath="/ucpe:config/interfaces:interface[name='nat0']/port-forwarding-all"
    configured = False
    testNum = 0


    for i in range(0,100):
        try:
            #This is just for initial configuration
            if not configured:
                configured = True
                if not connection:
                    connection = sysrepo.Connection(app_name, sysrepo.SR_CONN_DAEMON_REQUIRED)
                if not session:
                    session = sysrepo.Session(connection)

                schemas = session.list_schemas()
                schema_list = []
                for n in range(0, schemas.schema_cnt()):
                    selected_schema = schemas.schema(n)
                    if str(selected_schema.module_name()).find("sysrepo-") > -1:
                        continue
                    schema_dict = dict()
                    schema_dict['module_name'] = selected_schema.module_name()
                    schema_dict['ns'] = selected_schema.ns()
                    schema_dict['prefix'] = selected_schema.prefix()
                    schema_dict['implemented'] = selected_schema.implemented()
                    schema_dict['revision'] = selected_schema.revision().revision()
                    schema_dict['file'] = selected_schema.revision().file_path_yang()
                    schema_list.append(schema_dict)

                ctx = ly.Context(yang_folder)

                for schema in schema_list:
                    ctx.load_module(schema['module_name'], None)

                root = ctx.parse_data_path("{}/{}.{}".format(data_folder, module_name, active_datastore),
                                        ly.LYD_XML, ly.LYD_OPT_CONFIG)

            for x in range(0,100000):
                data_list = root.child().find_path(xpath).data() # This line here
            #from pudb import set_trace; set_trace()

            for elem in data_list:
                schema = elem.schema()
                if ly.LYS_LEAF == schema.nodetype():
                    casted = elem.subtype()
                    if casted is None:
                        continue
                else:
                    break
            if casted is not None:
                print("Success. Finished: " + casted.value_str())
            else:
                raise Exception(ex)
            testNum += 1

        except Exception as ex:
            time.sleep(.400)
            print("Error! at test{}, {}".format(testNum, ex))

        print("Wait before next test! Test number " + str(testNum) + " finished!")
        time.sleep(5)

我希望看到包含分配和内存释放的完整日志 最后是HEAP摘要。如果我离开脚本足够长的时间,它将占用整个内存,但最终不会输出任何内容。 通过将命令与添加的选项一起使用:

valgrind --log-file=/home/valgrind.log --leak-check=yes --track-origins=yes /home/tinyTest_parse_data_path.py 
I get the output:
==32672== Memcheck, a memory error detector
==32672== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==32672== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==32672== Command: /home/tinyTest_parse_data_path.py
==32672== Parent PID: 16530
==32672==
~ 

这可能是什么原因

0 个答案:

没有答案