parameters: (self)
return_statement: return queue_info
docstring: Computes queuing information for each request.
  
      We determine blocking requests by looking at which urls are in-flight
      (created but not yet destroyed) at the time of the creation of each
      request. This means that a request that we list as blocking may just be
      queued (throttled) at the same time as our request, and not actually
      blocking.
  
      The lifetime of the queuing events extends from when a resource is first
      slotted into the sytem until the request is complete. The main interesting
      queuing events are begin, end (which define the lifetime) and ready, an
      instant event that is usually within a millisecond after the request_time of
      the Request.
  
      Returns:
        {request_track.Request:
           (start_msec: throttle start, end_msec: throttle end,
            ready_msec: ready,
            blocking: [blocking requests],
            source_ids: [source ids of the request])}, where the map values are
        a named tuple with the specified fields.
docstring_summary: Computes queuing information for each request.
docstring_tokens: Computes queuing information for each request .
function: def GenerateRequestQueuing(self):
      """Computes queuing information for each request.
  
      We determine blocking requests by looking at which urls are in-flight
      (created but not yet destroyed) at the time of the creation of each
      request. This means that a request that we list as blocking may just be
      queued (throttled) at the same time as our request, and not actually
      blocking.
  
      The lifetime of the queuing events extends from when a resource is first
      slotted into the sytem until the request is complete. The main interesting
      queuing events are begin, end (which define the lifetime) and ready, an
      instant event that is usually within a millisecond after the request_time of
      the Request.
  
      Returns:
        {request_track.Request:
           (start_msec: throttle start, end_msec: throttle end,
            ready_msec: ready,
            blocking: [blocking requests],
            source_ids: [source ids of the request])}, where the map values are
        a named tuple with the specified fields.
      """
      url_to_requests = collections.defaultdict(list)
      for rq in self._request_track.GetEvents():
        url_to_requests[rq.url].append(rq)
      # Queuing events are organized by source id, which corresponds to a load of
      # a url. First collect timing information for each source id, then associate
      # with each request.
      timing_by_source_id = {}
      for source_id, events in self._queuing_events_by_id.iteritems():
        assert all(e.end_msec is None for e in events), \
            'Unexpected end_msec for nested async queuing events'
        ready_times = [e.start_msec for e in events if e.name == self.READY_NAME]
        if not ready_times:
          ready_msec = None
        else:
          assert len(ready_times) == 1, events
          ready_msec = ready_times[0]
        timing_by_source_id[source_id] = (
            min(e.start_msec for e in events),
            max(e.start_msec for e in events),
            ready_msec)
      queue_info = {}
      for request_url, requests in url_to_requests.iteritems():
        matching_source_ids = set(
            source_id for source_id, url in self._source_id_to_url.iteritems()
            if url == request_url)
        if len(matching_source_ids) > 1:
          logging.warning('Multiple matching source ids, probably duplicated'
                          'urls: %s', [rq.url for rq in requests])
        # Get first source id.
        sid = next(s for s in matching_source_ids) \
            if matching_source_ids else None
        (throttle_start_msec, throttle_end_msec, ready_msec) = \
           timing_by_source_id[sid] if matching_source_ids else (-1, -1, -1)
  
        blocking_requests = []
        for sid, (flight_start_msec,
                  flight_end_msec, _)  in timing_by_source_id.iteritems():
          if (flight_start_msec < throttle_start_msec and
              flight_end_msec > throttle_start_msec and
              flight_end_msec < throttle_end_msec):
            blocking_requests.extend(
                url_to_requests.get(self._source_id_to_url[sid], []))
  
        info = collections.namedtuple(
            'QueueInfo', ['start_msec', 'end_msec', 'ready_msec', 'blocking'
                          'source_ids'])
        info.start_msec = throttle_start_msec
        info.end_msec = throttle_end_msec
        info.ready_msec = ready_msec
        current_request_ids = set(rq.request_id for rq in requests)
        info.blocking = [b for b in blocking_requests
                         if b is not None and
                         b.request_id not in current_request_ids]
        info.source_ids = matching_source_ids
        for rq in requests:
          queue_info[rq] = info
      return queue_info
function_tokens: def GenerateRequestQueuing ( self ) : url_to_requests = collections . defaultdict ( list ) for rq in self . _request_track . GetEvents ( ) : url_to_requests [ rq . url ] . append ( rq ) # Queuing events are organized by source id, which corresponds to a load of # a url. First collect timing information for each source id, then associate # with each request. timing_by_source_id = { } for source_id , events in self . _queuing_events_by_id . iteritems ( ) : assert all ( e . end_msec is None for e in events ) , 'Unexpected end_msec for nested async queuing events' ready_times = [ e . start_msec for e in events if e . name == self . READY_NAME ] if not ready_times : ready_msec = None else : assert len ( ready_times ) == 1 , events ready_msec = ready_times [ 0 ] timing_by_source_id [ source_id ] = ( min ( e . start_msec for e in events ) , max ( e . start_msec for e in events ) , ready_msec ) queue_info = { } for request_url , requests in url_to_requests . iteritems ( ) : matching_source_ids = set ( source_id for source_id , url in self . _source_id_to_url . iteritems ( ) if url == request_url ) if len ( matching_source_ids ) > 1 : logging . warning ( 'Multiple matching source ids, probably duplicated' 'urls: %s' , [ rq . url for rq in requests ] ) # Get first source id. sid = next ( s for s in matching_source_ids ) if matching_source_ids else None ( throttle_start_msec , throttle_end_msec , ready_msec ) = timing_by_source_id [ sid ] if matching_source_ids else ( - 1 , - 1 , - 1 ) blocking_requests = [ ] for sid , ( flight_start_msec , flight_end_msec , _ ) in timing_by_source_id . iteritems ( ) : if ( flight_start_msec < throttle_start_msec and flight_end_msec > throttle_start_msec and flight_end_msec < throttle_end_msec ) : blocking_requests . extend ( url_to_requests . get ( self . _source_id_to_url [ sid ] , [ ] ) ) info = collections . namedtuple ( 'QueueInfo' , [ 'start_msec' , 'end_msec' , 'ready_msec' , 'blocking' 'source_ids' ] ) info . start_msec = throttle_start_msec info . end_msec = throttle_end_msec info . ready_msec = ready_msec current_request_ids = set ( rq . request_id for rq in requests ) info . blocking = [ b for b in blocking_requests if b is not None and b . request_id not in current_request_ids ] info . source_ids = matching_source_ids for rq in requests : queue_info [ rq ] = info return queue_info