Ejemplo n.º 1
0
	def _write_data(self, request):
		"""
		Write data to redis instance which is also used for cache.
		"""
		client = get_connection()
		rid = client.incr('request_count')
		if request.user.is_authenticated():
			uid = request.user.pk
		else:
			uid = 0
		data = {'middleware_queries': self.middleware_queries_count, 'middleware_queries_time': self.middleware_queries_time,
				'path': request.path, 'user_id': uid, 'view_queries_time': self.view_queries_time, 'view_queries': self.view_queries_count,'total_time': self.total_time}
		client.hmset('request:%d' % rid, data)
		client.sadd('request_ids', rid)
    def handle(self, *args, **options):
        client = get_connection()
        rids = client.smembers('request_ids')
        pipe = client.pipeline(transaction=False)
        for rid in rids:
            pipe.hgetall('request:%s' % rid)

        results = pipe.execute()
        self.stdout.write('Request path, User id, Middleware queries, Middleware queries time (ms), View queries, View queries time (ms), Request total time (ms)\n')
        for r in results:
            self.stdout.write('%(path)s, %(user_id)s, %(middleware_queries)s, %(middleware_queries_time)s, %(view_queries)s, %(view_queries_time)s, %(total_time)s\n' % r)
            
        if options['clear_stats'] and len(rids)>0:
            client.srem('request_ids', *list(rids))