代码之家  ›  专栏  ›  技术社区  ›  Roman Starkov

如何解析性能“pickle”二进制输出?

  •  2
  • Roman Starkov  · 技术社区  · 16 年前

    performce命令行有一个特殊的开关-g,该开关假定使用Python的“pickle”序列化格式使其输出具有机器可读性。一般来说,这是真的吗?

    例如,考虑 p4 -G diff -duw3 <file1> <file2> <file3> . 据我所知,输出是一个序列:pickle、raw diff、pickle、raw diff、pickle、raw diff。它似乎不包含任何能使人可靠定位pickle/diff边界的分隔符。

    我是缺少什么东西,还是这种“机器可读”格式实际上不是机器可读的?我怎样才能找到泡菜和生的差异之间的界限呢?

    1 回复  |  直到 16 年前
        1
  •  5
  •   Douglas Leeder    16 年前

    p4 -G 将其数据输出到 marshal 未腌制过的形状。

    但你是对的- p4 -G diff -duw3 也不会联合国 元帅 ,所以我想有个问题。

    p4 -G opened 但取消标记很好。不管怎样 diff 失败。

    以下是相关的知识库文章: http://kb.perforce.com/ToolsScripts/PerforceUtilities/UsingP4G

    #!/usr/bin/env python
    import marshal
    import subprocess
    
    # proc = subprocess.Popen(["p4","-G","diff","-duw3","configure.ac","Makefile.am"],stdout=subprocess.PIPE)
    proc = subprocess.Popen(["p4","-G","diff"],stdout=subprocess.PIPE)
    # proc = subprocess.Popen(["p4","-G","opened"],stdout=subprocess.PIPE)
    pipe = proc.stdout
    output = []
    try:
        while 1:
            record = marshal.load(pipe)
            output.append(record)
    except EOFError:
        pass
    pipe.close()
    proc.wait()
    
    # print list of dictionary records
    c = 0
    for dict in output:
        c = c + 1
        print "\n--%d--" % c
        for key in dict.keys():
            print "%s: %s" % ( key, dict[key] )