def save_snapshot(self, id, filename):
        self.stop_profiling()
        if filename is not None:
            filename = self.dump_snapshot(filename)
            print('Snapshot saved to %s' % filename)
            response = ProfilerResponse(id=id, snapshot_filepath=filename)
        else:
            response = ProfilerResponse(id=id)
            statsToResponse(self.get_snapshot(), response)


        self.writer.addCommand(response)
        self.start_profiling()
    def save_snapshot(self, id, filename, send_stat=False):
        self.stop_profiling()
        if filename is not None:
            filename = self.dump_snapshot(filename)
            print('Snapshot saved to %s' % filename)

        if not send_stat:
            response = ProfilerResponse(id=id, snapshot_filepath=filename)
        else:
            response = ProfilerResponse(id=id)
            statsToResponse(self.get_snapshot(), response)

        self.writer.addCommand(response)
        self.start_profiling()
from _prof_imports import TSerialization
from _prof_imports import TBinaryProtocol
from _prof_imports import ProfilerResponse
from _prof_imports import IS_PY3K


if __name__ == '__main__':

    file_name = sys.argv[1]

    stats = pstats.Stats(file_name)

    m = ProfilerResponse(id=0)

    statsToResponse(stats.stats, m)

    data = TSerialization.serialize(m, TBinaryProtocol.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()
import sys
import pstats

from prof_util import statsToResponse

from _prof_imports import TSerialization
from _prof_imports import TJSONProtocol
from _prof_imports import ProfilerResponse
from _prof_imports import IS_PY3K

if __name__ == '__main__':

    file_name = sys.argv[1]

    stats = pstats.Stats(file_name)

    m = ProfilerResponse(id=0)

    statsToResponse(stats.stats, m)

    data = TSerialization.serialize(m, TJSONProtocol.TJSONProtocolFactory())

    if IS_PY3K:
        data = data.decode("utf-8")

    sys.stdout.write(data)
    sys.stdout.flush()