mirror of https://github.com/zulip/zulip.git
profiling: Use mkstemp for profile.data filename.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
601b5eb036
commit
79d888223f
|
@ -5,8 +5,10 @@ from mypy_extensions import NoReturn
|
|||
import glob
|
||||
import argparse
|
||||
import os
|
||||
import shlex
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
import ujson
|
||||
import httplib2
|
||||
import httpretty
|
||||
|
@ -441,12 +443,13 @@ if __name__ == "__main__":
|
|||
failures = True
|
||||
if options.profile:
|
||||
prof.disable()
|
||||
prof.dump_stats("/tmp/profile.data")
|
||||
print("Profile data saved to /tmp/profile.data")
|
||||
print("You can visualize it using e.g. `snakeviz /tmp/profile.data`")
|
||||
print("Note: If you are using vagrant for development environment you will need to do:")
|
||||
print("1.) `vagrant ssh -- -L 8080:127.0.0.1:8080`")
|
||||
print("2.) `snakeviz -s /tmp/profile.data`")
|
||||
with tempfile.NamedTemporaryFile(prefix='profile.data.', delete=False) as stats_file:
|
||||
prof.dump_stats(stats_file.name)
|
||||
print("Profile data saved to {}".format(stats_file.name))
|
||||
print("You can visualize it using e.g. `snakeviz {}`".format(shlex.quote(stats_file.name)))
|
||||
print("Note: If you are using vagrant for development environment you will need to do:")
|
||||
print("1.) `vagrant ssh -- -L 8080:127.0.0.1:8080`")
|
||||
print("2.) `snakeviz -s {}`".format(shlex.quote(stats_file.name)))
|
||||
|
||||
if options.report_slow_tests:
|
||||
from zerver.lib.test_runner import report_slow_tests
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import cProfile
|
||||
import logging
|
||||
import tempfile
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.core.management.base import CommandParser
|
||||
|
@ -41,9 +42,10 @@ def profile_request(request: HttpRequest) -> HttpResponse:
|
|||
ret = get_messages_backend(request, request.user,
|
||||
apply_markdown=True)
|
||||
prof.disable()
|
||||
prof.dump_stats("/tmp/profile.data")
|
||||
request_logger.process_response(request, ret)
|
||||
logging.info("Profiling data written to /tmp/profile.data")
|
||||
with tempfile.NamedTemporaryFile(prefix='profile.data.', delete=False) as stats_file:
|
||||
prof.dump_stats(stats_file.name)
|
||||
request_logger.process_response(request, ret)
|
||||
logging.info("Profiling data written to {}".format(stats_file.name))
|
||||
return ret
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
|
|
Loading…
Reference in New Issue