check to see how much of the buffer is being used
480514
def check_buffer(coords, length, buffer):
    
    s = min(coords[0], buffer)
    e = min(length - coords[1], buffer)
    return [s, e]
162471
def _spill(self):
        
        global MemoryBytesSpilled, DiskBytesSpilled
        if self._file is None:
            self._open_file()

        used_memory = get_used_memory()
        pos = self._file.tell()
        self._ser.dump_stream(self.values, self._file)
        self.values = []
        gc.collect()
        DiskBytesSpilled += self._file.tell() - pos
        MemoryBytesSpilled += max(used_memory - get_used_memory(), 0) << 20
618468
def _gather_buffer_space():
    '''
    
    '''
    if HAS_PSUTIL and psutil.version_info >= (0, 6, 0):
        # Oh good, we have psutil. This will be quick.
        total_mem = psutil.virtual_memory().total
    else:
        # Avoid loading core grains unless absolutely required
        import platform
        import salt.grains.core
        # We need to load up ``mem_total`` grain. Let's mimic required OS data.
        os_data = {'kernel': platform.system()}
        grains = salt.grains.core._memdata(os_data)
        total_mem = grains['mem_total'] * 1024 * 1024
    # Return the higher number between 5% of the system memory and 10MiB
    return max([total_mem * 0.05, 10 << 20])
548000
function bufferedPercent(buffered, duration) {
  var bufferedDuration = 0;
  var start = void 0;
  var end = void 0;

  if (!duration) {
    return 0;
  }

  if (!buffered || !buffered.length) {
    buffered = (0, _timeRanges.createTimeRange)(0, 0);
  }

  for (var i = 0; i < buffered.length; i++) {
    start = buffered.start(i);
    end = buffered.end(i);

    // buffered end can be bigger than duration by a very small fraction
    if (end > duration) {
      end = duration;
    }

    bufferedDuration += end - start;
  }

  return bufferedDuration / duration;
}
561984
protected void ensureCapacity() {
        if(_buffer.remaining() < 8) {
            ByteBuffer b = ByteBuffer.allocate(_buffer.capacity() << 1);
            _buffer.flip();
            b.put(_buffer);
            _buffer = b;
        }
    }
142283
def blocksize(self, input_totalframes):
        """"""

        blocksize = input_totalframes
        if self.pad:
            mod = input_totalframes % self.buffer_size
            if mod:
                blocksize += self.buffer_size - mod

        return blocksize
1142861
def _maybe_warn_about_buffer_size():
    
    global _last_warning

    if not _last_warning:
        _last_warning = time.time()

    if _buffer_size > _warn_threshold and (time.time() - _last_warning) > 120:
        LOGGER.warning('InfluxDB measurement buffer has %i entries',
                       _buffer_size)
761296
def get_buffer(self):
        """"""
        buffer_size = self.reply.size()
        data = self.reply.read(buffer_size)
        self.downloaded_file_buffer.append(data)
1341552
function continue_from_buffer(data) {

    var durations = continue_durations_from_hex_buffer(data);

    var on = durations[0];
    var off = durations[1];
    var stop = durations[2];

    return (8900 < on && on < 9200) &&
        (-2350 < off && off < -2100) &&
        (500 < stop && stop < 650);
}
1039762
private void checkUserFileBufferBytes() {
    if (!isSet(PropertyKey.USER_FILE_BUFFER_BYTES)) { // load from hadoop conf
      return;
    }
    long usrFileBufferBytes = getBytes(PropertyKey.USER_FILE_BUFFER_BYTES);
    Preconditions.checkState((usrFileBufferBytes & Integer.MAX_VALUE) == usrFileBufferBytes,
        PreconditionMessage.INVALID_USER_FILE_BUFFER_BYTES.toString(),
        PropertyKey.Name.USER_FILE_BUFFER_BYTES, usrFileBufferBytes);
  }
693999
def readBuffer(self, newLength):
        
        result = Buffer(self.buf, self.offset, newLength)
        self.skip(newLength)
        return result
99089
def is_full(self):
        """"""
        if self.length == 0.0:
            return False
        if len(self.bar) == 0:
            return False
        if self.current_beat >= self.length - 0.001:
            return True
        return False
1044996
def _check_limit(self):
        """"""

        # First compress
        self._compress()

        # Then check the max size
        if len(self._store) >= self._max_size:
            self._store.popitem(last=False)
1054830
def find_usage(self):
        
        logger.debug("Checking usage for service %s", self.service_name)
        for lim in self.limits.values():
            lim._reset_usage()
        try:
            self.connect()
            resp = self.conn.get_send_quota()
        except EndpointConnectionError as ex:
            logger.warning('Skipping SES: %s', str(ex))
            return
        except ClientError as ex:
            if ex.response['Error']['Code'] in ['AccessDenied', '503']:
                logger.warning('Skipping SES: %s', ex)
                return
            raise
        self.limits['Daily sending quota']._add_current_usage(
            resp['SentLast24Hours']
        )
        self._have_usage = True
        logger.debug("Done checking usage.")
1212055
public void logBufferUtilization() {
		System.out.println("Buffer utilization at " + System.currentTimeMillis());

		System.out.println("\tUnused global buffers: " + this.globalBufferPool.numAvailableBuffers());

		System.out.println("\tLocal buffer pool status:");

		for (LocalBufferPoolOwner bufferPool : this.localBuffersPools.values()) {
			bufferPool.logBufferUtilization();
		}

		System.out.println("\tIncoming connections:");

		for (Channel channel : this.channels.values()) {
			if (channel.isInputChannel()) {
				((InputChannel<?>) channel).logQueuedEnvelopes();
			}
		}
	}
294372
def _gather_buffers(self, event: Message):
        
        if isinstance(event, BytesMessage):
            buf = self._byte_buffer
        else:
            buf = self._string_buffer

        # yay for code shortening
        buf.write(event.data)
        buf.seek(0)
        data = buf.read()
        buf.seek(0)
        buf.truncate()
        return data
388640
def find_usage(self):
        
        logger.debug("Checking usage for service %s", self.service_name)
        for lim in self.limits.values():
            lim._reset_usage()
        self._update_limits_from_api()
        self._have_usage = True
        logger.debug("Done checking usage.")