return the sleep time in msec
334337
protected long calculateSleepTime() {
        Calendar c = new GregorianCalendar();
        int currentHour = c.get(Calendar.HOUR_OF_DAY);
        int currentMin = c.get(Calendar.MINUTE);
        int currentSec = c.get(Calendar.SECOND);
        long stime = SECONDS_FOR_24_HOURS - ((currentHour * 60 + currentMin) * 60 + currentSec) + cleanupHour * 60 * 60;
        if (stime > SECONDS_FOR_24_HOURS) {
            stime = stime - SECONDS_FOR_24_HOURS;
        }
        if (stime < 10) {
            stime = 10;
        }
        stime = stime * 1000; // convert to msec
        return stime;
    }
597182
function get_cpu_idle() {
  var idle = 0;
  var cpus = os.cpus();
  var i, len;
  for (i=0, len = cpus.length; i < len; i += 1) {
    var cpu = cpus[i];
    var total = cpu.times.sys + cpu.times.idle + cpu.times.user + cpu.times.nice + cpu.times.irq;
    idle += (cpu.times.idle/total*100);
  }
  idle = idle / cpus.length;
  return idle;
}
343997
def get_hwclock():
    '''
    
    '''
    if salt.utils.path.which('timedatectl'):
        ret = _timedatectl()
        for line in (x.strip() for x in ret['stdout'].splitlines()):
            if 'rtc in local tz' in line.lower():
                try:
                    if line.split(':')[-1].strip().lower() == 'yes':
                        return 'localtime'
                    else:
                        return 'UTC'
                except IndexError:
                    pass

        msg = ('Failed to parse timedatectl output: {0}\n'
               'Please file an issue with SaltStack').format(ret['stdout'])
        raise CommandExecutionError(msg)

    else:
        os_family = __grains__['os_family']
        for family in ('RedHat', 'Suse', 'NILinuxRT'):
            if family in os_family:
                return _get_adjtime_timezone()

        if 'Debian' in __grains__['os_family']:
            # Original way to look up hwclock on Debian-based systems
            try:
                with salt.utils.files.fopen('/etc/default/rcS', 'r') as fp_:
                    for line in fp_:
                        line = salt.utils.stringutils.to_unicode(line)
                        if re.match(r'^\s*#', line):
                            continue
                        if 'UTC=' in line:
                            is_utc = line.rstrip('\n').split('=')[-1].lower()
                            if is_utc == 'yes':
                                return 'UTC'
                            else:
                                return 'localtime'
            except IOError as exc:
                pass
            # Since Wheezy
            return _get_adjtime_timezone()

        if 'Gentoo' in __grains__['os_family']:
            if not os.path.exists('/etc/adjtime'):
                offset_file = '/etc/conf.d/hwclock'
                try:
                    with salt.utils.files.fopen(offset_file, 'r') as fp_:
                        for line in fp_:
                            line = salt.utils.stringutils.to_unicode(line)
                            if line.startswith('clock='):
                                line = line.rstrip('\n')
                                line = line.split('=')[-1].strip('\'"')
                                if line == 'UTC':
                                    return line
                                if line == 'local':
                                    return 'LOCAL'
                        raise CommandExecutionError(
                            'Correct offset value not found in {0}'
                            .format(offset_file)
                        )
                except IOError as exc:
                    raise CommandExecutionError(
                        'Problem reading offset file {0}: {1}'
                        .format(offset_file, exc.strerror)
                    )
            return _get_adjtime_timezone()

        if 'Solaris' in __grains__['os_family']:
            offset_file = '/etc/rtc_config'
            try:
                with salt.utils.files.fopen(offset_file, 'r') as fp_:
                    for line in fp_:
                        line = salt.utils.stringutils.to_unicode(line)
                        if line.startswith('zone_info=GMT'):
                            return 'UTC'
                    return 'localtime'
            except IOError as exc:
                if exc.errno == errno.ENOENT:
                    # offset file does not exist
                    return 'UTC'
                raise CommandExecutionError(
                    'Problem reading offset file {0}: {1}'
                    .format(offset_file, exc.strerror)
                )

        if 'AIX' in __grains__['os_family']:
            offset_file = '/etc/environment'
            try:
                with salt.utils.files.fopen(offset_file, 'r') as fp_:
                    for line in fp_:
                        line = salt.utils.stringutils.to_unicode(line)
                        if line.startswith('TZ=UTC'):
                            return 'UTC'
                    return 'localtime'
            except IOError as exc:
                if exc.errno == errno.ENOENT:
                    # offset file does not exist
                    return 'UTC'
                raise CommandExecutionError(
                    'Problem reading offset file {0}: {1}'
                    .format(offset_file, exc.strerror)
                )
408009
def wait(self, timeout=None):
        """"""
        logger = logging.getLogger(__name__)
        if int(self.max_sleep_interval) < int(self._min_sleep_interval):
            self.max_sleep_interval = int(self._min_sleep_interval)
        t0 = time.time()
        sleep_seconds = min(5, self.max_sleep_interval)
        status = self.status
        prev_status = status
        while status < COMPLETED:
            logger.debug("sleep for %d seconds", sleep_seconds)
            time.sleep(sleep_seconds)
            if 2*sleep_seconds <= self.max_sleep_interval:
                sleep_seconds *= 2
            if timeout is not None:
                if int(time.time() - t0) > int(timeout):
                    return
            status = self.status
            if status != prev_status:
                sleep_seconds = min(5, self.max_sleep_interval)
                prev_status = status
244379
def pttl(self, key):
        
        """
        Returns time to live in milliseconds if output_ms is True, else returns seconds.
        """
        key = self._encode(key)
        if key not in self.redis:
            # as of redis 2.8, -2 is returned if the key does not exist
            return long(-2) if self.strict else None
        if key not in self.timeouts:
            # as of redis 2.8, -1 is returned if the key is persistent
            # redis-py returns None; command docs say -1
            return long(-1) if self.strict else None

        time_to_live = get_total_milliseconds(self.timeouts[key] - self.clock.now())
        return long(max(-1, time_to_live))
1101155
def responsive_sleep(self, seconds, wait_reason=''):
        """"""
        for x in xrange(int(seconds)):
            if (self.config.wait_log_interval and
                    not x % self.config.wait_log_interval):
                self.config.logger.debug(
                    '%s: %dsec of %dsec' % (wait_reason, x, seconds)
                )
            self.quit_check()
            time.sleep(1.0)
976982
def get_using_network_time():
    '''
    
    '''
    ret = salt.utils.mac_utils.execute_return_result(
        'systemsetup -getusingnetworktime')

    return salt.utils.mac_utils.validate_enabled(
        salt.utils.mac_utils.parse_return(ret)) == 'on'
301861
def get_harddisk_sleep():
    '''
    
    '''
    ret = salt.utils.mac_utils.execute_return_result(
        'systemsetup -getharddisksleep')
    return salt.utils.mac_utils.parse_return(ret)
733588
def sleep(self, seconds=0.05, dt=0.01):
        
        t0 = _t.time()
        while _t.time()-t0 < seconds:
            
            # Pause a bit to avoid heavy CPU
            _t.sleep(dt)
            
            # process events
            self.process_events()
334386
def responsive_sleep(self, seconds, wait_reason=''):
        """"""
        for x in range(int(seconds)):
            if (self.config.wait_log_interval and
                not x % self.config.wait_log_interval):
                print('%s: %dsec of %dsec' % (wait_reason,
                                              x,
                                              seconds))
            time.sleep(1.0)
151884
def _adapt_sleep_interval(self, sent, received, queue, now):
        
        Global.LOGGER.debug("adjusting sleep interval")

        dispatched_since_last_check = sent - self.last_queue_check_count
        seconds_since_last_check = (
            now - self.last_queue_check_date).total_seconds()

        Global.LOGGER.debug(
            str(dispatched_since_last_check) + " dispatched in the last " + str(seconds_since_last_check))
        sleep_time = (seconds_since_last_check /
                      (dispatched_since_last_check + queue + 1)) * 0.75

        if sleep_time > 0.5:
            sleep_time = 0.5

        if sleep_time < 0.0001:
            sleep_time = 0.0001

        self.last_queue_check_date = now
        self.last_queue_check_count = sent

        Global.CONFIG_MANAGER.message_fetcher_sleep_interval = sleep_time

        sleep_interval_log_string = f"new sleep_interval = {sleep_time}"
        Global.LOGGER.debug(sleep_interval_log_string)

        if Global.CONFIG_MANAGER.show_stats:
            Global.LOGGER.info(sleep_interval_log_string)
1366954
public static String getTimestamp(boolean withMsec) {
        return (withMsec ? SafeDateFormatter.getDateFormat(PATTERN_MSEC).format(new Date()) :
            SafeDateFormatter.getDateFormat(PATTERN).format(new Date()));
    }
904197
def getSystemInfo(self, timeout=1):
        
        namespace = System.getServiceType("getSystemInfo")
        uri = self.getControlURL(namespace)

        results = self.execute(uri, namespace, "GetInfo", timeout=timeout)

        return SystemInfo(results)
262175
def uptime(self):
        
        namespace = 'urn:brocade.com:mgmt:brocade-system'
        get_system_uptime = ET.Element('get-system-uptime', xmlns=namespace)
        results = self._callback(get_system_uptime, handler='get')
        system_uptime = dict(days=results.find('.//{%s}days' % namespace).text,
                             hours=results.find('.//{%s}hours' %
                                                namespace).text,
                             minutes=results.find('.//{%s}minutes' %
                                                  namespace).text,
                             seconds=results.find('.//{%s}seconds' %
                                                  namespace).text)
        return system_uptime
12410
def _get_mtime():
    
    return os.path.exists(RPM_PATH) and int(os.path.getmtime(RPM_PATH)) or 0
1094983
def _get_sleep_interval(self, start_time):
        """"""
        elapsed = time.time() - start_time
        if elapsed < 0.05:
            return 0.01
        elif elapsed < 1.0:
            return 0.05
        elif elapsed < 10.0:
            return 0.1
        elif elapsed < 60.0:
            return 0.5
        return 1.0
1072815
@Nonnull
  public static ESuccess sleep (@Nonnegative final long nMilliseconds)
  {
    ValueEnforcer.isGE0 (nMilliseconds, "MilliSeconds");

    try
    {
      Thread.sleep (nMilliseconds);
      return ESuccess.SUCCESS;
    }
    catch (final InterruptedException ex)
    {
      Thread.currentThread ().interrupt ();
      return ESuccess.FAILURE;
    }
  }