Example #1
0
def send_message(sock, message):
    """ Send a serialized message (protobuf Message interface)
        to a socket, prepended by its length packed in 4
        bytes (big endian).
    """
    s = serialize(message, TBinaryProtocolFactory())
    packed_len = struct.pack('>L', len(s))
    sock.sendall(packed_len + s)
def send_message(sock, message):
    """ Send a serialized message (protobuf Message interface)
        to a socket, prepended by its length packed in 4
        bytes (big endian).
    """
    s = serialize(message, TBinaryProtocolFactory())
    packed_len = struct.pack('>L', len(s))
    sock.sendall(packed_len + s)
Example #3
0
from prof_util import stats_to_response

if __name__ == '__main__':

    filename = sys.argv[1]

    m = ProfilerResponse(id=0)

    if filename.endswith('.prof'):
        import vmprof_profiler
        vmprof_profiler.tree_stats_to_response(filename, m)
    else:
        stats = pstats.Stats(filename)
        stats_to_response(stats.stats, m)

    data = serialize(m, TBinaryProtocolFactory())

    # setup stdout to write binary data to it
    if IS_PY3K:
        out = sys.stdout.buffer
    elif sys.platform == 'win32':
        import os, msvcrt
        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        out = sys.stdout
    else:
        out = sys.stdout

    out.write(data)
    out.flush()

if __name__ == "__main__":

    filename = sys.argv[1]

    m = ProfilerResponse(id=0)

    if filename.endswith(".prof"):
        import vmprof_profiler

        vmprof_profiler.tree_stats_to_response(filename, m)
    else:
        stats = pstats.Stats(filename)
        stats_to_response(stats.stats, m)

    data = serialize(m, TBinaryProtocolFactory())

    # setup stdout to write binary data to it
    if IS_PY3K:
        out = sys.stdout.buffer
    elif sys.platform == "win32":
        import os, msvcrt

        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        out = sys.stdout
    else:
        out = sys.stdout

    out.write(data)
    out.flush()