Python progressbar.Timer() Examples

The following are 22 code examples of progressbar.Timer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module progressbar , or try the search function .
Example #1
Source File: laika.py    From laikaboss with Apache License 2.0 6 votes vote down vote up
def run(self):
        try:
            from progressbar import ProgressBar, Bar, Counter, Timer, ETA, Percentage, RotatingMarker
            widgets = [Percentage(), Bar(left='[', right=']'), ' Processed: ', Counter(), '/', "%s" % self.task_count, ' total files (', Timer(), ') ', ETA()]
            pb = ProgressBar(widgets=widgets, maxval=self.task_count).start()
            while self.task_queue.qsize():
                pb.update(self.task_count - self.task_queue.qsize())
                
                time.sleep(0.5)
            pb.finish()
        except KeyboardInterrupt:
            warning("progressbar interrupted by user\n")
            return 1
        except ImportError:
            warning("progressbar module not available")
        except:
            warning("unknown error from progress bar")

        return 0 
Example #2
Source File: data_handler.py    From cortex with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def reset(self, mode, make_pbar=True, string=''):
        self.mode = mode
        self.u = 0

        if make_pbar:
            widgets = [string, Timer(), ' | ',
                       Percentage(), ' | ', ETA(), Bar()]
            if len([len(loader[self.mode]) for loader
                    in self.loaders.values()]) == 0:
                maxval = 1000
            else:
                maxval = min(len(loader[self.mode])
                             for loader in self.loaders.values())
            self.pbar = ProgressBar(widgets=widgets, maxval=maxval).start()
        else:
            self.pbar = None

        sources = self.loaders.keys()
        self.iterators = dict((source, self.make_iterator(source))
                              for source in sources) 
Example #3
Source File: utils.py    From HoneyBot with MIT License 6 votes vote down vote up
def capture_on_interface(interface, name, timeout=60):
    """
    :param interface: The name of the interface on which to capture traffic
    :param name: The name of the capture file
    :param timeout: A limit in seconds specifying how long to capture traffic
    """

    if timeout < 15:
        logger.error("Timeout must be over 15 seconds.")
        return
    if not sys.warnoptions:
        warnings.simplefilter("ignore")
    start = time.time()
    widgets = [
        progressbar.Bar(marker=progressbar.RotatingMarker()),
        ' ',
        progressbar.FormatLabel('Packets Captured: %(value)d'),
        ' ',
        progressbar.Timer(),
    ]
    progress = progressbar.ProgressBar(widgets=widgets)
    capture = pyshark.LiveCapture(interface=interface, output_file=os.path.join('tmp', name))
    pcap_size = 0
    for i, packet in enumerate(capture.sniff_continuously()):
        progress.update(i)
        if os.path.getsize(os.path.join('tmp', name)) != pcap_size:
            pcap_size = os.path.getsize(os.path.join('tmp', name))
        if not isinstance(packet, pyshark.packet.packet.Packet):
            continue
        if time.time() - start > timeout:
            break
        if pcap_size > const.PT_MAX_BYTES:
            break
    capture.clear()
    capture.close()
    return pcap_size 
Example #4
Source File: bar_logger.py    From karonte with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def set_tot_elaborations(self, tot_elaborations):
        """
        Set the total number of elaborations

        :param tot_elaborations: total number of elaborations
        :return: None
        """

        widgets = [
            progressbar.Percentage(),
            ' (', progressbar.SimpleProgress(), ') ',

            progressbar.Bar(),
            progressbar.Timer(),
            ' ETC: ', self._ETC, ' '
        ]
        self._bar = progressbar.ProgressBar(redirect_stderr=True, max_value=tot_elaborations, widgets=widgets)
        self._bar.start()
        self._tot_elaborations = tot_elaborations 
Example #5
Source File: __init__.py    From attention-lvcsr with MIT License 6 votes vote down vote up
def create_bar(self):
        """Create a new progress bar.

        Calls `self.get_iter_per_epoch()`, selects an appropriate
        set of widgets and creates a ProgressBar.

        """
        iter_per_epoch = self.get_iter_per_epoch()
        epochs_done = self.main_loop.log.status['epochs_done']

        if iter_per_epoch is None:
            widgets = ["Epoch {}, step ".format(epochs_done),
                       progressbar.Counter(), ' ',
                       progressbar.BouncingBar(), ' ',
                       progressbar.Timer()]
            iter_per_epoch = progressbar.UnknownLength
        else:
            widgets = ["Epoch {}, step ".format(epochs_done),
                       progressbar.Counter(),
                       ' (', progressbar.Percentage(), ') ',
                       progressbar.Bar(), ' ',
                       progressbar.Timer(), ' ', progressbar.ETA()]

        return progressbar.ProgressBar(widgets=widgets,
                                       max_value=iter_per_epoch) 
Example #6
Source File: zbx_deleteMonitors.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def deleteHostsByHostgroup(groupname):
    hostgroup = zapi.hostgroup.get(output=['groupid'],filter={'name': groupname})
    if hostgroup.__len__() != 1:
        logger.error('Hostgroup not found: %s\n\tFound this: %s' % (groupname,hostgroup))
    groupid = int(hostgroup[0]['groupid'])
    hosts = zapi.host.get(output=['name','hostid'],groupids=groupid)
    total = len(hosts)
    logger.info('Hosts found: %d' % (total))
    if ( args.run ):
        x = 0
        bar = ProgressBar(maxval=total,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
        logger.echo = False
        for host in hosts:
            x = x + 1
            bar.update(x)
            logger.debug('(%d/%d) >> Removing >> %s' % (x, total, host))
            out = zapi.globo.deleteMonitors(host['name'])
        bar.finish()
        logger.echo = True
    else:
        logger.info('No host removed due to --no-run arg. Full list of hosts:')
        for host in hosts:
            logger.info('%s' % host['name'])
    return 
Example #7
Source File: zbx_clone.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def hosts_disable_all():
  """
  status de host 0 = enabled
  status de host 1 = disabled
  """
  logger.info('Disabling all hosts, in blocks of 1000')
  hosts = zapi.host.get(output=[ 'hostid' ], search={ 'status': 0 })
  maxval = int(ceil(hosts.__len__())/1000+1)
  bar = ProgressBar(maxval=maxval,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
  i = 0
  for i in xrange(maxval):
    block = hosts[:1000]
    del hosts[:1000]
    result = zapi.host.massupdate(hosts=[ x for x in block ], status=1)
    i += 1
    bar.update(i)
  bar.finish()
  logger.info('Done')
  return 
Example #8
Source File: zbx_clone.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def proxy_passive_to_active():
  """
  status de prxy 5 = active
  status de prxy 6 = passive
  """
  logger.info('Change all proxys to active')
  proxys = zapi.proxy.get(output=[ 'shorten', 'host' ],
    filter={ 'status': 6 })
  if ( proxys.__len__() == 0 ):
    logger.info('Done')
    return
  bar = ProgressBar(maxval=proxys.__len__(),widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
  i = 0
  for x in proxys:
    i += 1
    proxyid = x['proxyid']
    result = zapi.proxy.update(proxyid=proxyid, status=5)
    logger.echo = False
    logger.debug('Changed from passive to active proxy: %s' % (x['host']))
    bar.update(i)
  bar.finish()
  logger.echo = True
  logger.info('Done')
  return 
Example #9
Source File: dataset.py    From zhusuan with MIT License 6 votes vote down vote up
def show_progress(block_num, block_size, total_size):
    global pbar

    if pbar is None:
        if total_size > 0:
            prefixes = ('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi')
            power = min(int(math.log(total_size, 2) / 10), len(prefixes) - 1)
            scaled = float(total_size) / (2 ** (10 * power))
            total_size_str = '{:.1f} {}B'.format(scaled, prefixes[power])
            try:
                marker = '█'
            except UnicodeEncodeError:
                marker = '*'
            widgets = [
                progressbar.Percentage(),
                ' ', progressbar.DataSize(),
                ' / ', total_size_str,
                ' ', progressbar.Bar(marker=marker),
                ' ', progressbar.ETA(),
                ' ', progressbar.AdaptiveTransferSpeed(),
            ]
            pbar = progressbar.ProgressBar(widgets=widgets,
                                           max_value=total_size)
        else:
            widgets = [
                progressbar.DataSize(),
                ' ', progressbar.Bar(marker=progressbar.RotatingMarker()),
                ' ', progressbar.Timer(),
                ' ', progressbar.AdaptiveTransferSpeed(),
            ]
            pbar = progressbar.ProgressBar(widgets=widgets,
                                           max_value=progressbar.UnknownLength)

    downloaded = block_num * block_size
    if downloaded < total_size:
        pbar.update(downloaded)
    else:
        pbar.finish()
        pbar = None 
Example #10
Source File: zbx_clone.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def discovery_disable_all(status=0):
  """
  Alterar status de todos os discoveries *auto*
  Status 0 = enable
  Status 1 = disable
  """ 
  logger.info('Disabling all network discoveries')
  druleids = zapi.drule.get(output=[ 'druleid', 'iprange', 'name', 'proxy_hostid', 'status' ],
      selectDChecks='extend', filter={ 'status': 0 })
  if ( druleids.__len__() == 0 ):
    logger.info('Done')
    return
  bar = ProgressBar(maxval=druleids.__len__(),widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
  i = 0
  for x in druleids:
    params_disable = {
      'druleid': x['druleid'],
      'iprange': x['iprange'],
      'name': x['name'],
      'dchecks': x['dchecks'],
      'status': 1
    }
    out = zapi.drule.update(**params_disable)
    logger.echo = False
    if out:
      logger.debug('\tNew status: %s (%s) --> %d' % (x['name'],out['druleids'],status))
    else:
      logger.warning('\tFAILED to change status: %s (%s) --> %d' % (x['name'],out['druleids'],status))
    i += 1
    bar.update(i)
  logger.echo = True
  bar.finish()
  logger.info('Done')
  return 
Example #11
Source File: iters.py    From neupy with MIT License 5 votes vote down vote up
def make_progressbar(max_value, show_output):
    widgets = [
        progressbar.Timer(format='Time: %(elapsed)s'),
        ' |',
        progressbar.Percentage(),
        progressbar.Bar(),
        ' ',
        progressbar.ETA(),
    ]

    if show_output:
        widgets.extend([' | ', progressbar.DynamicMessage('loss')])

    return progressbar.ProgressBar(max_value=max_value, widgets=widgets) 
Example #12
Source File: ZabbixTuner.py    From ZabbixTuner with GNU General Public License v3.0 5 votes vote down vote up
def desabilitaItensNaoSuportados():
    query = {
            "output": "extend",
            "filter": {
                "state": 1
            },
            "monitored": True
        }

    filtro = input('Qual a busca para key_? [NULL = ENTER]')
    if filtro.__len__() > 0:
        query['search'] = {'key_': filtro}

    limite = input('Qual o limite de itens? [NULL = ENTER]')
    if limite.__len__() > 0:
        try:
            query['limit'] = int(limite)
        except:
            print('Limite invalido')
            input("Pressione ENTER para voltar")
            main()

    opcao = input("Confirma operação? [s/n]")
    if opcao == 's' or opcao == 'S':
        itens = zapi.item.get(query)
        print('Encontramos {} itens'.format(itens.__len__()))
        bar = ProgressBar(maxval=itens.__len__(), widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
        i = 0
        for x in itens:
            zapi.item.update({"itemid": x['itemid'], "status": 1})
            i += 1
            bar.update(i)
        bar.finish()
        print("Itens desabilitados!!!")
        print()
        input("Pressione ENTER para continuar")
    main() 
Example #13
Source File: reader.py    From jack with MIT License 5 votes vote down vote up
def process_dataset(self, dataset: Sequence[Tuple[QASetting, Answer]], batch_size: int, silent=True):
        """
        Similar to the call method, only that it works on a labeled dataset and applies batching. However, assumes
        that batches in input_module.batch_generator are processed in order and do not get shuffled during with
        flag is_eval set to true.

        Args:
            dataset:
            batch_size: note this information is needed here, but does not set the batch_size the model is using.
            This has to happen during setup/configuration.
            silent: if true, no output

        Returns:
            predicted outputs/answers to a given (labeled) dataset
        """
        batches = self.input_module.batch_generator(dataset, batch_size, is_eval=True)
        answers = list()
        enumerator = enumerate(batches)
        if not silent:
            logger.info("Start answering...")
            bar = progressbar.ProgressBar(
                max_value=math.ceil(len(dataset) / batch_size),
                widgets=[' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') '])
            enumerator = bar(enumerator)
        for j, batch in enumerator:
            output_module_input = self.model_module(batch, self.output_module.input_ports)
            questions = [q for q, a in dataset[j * batch_size:(j + 1) * batch_size]]
            answers.extend(a[0] for a in self.output_module(
                questions, {p: output_module_input[p] for p in self.output_module.input_ports}))

        return answers 
Example #14
Source File: hooks.py    From jack with MIT License 5 votes vote down vote up
def __call__(self, epoch):
        if self._batches is None:
            logger.info("Preparing evaluation data...")
            self._batches = self.reader.input_module.batch_generator(self._dataset, self._batch_size, is_eval=True)

        logger.info("Started evaluation %s" % self._info)
        metrics = defaultdict(lambda: list())
        bar = progressbar.ProgressBar(
            max_value=len(self._dataset) // self._batch_size + 1,
            widgets=[' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') '])
        for i, batch in bar(enumerate(self._batches)):
            inputs = self._dataset[i * self._batch_size:(i + 1) * self._batch_size]
            predictions = self.reader.model_module(batch, self._ports)
            m = self.apply_metrics(inputs, predictions)
            for k in self._metrics:
                metrics[k].append(m[k])

        metrics = self.combine_metrics(metrics)
        super().add_to_history(metrics, self._iter, epoch)

        printmetrics = sorted(metrics.keys())
        res = "Epoch %d\tIter %d\ttotal %d" % (epoch, self._iter, self._total)
        for m in printmetrics:
            res += '\t%s: %.3f' % (m, metrics[m])
            self.update_summary(self._iter, self._info + '_' + m, metrics[m])
            if self._write_metrics_to is not None:
                with open(self._write_metrics_to, 'a') as f:
                    f.write("{0} {1} {2:.5}\n".format(datetime.now(), self._info + '_' + m,
                                                      np.round(metrics[m], 5)))
        res += '\t' + self._info
        logger.info(res)

        if self._side_effect is not None:
            self._side_effect_state = self._side_effect(metrics, self._side_effect_state) 
Example #15
Source File: link_prediction.py    From jack with MIT License 5 votes vote down vote up
def compute_ranks(scoring_function, triples, entity_set, true_triples=None):
    subject_ranks, object_ranks = [], []
    subject_ranks_filtered, object_ranks_filtered = [], []

    bar = progressbar.ProgressBar(
        max_value=len(triples),
        widgets=[' [', progressbar.Timer(), '] ', progressbar.Bar(), ' (', progressbar.ETA(), ') '])
    for s, p, o in bar(triples):
        subject_triples = [(s, p, o)] + [(x, p, o) for x in entity_set if x != s]
        object_triples = [(s, p, o)] + [(s, p, x) for x in entity_set if x != o]

        subject_triple_scores = np.array(scoring_function(subject_triples))
        object_triple_scores = np.array(scoring_function(object_triples))

        subject_rank = 1 + np.argsort(np.argsort(- subject_triple_scores))[0]
        object_rank = 1 + np.argsort(np.argsort(- object_triple_scores))[0]

        subject_ranks.append(subject_rank)
        object_ranks.append(object_rank)

        if true_triples is None:
            true_triples = []

        for idx, triple in enumerate(subject_triples):
            if triple != (s, p, o) and triple in true_triples:
                subject_triple_scores[idx] = - np.inf

        for idx, triple in enumerate(object_triples):
            if triple != (s, p, o) and triple in true_triples:
                object_triple_scores[idx] = - np.inf

        subject_rank_filtered = 1 + np.argsort(np.argsort(- subject_triple_scores))[0]
        object_rank_filtered = 1 + np.argsort(np.argsort(- object_triple_scores))[0]

        subject_ranks_filtered.append(subject_rank_filtered)
        object_ranks_filtered.append(object_rank_filtered)

    return (subject_ranks, object_ranks), (subject_ranks_filtered, object_ranks_filtered) 
Example #16
Source File: move_items.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def createSQL(table,values,name='insert'):
	'''
	Generate the SQL insert line, breaking each insert to up to ~1k values
	and up to ~1k insert's (~1M values total for each SQL file)
	'''
	logger.info('Generating SQL file')
	queryInsert='INSERT INTO %s (itemid,clock,num,value_min,value_avg,value_max) VALUES' % table
	i=0 # Controls the progress bar
	x=0 # Controls number of inserts in one line
	y=0 # Controls number of lines in one file
	z=0 # Controls number of file name
	valuesLen=values.__len__()
	sqlFile='%s.sql.%d' % (name,z)
	logger.debug('Total itens for %s: %d' % (name,valuesLen))

	if valuesLen > 0:
		bar=ProgressBar(maxval=valuesLen,widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
		for value in values:
			i+=1
			x+=1
			if x != 1: # First line only
				sqlInsert='%s,%s' % (sqlInsert,value)
			else:
				sqlInsert=value
			if y >= 1000: # If there is more than 1k lines, write to new file
				z+=1
				y=0
			if x >= 1000 or i == valuesLen: # If there is more than 1k values or we finished our list, write to file
				sqlFile='%s.sql.%d' % (name,z)
				fileAppend(f=sqlFile,content='%s %s;\n' % (queryInsert,sqlInsert))
				x=0
				y+=1
				sqlInsert=''
			if args.loglevel.upper() != 'DEBUG': # Dont print progressbar if in debug mode
				bar.update(i)
		bar.finish()
	else:
		logger.warning('No values received') 
Example #17
Source File: core.py    From i3-xfce with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, steps_nb, step_name_len):
    """
    Constructor
    """
    threading.Thread.__init__(self)
    self._running = False
    self._current_step = 0
    self._steps_nb = steps_nb
    self._step_name_len = step_name_len + len(str(steps_nb)) * 2 + 2
    self._widgets = [" ".ljust(self._step_name_len),
                     ' [', progressbar.Timer(), '] ',
                     progressbar.Bar(),
                     ' (', progressbar.ETA(), ') ',
                    ]
    self._pbar = progressbar.ProgressBar(max_value=steps_nb, widgets=self._widgets) 
Example #18
Source File: diskover.py    From diskover with Apache License 2.0 5 votes vote down vote up
def progress_bar(event):
    if event == 'Checking' or event == 'Calculating':
        widgets = [progressbar.AnimatedMarker(), ' ', event + ' (Queue: ', progressbar.Counter(), ') ', progressbar.Timer()]
        bar = progressbar.ProgressBar(widgets=widgets, max_value=progressbar.UnknownLength)
    else:
        widgets = [event + ' ', progressbar.Bar(), progressbar.Percentage(),
            ' (', progressbar.Timer(), ', ', progressbar.ETA(), ')']
        bar = progressbar.ProgressBar(widgets=widgets, max_value=100)
    return bar 
Example #19
Source File: move_items.py    From zabbix-scripts with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def main():
	'''
	Controls general flow of operations
	'''
	# If it exists, use the cached data of hosts and items
	if (os.path.isfile(move_items_file)):
		with open(move_items_file) as infile:
			hosts=json.load(infile)
			logger.info('Cache loaded from file (%s)' % move_items_file)
	else:
		hosts=getItems()
		with open(move_items_file, 'w') as outfile:
			json.dump(hosts, outfile)
			logger.info('Cache written to file (%s)' % move_items_file)

	for host in hosts:
		logger.info('Geting trends data of host: %s' % host['name'])
		host['trends']=list()
		host['trends_uint']=list()
		if host['itens'].__len__() > 0:
			bar=ProgressBar(maxval=host['itens'].__len__(),widgets=[Percentage(), ReverseBar(), ETA(), RotatingMarker(), Timer()]).start()
			i=0
			for item in host['itens']:
				temp=getTrends(hostname=host['name'],item=item)
				i+=1
				if args.loglevel.upper() != 'DEBUG':
					bar.update(i)
				if temp['table'] == 'trends':
					for value in temp['values']:
						host['trends'].append('(%d, %d, %d, %d, %d, %d)' % (int(item['itemid']), int(value[1]), int(value[2]), int(value[3]), int(value[4]), int(value[5])))
				elif temp['table'] == 'trends_uint':
					for value in temp['values']:
						host['trends_uint'].append('(%d, %d, %d, %d, %d, %d)' % (int(item['itemid']), int(value[1]), int(value[2]), int(value[3]), int(value[4]), int(value[5])))
				else:
					logger.warning('Unknown value type: %s' % temp['table'])
			bar.finish()
		'''
		Now, we send in blocks of up to ~1M values to generate the SQL files
		'''
		if host['trends'].__len__() > 0:
			createSQL(table='trends',values=host['trends'],name=host['name'])
		elif host['trends_uint'].__len__() > 0:
			createSQL(table='trends_uint',values=host['trends_uint'],name=host['name'])
		else:
			logger.warning('No data from %s found to be sent.' % host['name'])



# Start DB connection 
Example #20
Source File: protocols.py    From iWant with MIT License 4 votes vote down vote up
def __init__(self, **kwargs):
        self.peers_list = kwargs['peers_list']
        self.file_handler = kwargs['file_handler']
        self.file_size = kwargs['file_size']
        self.file_checksum = kwargs['file_checksum']
        self.file_root_hash = kwargs['file_root_hash']
        self.resume_from = kwargs['resume_from']
        self.dbpool = kwargs['dbpool']

        self.piece_size = piece_size(self.file_size)
        self.total_pieces = int(
            math.ceil(
                self.file_size *
                1000.0 *
                1000.0 /
                self.piece_size))
        self.start_piece = self.resume_from
        self.last_piece = self.total_pieces
        self.last_piece_size = self.file_size * 1000.0 * \
            1000.0 - ((self.total_pieces - 1) * self.piece_size)
        self.blocks_per_piece = int(self.piece_size / CHUNK_SIZE)
        self.blocks_per_last_piece = int(
            math.ceil(
                self.last_piece_size /
                CHUNK_SIZE))
        self.download_status = 0
        if self.start_piece != 0 and self.start_piece != (self.last_piece - 1):
            self.download_status = (self.start_piece) * self.piece_size
        elif self.start_piece == self.last_piece - 1 and self.start_piece != 0:
            self.download_status = (
                self.start_piece - 1) * self.last_piece_size
        self.bar = progressbar.ProgressBar(
            maxval=int(self.file_size * 1000.0 * 1000.0),
            widgets=[
                progressbar.Bar(
                    '=',
                    '[',
                    ']'),
                ' ',
                progressbar.Percentage(),
                ' ',
                progressbar.Timer()]).start() 
Example #21
Source File: girlscout.py    From angr with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def _full_code_scan(self):
        """
        Perform a full code scan on the target binary.
        """

        # We gotta time this function
        start_time = datetime.now()

        traced_address = set()
        self.functions = set()
        self.call_map = networkx.DiGraph()
        self.cfg = networkx.DiGraph()
        initial_state = self.project.factory.blank_state(mode="fastpath")
        initial_options = initial_state.options - {o.TRACK_CONSTRAINTS} - o.refs
        initial_options |= {o.SUPER_FASTPATH}
        # initial_options.remove(o.COW_STATES)
        initial_state.options = initial_options
        # Sadly, not all calls to functions are explicitly made by call
        # instruction - they could be a jmp or b, or something else. So we
        # should record all exits from a single function, and then add
        # necessary calling edges in our call map during the post-processing
        # phase.
        function_exits = defaultdict(set)

        widgets = [progressbar.Percentage(),
                   ' ',
                   progressbar.Bar(marker=progressbar.RotatingMarker()),
                   ' ',
                   progressbar.Timer(),
                   ' ',
                   progressbar.ETA()
        ]

        pb = progressbar.ProgressBar(widgets=widgets, maxval=10000 * 100).start()

        while True:
            next_addr = self._get_next_code_addr(initial_state)
            percentage = self._seg_list.occupied_size * 100.0 / (self._valid_memory_region_size)
            if percentage > 100.0: percentage = 100.0
            pb.update(percentage * 10000)

            if next_addr is not None:
                l.info("Analyzing %xh, progress %0.04f%%", next_addr, percentage)
            else:
                l.info('No more addr to analyze. Progress %0.04f%%', percentage)
                break

            self.call_map.add_node(next_addr)

            self._scan_code(traced_address, function_exits, initial_state, next_addr)

        pb.finish()
        end_time = datetime.now()
        l.info("A full code scan takes %d seconds.", (end_time - start_time).seconds) 
Example #22
Source File: training.py    From reweighted-ws with GNU Affero General Public License v3.0 4 votes vote down vote up
def perform_epoch(self):
        n_datapoints = self.dataset.n_datapoints
        batch_size = self.batch_size
        n_batches = n_datapoints // batch_size
        epoch = self.step // n_batches
        LL_epoch = 0

        self.update_shvars()
        self.shuffle_train_data()

        # Update learning rated
        self.shvar['lr_p'].set_value((self.calc_learning_rates(self.learning_rate_p / self.lr_decay**epoch)).astype(floatX))
        self.shvar['lr_q'].set_value((self.calc_learning_rates(self.learning_rate_q / self.lr_decay**epoch)).astype(floatX))
        self.shvar['lr_s'].set_value((self.calc_learning_rates(self.learning_rate_s / self.lr_decay**epoch)).astype(floatX))

        widgets = ["Epoch %d, step "%(epoch+1), pbar.Counter(), ' (', pbar.Percentage(), ') ', pbar.Bar(), ' ', pbar.Timer(), ' ', pbar.ETA()]
        bar = pbar.ProgressBar(widgets=widgets, maxval=n_batches).start()

        t0 = time()
        while True:
            LL = self.perform_step(update=False)
            LL_epoch += LL

            batch_idx = self.step % n_batches
            bar.update(batch_idx)

            if self.step % n_batches == 0:
                break
        t = time()-t0
        bar.finish()

        LL_epoch /= n_batches

        self.logger.info("Completed epoch %d in %.1fs (%.1fms/step). Calling epoch_monitors..." % (epoch+1, t, t/n_batches*1000))
        for m in self.epoch_monitors:
            m.on_iter(self.model)

        self.dlog.append_all({
            'timing.epoch':  t,
            'timing.step': t/n_batches
        })
        return LL_epoch