Installs an interval loop that dumps stats to a file.
8796
def installStatsLoop(statsFile, statsDelay):
  """"""

  def dumpStats():
    """Actual stats dump function."""
    scales.dumpStatsTo(statsFile)
    reactor.callLater(statsDelay, dumpStats)

  def startStats():
    """Starts the stats dump in "statsDelay" seconds."""
    reactor.callLater(statsDelay, dumpStats)

  reactor.callWhenRunning(startStats)
56267
def run(self):
        """"""
        for rel_path in sorted(self.paths):
            file_path = join(self.data_dir, rel_path)
            self.minify(file_path)

        after = self.size_of(self.after_total)
        before = self.size_of(self.before_total)
        saved = self.size_of(self.before_total - self.after_total)

        template = '\nTotal: ' \
                   '\033[92m{}\033[0m -> \033[92m{}\033[0m. ' \
                   'Compressed: \033[92m{}\033[0m\n'

        print(template.format(before, after, saved))
600722
def persist_compilestats(run, session, stats):
    
    for stat in stats:
        stat.run_id = run.id
        session.add(stat)
819319
def _add(self, lines):
        '''

        '''
        lines = self._setup('ADD', lines)

        for line in lines:
            values = line.split(" ")
            frompath = values.pop(0)

            # Custom parsing for frompath

            # If it's a web address, add to install routine to get
            if frompath.startswith('http'):
                for topath in values:
                    self._parse_http(frompath, topath)

            # Add the file, and decompress in install
            elif re.search("[.](gz|gzip|bz2|xz)$", frompath.strip()):
                for topath in values:
                    self._parse_archive(frompath, topath)

            # Just add the files
            else:
                for topath in values:
                    self._add_files(frompath, topath)
1043592
def send(self, stats):
        ""
        buf = cStringIO.StringIO()
        now = int(time.time())
        num_stats = 0

        # timer stats
        pct = stats.percent
        timers = stats.timers
        for key, vals in timers.iteritems():
            if not vals:
                continue

            # compute statistics
            num = len(vals)
            vals = sorted(vals)
            vmin = vals[0]
            vmax = vals[-1]
            mean = vmin
            max_at_thresh = vmax
            if num > 1:
                idx = round((pct / 100.0) * num)
                tmp = vals[:int(idx)]
                if tmp:
                    max_at_thresh = tmp[-1]
                    mean = sum(tmp) / idx

            key = 'stats.timers.%s' % key
            buf.write('%s.mean %f %d\n' % (key, mean, now))
            buf.write('%s.upper %f %d\n' % (key, vmax, now))
            buf.write('%s.upper_%d %f %d\n' % (key, pct, max_at_thresh, now))
            buf.write('%s.lower %f %d\n' % (key, vmin, now))
            buf.write('%s.count %d %d\n' % (key, num, now))
            num_stats += 1

        # counter stats
        counts = stats.counts
        for key, val in counts.iteritems():
            buf.write('stats.%s %f %d\n' % (key, val / stats.interval, now))
            buf.write('stats_counts.%s %f %d\n' % (key, val, now))
            num_stats += 1

        # counter stats
        gauges = stats.gauges
        for key, val in gauges.iteritems():
            buf.write('stats.%s %f %d\n' % (key, val, now))
            buf.write('stats_counts.%s %f %d\n' % (key, val, now))
            num_stats += 1

        buf.write('statsd.numStats %d %d\n' % (num_stats, now))

        # TODO: add support for N retries

        for host in self._hosts:
            # flush stats to graphite
            try:
                sock = socket.create_connection(host)
                sock.sendall(buf.getvalue())
                sock.close()
            except Exception, ex:
                self.error(E_SENDFAIL % ('graphite', host, ex))
1066709
public void dump_stats(Writer out, boolean labels)
    throws IOException
    {
        if ( labels ) {
            out.write("--------------------------------------------------\n");
            out.write("FileManager Header:\n");
            out.write("--------------------------------------------------\n");
            out.write("Filename = " + filename + "\n");
            out.write("Allocations: " + allocs + "\n");
            out.write("Deallocations: " + deallocs +"\n");
            out.write("Coalesces: " + coalesces + "\n");
            out.write("Allocated blocks: " + allocated_blocks + "\n");
            out.write("Allocated bytes: " + allocated_words +"\n");           
            out.write("Free blocks: " + free_blocks+ "\n");
            out.write("Free bytes: " + free_words+ "\n");
            out.write("Seeks: " + seeks+ "\n");
            out.write("Requests for small blocks: " + small_requests+ "\n");
            out.write("Requests for large blocks: " + large_requests+ "\n");
            out.write("Quick list hits: " + ql_hits+ "\n");
            out.write("Misc list hits: " + ml_hits+ "\n");
            out.write("Block splits (from misc list): " + ml_splits+ "\n");
            out.write("Misc list blocks searched: " + ml_blocks_searched+ "\n");
            out.write("Fast startups: " + fast_startups+ "\n");

            //out.write("Internal blocksize = " + CACHE_PAGESIZE + "\n");
            //out.write("Cache size = " + cachesize+ "\n");
            //out.write("Cache hits: " + cache_hits+ "\n");
            //out.write("Cache misses: " + cache_misses+ "\n");
            //out.write("Page allocations: " + page_allocations+ "\n");
            out.write("Read requests: " + read_count + "\n");
            out.write("Write requests: " + write_count+ "\n");
            out.write("Accumulated physical read time:" + read_time+ "\n");
            out.write("Accumulated physical write time:" + write_time+ "\n");
            out.write("Bytes read: " + bytes_read + "\n");
            out.write("Bytes written: " + bytes_written + "\n");
        } else {
            out.write(filename + "\t");
            out.write(allocs + "\t");
            out.write(deallocs +"\t");
            out.write(coalesces + "\t");
            out.write(allocated_blocks + "\t");
            out.write(allocated_words +"\t");           
            out.write(free_blocks+ "\t");
            out.write(free_words+ "\t");

            out.write(seeks+ "\t");
            out.write(read_count + "\t");
            out.write(write_count+ "\t");
            out.write(read_time+ "\t");
            out.write(write_time+ "\t");

            out.write(bytes_read + "\t");
            out.write(bytes_written + "\t");

            out.write(small_requests+ "\t");
            out.write(large_requests+ "\t");
            out.write(ql_hits+ "\t");
            out.write(ml_hits+ "\t");
            out.write(ml_splits+ "\t");
            out.write(ml_blocks_searched+ "\t");
            out.write(fast_startups+ "\t");

            //out.write(CACHE_PAGESIZE + "\t");
            //out.write(cachesize+ "\t");
            //out.write(cache_hits+ "\t");
            //out.write(cache_misses+ "\t");
            //out.write(page_allocations+ "\t");

        }
    }
1007112
def update_stats(stats, start_time, data):
    '''
    
    '''
    end_time = time.time()
    cmd = data['cmd']
    # the jid is used as the create time
    try:
        jid = data['jid']
    except KeyError:
        try:
            jid = data['data']['__pub_jid']
        except KeyError:
            log.info('jid not found in data, stats not updated')
            return stats
    create_time = int(time.mktime(time.strptime(jid, '%Y%m%d%H%M%S%f')))
    latency = start_time - create_time
    duration = end_time - start_time

    stats[cmd]['runs'] += 1
    stats[cmd]['latency'] = (stats[cmd]['latency'] * (stats[cmd]['runs'] - 1) + latency) / stats[cmd]['runs']
    stats[cmd]['mean'] = (stats[cmd]['mean'] * (stats[cmd]['runs'] - 1) + duration) / stats[cmd]['runs']

    return stats
1053132
function statFile(filePath, callback) {
  fs.stat(filePath, function(err, stats) {

    // Resource does not exist
    if (err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) {
      const error = new Error('Resource does not exist');
      error.httpCode = 404;

      callback(error);

    // Not a file
    } else if (!stats.isFile()) {
      const error = new Error('Resource is not a file');
      error.httpCode = 400;

      callback(error);

    // Server error
    } else if (err) {
      const error = new Error('Server error');
      error.httpCode = 500;

      callback(error);

    // Success. Get the stats.
    } else {
      callback(null, stats);
    }
  });
}
192438
def dump(self, filename):
        """"""
        try:
            with open(filename, 'wb') as fp:
                cPickle.dump(self.counters, fp)
        except Exception as e:
            logging.warning("can't dump counter to file %s: %s", filename, e)
            return False
        return True
1221959
def _batch_insert(self, inserts, intervals, **kwargs):
    '''
    
    '''
    updates = {}
    # TODO support flush interval
    for interval,config in self._intervals.items():
      for timestamp,names in inserts.iteritems():
        timestamps = self._normalize_timestamps(timestamp, intervals, config)
        for name,values in names.iteritems():
          for value in values:
            for tstamp in timestamps:
              query,insert = self._insert_data(
                name, value, tstamp, interval, config, dry_run=True)

              batch_key = self._batch_key(query)
              updates.setdefault(batch_key, {'query':query, 'interval':interval})
              new_insert = self._batch(insert, updates[batch_key].get('insert'))
              updates[batch_key]['insert'] = new_insert

    # now that we've collected a bunch of updates, flush them out
    for spec in updates.values():
      self._client[ spec['interval'] ].update(
        spec['query'], spec['insert'], upsert=True, check_keys=False )
773926
protected static function writeStatisticsToStatusFile()
    {
        // For master process.
        if (self::$_masterPid === getmypid()) {
            $loadavg = function_exists('sys_getloadavg') ? array_map('round', sys_getloadavg(), array(2)) : array('-', '-', '-');
            file_put_contents(self::$_statisticsFile,
                "---------------------------------------GLOBAL STATUS--------------------------------------------\n");
            file_put_contents(self::$_statisticsFile,
                'Swoole version:' . phpversion('swoole') . "          PHP version:" . PHP_VERSION . "\n", FILE_APPEND);
            file_put_contents(self::$_statisticsFile, 'start time:' . date('Y-m-d H:i:s',
                    self::$_globalStatistics['start_timestamp']) . '   run ' . floor((time() - self::$_globalStatistics['start_timestamp']) / (24 * 60 * 60)) . ' days ' . floor(((time() - self::$_globalStatistics['start_timestamp']) % (24 * 60 * 60)) / (60 * 60)) . " hours   \n",
                FILE_APPEND);
            $load_str = 'load average: ' . implode(", ", $loadavg);
            file_put_contents(self::$_statisticsFile,
                str_pad($load_str, 33) . 'event-loop:' . self::getEventLoopName() . "\n", FILE_APPEND);
            file_put_contents(self::$_statisticsFile,
                count(self::$_pidMap) . ' workers       ' . count(self::getAllWorkerPids()) . " processes\n",
                FILE_APPEND);
            file_put_contents(self::$_statisticsFile,
                str_pad('worker_name', self::$_maxWorkerNameLength) . " exit_status     exit_count\n", FILE_APPEND);
            foreach (self::$_pidMap as $worker_id => $worker_pid_array) {
                $worker = self::$_workers[$worker_id];
                if (isset(self::$_globalStatistics['worker_exit_info'][$worker_id])) {
                    foreach (self::$_globalStatistics['worker_exit_info'][$worker_id] as $worker_exit_status => $worker_exit_count) {
                        file_put_contents(self::$_statisticsFile,
                            str_pad($worker->name, self::$_maxWorkerNameLength) . " " . str_pad($worker_exit_status,
                                16) . " $worker_exit_count\n", FILE_APPEND);
                    }
                } else {
                    file_put_contents(self::$_statisticsFile,
                        str_pad($worker->name, self::$_maxWorkerNameLength) . " " . str_pad(0, 16) . " 0\n",
                        FILE_APPEND);
                }
            }
            file_put_contents(self::$_statisticsFile,
                "---------------------------------------PROCESS STATUS-------------------------------------------\n",
                FILE_APPEND);
            file_put_contents(self::$_statisticsFile,
                "pid\tmemory  " . str_pad('listening', self::$_maxSocketNameLength) . " " . str_pad('worker_name',
                    self::$_maxWorkerNameLength) . " connections " . str_pad('total_request',
                    13) . " " . str_pad('send_fail', 9) . " " . str_pad('throw_exception', 15) . "\n", FILE_APPEND);

            chmod(self::$_statisticsFile, 0722);

            foreach (self::getAllWorkerPids() as $worker_pid) {
                swoole_process::kill($worker_pid, SIGUSR2);
            }
            return;
        }

        // For child processes.
        /** @var Worker $worker */
        $worker           = current(self::$_workers);
        $worker_status_str = getmypid() . "\t" . str_pad(round(memory_get_usage(true) / (1024 * 1024), 2) . "M",
                7) . " " . str_pad($worker->getSocketName(),
                self::$_maxSocketNameLength) . " " . str_pad(($worker->name === $worker->getSocketName() ? 'none' : $worker->name),
                self::$_maxWorkerNameLength) . " ";
        $worker_status_str .= str_pad(ConnectionInterface::$statistics['connection_count'],
                11) . " " . str_pad(ConnectionInterface::$statistics['total_request'],
                14) . " " . str_pad(ConnectionInterface::$statistics['send_fail'],
                9) . " " . str_pad(ConnectionInterface::$statistics['throw_exception'], 15) . "\n";
        file_put_contents(self::$_statisticsFile, $worker_status_str, FILE_APPEND);
    }
724591
def run_analysis(self, argv):
        """"""
        args = self._parser.parse_args(argv)


        sedfile = args.sed_file

        if is_not_null(args.config):
            configfile = os.path.join(os.path.dirname(sedfile), args.config)
        else:
            configfile = os.path.join(os.path.dirname(sedfile), 'config.yaml')

        nbins = _get_enum_bins(configfile)

        first = args.seed
        last = first + args.nsims
        flist = [sedfile.replace("_SEED.fits", "_%06i.fits" % seed)
                 for seed in range(first, last)]
        outfile = args.outfile
        summaryfile = args.summaryfile


        outtable = fill_output_table(
            flist, "SED", CollectSED.collist, nbins=nbins)

        if is_not_null(outfile):
            outtable.write(outfile)

        if is_not_null(summaryfile):
            summary = summarize_sed_results(outtable)
            summary.write(summaryfile)
1161043
function statFiles(files, source, fn) {
  var batch = new Batch();

  files.forEach(function(file) {
    batch.push(statFile(file, source));
  });

  batch.end(fn);
}
27374
def dump_as_two_item_tsv(record, output_file):
    
    for ordered_stats in record.ordered_statistics:
        if len(ordered_stats.items_base) != 1:
            continue
        if len(ordered_stats.items_add) != 1:
            continue
        output_file.write('{0}\t{1}\t{2:.8f}\t{3:.8f}\t{4:.8f}{5}'.format(
            list(ordered_stats.items_base)[0], list(ordered_stats.items_add)[0],
            record.support, ordered_stats.confidence, ordered_stats.lift,
            os.linesep))
1030683
def stats(args):
    
    p = OptionParser(stats.__doc__)
    p.set_outfile()
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    folder, = args
    statsfiles = iglob(folder, "*.stats")
    after_equal = lambda x: x.split("=")[-1]
    header = "Library Assembled_reads Contigs".split()
    contents = []
    # label=M0096 total=7443 cnts=948 mean=7.851 std=35.96
    for statsfile in statsfiles:
        fp = open(statsfile)
        for row in fp:
            if row.startswith("label="):
                break
        label, total, cnts = row.split()[:3]
        label = after_equal(label)
        reads = int(after_equal(total))
        contigs = int(after_equal(cnts))
        contents.append((label, reads, contigs))

    all_labels, all_reads, all_contigs = zip(*contents)
    contents.append(("SUM", sum(all_reads), sum(all_contigs)))
    contents.append(("AVERAGE (per sample)", \
                    int(np.mean(all_reads)), int(np.mean(all_contigs))))
    contents.append(("MEDIAN (per sample)", \
                    int(np.median(all_reads)), int(np.median(all_contigs))))
    write_csv(header, contents, filename=opts.outfile)
1199502
def _run_happy_eval(vrn_file, rm_file, rm_interval_file, base_dir, data):
    
    out_dir = utils.safe_makedir(os.path.join(base_dir, "happy"))
    out_prefix = os.path.join(out_dir, "val")
    if not utils.file_exists(out_prefix + ".summary.csv"):
        vrn_file, rm_file, interval_bed = _prepare_inputs(vrn_file, rm_file, rm_interval_file, base_dir, data)
        cmd = ["hap.py", "-V", "-f", interval_bed, "-r", dd.get_ref_file(data),
               "-l", ",".join(_get_location_list(interval_bed)),
               "-o", out_prefix, rm_file, vrn_file]
        do.run(cmd, "Validate calls using hap.py", data)
    return {"vcf": out_prefix + ".vcf.gz"}
946814
def psdump(self, filename=None, **kargs):
        """"""
        canvas = self.canvas_dump(**kargs)
        if filename is None:
            fname = get_temp_file(autoext=".eps")
            canvas.writeEPSfile(fname)
            subprocess.Popen([conf.prog.psreader, fname+".eps"])
        else:
            canvas.writeEPSfile(filename)