Exemple #1
0
    def __call__(self, environ, start_response):
        request = MiniRequest(environ)

        if request.path_info == self.path:
            # we're being asked to render the profile view
            self.lock.acquire()
            try:
                text = self.index(request)
            finally:
                self.lock.release()
            start_response('200 OK',
                           [('content-type', 'text/html; charset="UTF-8"'),
                            ('content-length', str(len(text)))])
            return [bytes_(text)]

        self.lock.acquire()
        try:
            _locals = locals()
            code = self.unwind and PROFILE_EXEC_EAGER or PROFILE_EXEC_LAZY
            self.profiler.runctx(code, globals(), _locals)

            if self.first_request:  # discard to avoid timing warm-up
                self.profiler = profile.Profile()
                self.first_request = False
            else:
                self.profiler.dump_stats(self.log_filename)
                if HAS_PP2CT and self.cachegrind_filename is not None:
                    stats = pstats.Stats(self.profiler)
                    conv = pyprof2calltree.CalltreeConverter(stats)
                    with open(self.cachegrind_filename, 'w') as grind:
                        conv.output(grind)
            app_iter = _locals['app_iter_']
            return app_iter
        finally:
            self.lock.release()
Exemple #2
0
    def __call__(self, environ, start_response):
        request = MiniRequest(environ)

        if request.path_info == self.path:
            # we're being asked to render the profile view
            #self.lock.acquire()
            try:
                text = self.index(request)
            finally:
                pass
                #self.lock.release()
            start_response('200 OK',
                           [('content-type', 'text/html; charset="UTF-8"'),
                            ('content-length', str(len(text)))])
            return [bytes_(text)]

        #self.lock.acquire()
        try:
            _locals = locals()
            code = self.unwind and PROFILE_EXEC_EAGER or PROFILE_EXEC_LAZY
            self.profiler.runctx(code, globals(), _locals)

            #if self.first_request: # discard to avoid timing warm-up
            #    self.profiler = profile.Profile()
            #    self.first_request = False

            app_iter = _locals['app_iter_']
            return app_iter
        finally:
            pass
Exemple #3
0
    def __call__(self, environ, start_response):
        request = MiniRequest(environ)

        if request.path_info == self.path:
            # we're being asked to render the profile view
            #self.lock.acquire()
            try:
                text = self.index(request)
            finally:
                pass
                #self.lock.release()
            start_response('200 OK', [
                ('content-type', 'text/html; charset="UTF-8"'),
                ('content-length', str(len(text)))])
            return [bytes_(text)]

        #self.lock.acquire()
        try:
            _locals = locals()
            code = self.unwind and PROFILE_EXEC_EAGER or PROFILE_EXEC_LAZY
            self.profiler.runctx(code, globals(), _locals)

            #if self.first_request: # discard to avoid timing warm-up
            #    self.profiler = profile.Profile()
            #    self.first_request = False

            app_iter = _locals['app_iter_']
            return app_iter
        finally:
            pass
Exemple #4
0
    def __call__(self, environ, start_response):
        request = MiniRequest(environ)

        if request.path_info == self.path:
            # we're being asked to render the profile view
            self.lock.acquire()
            try:
                text = self.index(request)
            finally:
                self.lock.release()
            start_response('200 OK', [
                ('content-type', 'text/html; charset="UTF-8"'),
                ('content-length', str(len(text)))])
            return [bytes_(text)]

        self.lock.acquire()
        try:
            _locals = locals()
            code = self.unwind and PROFILE_EXEC_EAGER or PROFILE_EXEC_LAZY
            self.profiler.runctx(code, globals(), _locals)

            if self.first_request: # discard to avoid timing warm-up
                self.profiler = profile.Profile()
                self.first_request = False
            else:
                self.profiler.dump_stats(self.log_filename)
                if HAS_PP2CT and self.cachegrind_filename is not None:
                    stats = pstats.Stats(self.profiler)
                    conv = pyprof2calltree.CalltreeConverter(stats)
                    with open(self.cachegrind_filename, 'w') as grind:
                        conv.output(grind)
            app_iter = _locals['app_iter_']
            return app_iter
        finally:
            self.lock.release()
Exemple #5
0
 def test_index_get_withdata(self):
     request = self._makeRequest({
         'REQUEST_METHOD': 'GET',
         'wsgi.input': '',
     })
     middleware = self._makeOne(None)
     output = BytesIO(bytes_('hello!'))
     html = middleware.index(request, output)
     self.assertTrue('Profiling information is generated' in html)
Exemple #6
0
 def test_index_get_withdata(self):
     request = self._makeRequest({
          'REQUEST_METHOD':'GET',
          'wsgi.input':'',
          })
     middleware = self._makeOne(None)
     output = BytesIO(bytes_('hello!'))
     html = middleware.index(request, output)
     self.assertTrue('Profiling information is generated' in html)
Exemple #7
0
    def test_index_post_withdata_fulldirs(self):
        fields = [("fulldirs", "1"), ("sort", "cumulative"), ("limit", "500"), ("mode", "callers")]
        content_type, body = encode_multipart_formdata(fields)
        request = self._makeRequest(
            {"wsgi.input": BytesIO(body), "CONTENT_TYPE": content_type, "CONTENT_LENGTH": len(body)}
        )

        middleware = self._makeOne(None)
        request.environ["PATH_INFO"] = middleware.path
        output = BytesIO(bytes_("hello!"))
        html = middleware.index(request, output)
        self.assertTrue("Profiling information is generated" in html)
Exemple #8
0
def encode_multipart_formdata(fields):
    BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
    CRLF = '\r\n'
    L = []
    for (key, value) in fields:
        L.append('--' + BOUNDARY)
        L.append('Content-Disposition: form-data; name="%s"' % key)
        L.append('')
        L.append(value)
    L.append('--' + BOUNDARY + '--')
    L.append('')
    body = bytes_(CRLF.join(L))
    content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
    return content_type, body
Exemple #9
0
def encode_multipart_formdata(fields):
    BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
    CRLF = '\r\n'
    L = []
    for (key, value) in fields:
        L.append('--' + BOUNDARY)
        L.append('Content-Disposition: form-data; name="%s"' % key)
        L.append('')
        L.append(value)
    L.append('--' + BOUNDARY + '--')
    L.append('')
    body = bytes_(CRLF.join(L))
    content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
    return content_type, body
Exemple #10
0
def encode_multipart_formdata(fields):
    BOUNDARY = "----------ThIs_Is_tHe_bouNdaRY_$"
    CRLF = "\r\n"
    L = []
    for (key, value) in fields:
        L.append("--" + BOUNDARY)
        L.append('Content-Disposition: form-data; name="%s"' % key)
        L.append("")
        L.append(value)
    L.append("--" + BOUNDARY + "--")
    L.append("")
    body = bytes_(CRLF.join(L))
    content_type = "multipart/form-data; boundary=%s" % BOUNDARY
    return content_type, body
Exemple #11
0
    def test_index_post_withdata_fulldirs(self):
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        request = self._makeRequest({
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
        })

        middleware = self._makeOne(None)
        request.environ['PATH_INFO'] = middleware.path
        output = BytesIO(bytes_('hello!'))
        html = middleware.index(request, output)
        self.assertTrue('Profiling information is generated' in html)
Exemple #12
0
    def test_index_post_withdata_fulldirs(self):
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
            ]
        content_type, body = encode_multipart_formdata(fields)
        request = self._makeRequest(
            {'wsgi.input':BytesIO(body),
             'CONTENT_TYPE':content_type,
             'CONTENT_LENGTH':len(body),
             })

        middleware = self._makeOne(None)
        request.environ['PATH_INFO'] = middleware.path
        output = BytesIO(bytes_('hello!'))
        html = middleware.index(request, output)
        self.assertTrue('Profiling information is generated' in html)
Exemple #13
0
 def test_index_get_withdata(self):
     request = self._makeRequest({"REQUEST_METHOD": "GET", "wsgi.input": ""})
     middleware = self._makeOne(None)
     output = BytesIO(bytes_("hello!"))
     html = middleware.index(request, output)
     self.assertTrue("Profiling information is generated" in html)