为什么valgrind没有在我的试卷上输出任何东西

2024-09-30 20:23:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我看不到valgrind的输出

我使用valgrind检测另一个大程序的内存泄漏,所以我找到了它的位置(至少我认为我找到了),但是当我使用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)

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

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==
~ 

这一切的原因是什么


Tags: nameinnonefordataifschemaly