update stats for query planner
965359
function updateSqliteStats(){
	if (count_writes % 100 !== 0)
		return;
	db.query("SELECT MAX(rowid) AS count_units FROM units", function(rows){
		var count_units = rows[0].count_units;
		if (count_units > 500000) // the db is too big, anaylze will lock db for long time,skip it from now on.
			return;
		readCountOfAnalyzedUnits(function(count_analyzed_units){
			console.log('count analyzed units: '+count_analyzed_units);
			if (count_units < 2*count_analyzed_units)
				return;
			count_units_in_prev_analyze = count_units;
			console.log("will update sqlite stats");
			db.query("ANALYZE", function(){
				db.query("ANALYZE sqlite_master", function(){
					console.log("sqlite stats updated");
				});
			});
		});
	});
}
1345043
def _update_stat(self, submission_type, increase_success, increase_fail):
    """"""
    stat = self.stats.get(submission_type, (0, 0))
    stat = (stat[0] + increase_success, stat[1] + increase_fail)
    self.stats[submission_type] = stat
854235
def update_result(self):
        """"""
        try:
            if self.paused:
                result = self._paused_result
            else:
                result = self._final_result
        except AttributeError:
            self.table.update_frame()
            return
        stats, cpu_time, wall_time, title, at = result
        self.table.set_result(stats, cpu_time, wall_time, title, at)
1277771
private void updateStats() {
    final ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    if (bean.isThreadCpuTimeEnabled()) {
      // Update stats for all current threads
      final long[] ids = bean.getAllThreadIds();
      Arrays.sort(ids);
      long totalCpuTime = 0L;
      for (long id : ids) {
        long cpuTime = bean.getThreadCpuTime(id);
        if (cpuTime != -1) {
          totalCpuTime += cpuTime;
          CpuUsage usage = threadCpuUsages.get(id);
          if (usage == null) {
            final ThreadInfo info = bean.getThreadInfo(id);
            usage = new CpuUsage(id, info.getThreadName());
            threadCpuUsages.put(id, usage);
          }
          usage.update(cpuTime);
        }
      }

      // Update jvm cpu usage, if possible we query the operating system mxbean so we get
      // an accurate total including any threads that may have been started and stopped
      // between sampling. As a fallback we use the sum of the cpu time for all threads found
      // in this interval.
      //
      // Total cpu time can be found in:
      // http://docs.oracle.com/javase/7/docs/jre/api/management/extension/\
      // com/sun/management/OperatingSystemMXBean.html
      //
      // We use reflection to avoid direct dependency on com.sun.* classes.
      final OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
      try {
        final Method m = osBean.getClass().getMethod("getProcessCpuTime");
        final long jvmCpuTime = (Long) m.invoke(osBean);
        jvmCpuUsage.update((jvmCpuTime < 0) ? totalCpuTime : jvmCpuTime);
      } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        jvmCpuUsage.update(totalCpuTime);
      }

      // Handle ids in the map that no longer exist:
      // * Remove old entries if the last update time is over AGE_LIMIT
      // * Otherwise, update usage so rolling window is correct
      final long now = System.currentTimeMillis();
      final Iterator<Map.Entry<Long, CpuUsage>> iter = threadCpuUsages.entrySet().iterator();
      while (iter.hasNext()) {
        final Map.Entry<Long, CpuUsage> entry = iter.next();
        final long id = entry.getKey();
        final CpuUsage usage = entry.getValue();
        if (now - usage.getLastUpdateTime() > AGE_LIMIT) {
          iter.remove();
        } else if (Arrays.binarySearch(ids, id) < 0) {
          usage.updateNoValue();
        }
      }
    } else {
      LOGGER.debug("ThreadMXBean.isThreadCpuTimeEnabled() == false, cannot collect stats");
    }
  }
61854
function updateStatus() {
    if (options.log === false || !process.stderr.cursorTo) return;

    var s = Math.floor((Date.now() - start) / 1000);
    var h = Math.floor(s / 3600);
    var m = Math.floor((s - h * 3600) / 60);
    var time = (h ? h + 'h ' : '') + (h || m ? m + 'm ' : '') + (s % 60) + 's';

    process.stderr.cursorTo(0);
    process.stderr.write(tilesDone + ' tiles processed in ' + time);
    process.stderr.clearLine(1);
  }
1174927
def queries(self, last_updated_ms):
        """"""
        stats_logger.incr('queries')
        if not g.user.get_id():
            return json_error_response(
                'Please login to access the queries.', status=403)

        # Unix time, milliseconds.
        last_updated_ms_int = int(float(last_updated_ms)) if last_updated_ms else 0

        # UTC date time, same that is stored in the DB.
        last_updated_dt = utils.EPOCH + timedelta(seconds=last_updated_ms_int / 1000)

        sql_queries = (
            db.session.query(Query)
            .filter(
                Query.user_id == g.user.get_id(),
                Query.changed_on >= last_updated_dt,
            )
            .all()
        )
        dict_queries = {q.client_id: q.to_dict() for q in sql_queries}

        now = int(round(time.time() * 1000))

        unfinished_states = [
            QueryStatus.PENDING,
            QueryStatus.RUNNING,
        ]

        queries_to_timeout = [
            client_id for client_id, query_dict in dict_queries.items()
            if (
                query_dict['state'] in unfinished_states and (
                    now - query_dict['startDttm'] >
                    config.get('SQLLAB_ASYNC_TIME_LIMIT_SEC') * 1000
                )
            )
        ]

        if queries_to_timeout:
            update(Query).where(
                and_(
                    Query.user_id == g.user.get_id(),
                    Query.client_id in queries_to_timeout,
                ),
            ).values(state=QueryStatus.TIMED_OUT)

            for client_id in queries_to_timeout:
                dict_queries[client_id]['status'] = QueryStatus.TIMED_OUT

        return json_success(
            json.dumps(dict_queries, default=utils.json_int_dttm_ser))
538125
def update_status(modeladmin, request, queryset, status):
    """"""
    # We loop over the objects here rather than use queryset.update() for
    # two reasons:
    #
    #  1. No one should ever be updating zillions of Topics or Questions, so
    #     performance is not an issue.
    #  2. To be tidy, we want to log what the user has done.
    #
    for obj in queryset:
        obj.status = status
        obj.save()
        # Now log what happened.
        # Use ugettext_noop() 'cause this is going straight into the db.
        log_message = ugettext_noop(u'Changed status to \'%s\'.' %
            obj.get_status_display())
        modeladmin.log_change(request, obj, log_message)

    # Send a message to the user telling them what has happened.
    message_dict = {
        'count': queryset.count(),
        'object': modeladmin.model._meta.verbose_name,
        'verb': dict(STATUS_CHOICES)[status],
    }
    if not message_dict['count'] == 1:
        message_dict['object'] = modeladmin.model._meta.verbose_name_plural
    user_message = ungettext(
        u'%(count)s %(object)s was successfully %(verb)s.',
        u'%(count)s  %(object)s were successfully %(verb)s.',
        message_dict['count']) % message_dict
    modeladmin.message_user(request, user_message)

    # Return None to display the change list page again and allow the user
    # to reload the page without getting that nasty "Send the form again ..."
    # warning from their browser.
    return None
488238
def query_dated(num=8, kind='1'):
        '''
        
        '''
        return TabPost.select().where(
            TabPost.kind == kind
        ).order_by(
            TabPost.time_update.asc()
        ).limit(num)
1182369
function setMetricQuery( query ) {
		query.metric( metric )
			.aggregator( aggregator )
			.downsample( downsample )
			.rate( rate )
			.rateOptions({
				'counter': counter,
				'counterMax': counterMax,
				'resetValue': resetValue
			})
			.tags( 'nid', tags.nid );
	}
815766
def update_counts(self):
        ""
        # Properties.attrib['TotalCountOfFields']
        fields = str(len(self.fields))
        self.properties.attrib['TotalCountOfFields'] = fields

        # Properties.CountOfWellsX/Y
        wx, wy = (str(x) for x in self.count_of_wells)

        self.properties.CountOfWellsX = wx
        self.properties.CountOfWellsY = wy

        # Properties.attrib['TotalCountOfWells']
        wells = str(len(self.wells))
        self.properties.attrib['TotalCountOfWells'] = wells

        # Properties.attrib['TotalAssignedJobs']
        self.properties.attrib['TotalAssignedJobs'] = str(self.count_of_assigned_jobs)
644708
private void statsTick(long time)
    {
        /*
         * grab the table statistics from ee and put it into the statistics
         * agent.
         */
        if (m_tableStats != null) {
            CatalogMap<Table> tables = m_context.database.getTables();
            int[] tableIds = new int[tables.size()];
            int i = 0;
            for (Table table : tables) {
                tableIds[i++] = table.getRelativeIndex();
            }

            // data to aggregate
            long tupleCount = 0;
            long tupleDataMem = 0;
            long tupleAllocatedMem = 0;
            long indexMem = 0;
            long stringMem = 0;

            // update table stats
            final VoltTable[] s1 =
                m_ee.getStats(StatsSelector.TABLE, tableIds, false, time);
            if ((s1 != null) && (s1.length > 0)) {
                VoltTable stats = s1[0];
                assert(stats != null);

                // rollup the table memory stats for this site
                while (stats.advanceRow()) {
                    //Assert column index matches name for ENG-4092
                    assert(stats.getColumnName(7).equals("TUPLE_COUNT"));
                    assert(stats.getColumnName(6).equals("TABLE_TYPE"));
                    assert(stats.getColumnName(5).equals("TABLE_NAME"));
                    boolean isReplicated = tables.getIgnoreCase(stats.getString(5)).getIsreplicated();
                    boolean trackMemory = (!isReplicated) || m_isLowestSiteId;
                    if ("PersistentTable".equals(stats.getString(6)) && trackMemory){
                        tupleCount += stats.getLong(7);
                    }
                    assert(stats.getColumnName(8).equals("TUPLE_ALLOCATED_MEMORY"));
                    if (trackMemory) {
                        tupleAllocatedMem += stats.getLong(8);
                    }
                    assert(stats.getColumnName(9).equals("TUPLE_DATA_MEMORY"));
                    if (trackMemory) {
                        tupleDataMem += stats.getLong(9);
                    }
                    assert(stats.getColumnName(10).equals("STRING_DATA_MEMORY"));
                    if (trackMemory) {
                        stringMem += stats.getLong(10);
                    }
                }
                stats.resetRowPosition();

                m_tableStats.setStatsTable(stats);
            }
            else {
                // the EE returned no table stats, which means there are no tables.
                // Need to ensure the cached stats are cleared to reflect that
                m_tableStats.resetStatsTable();
            }

            // update index stats
            final VoltTable[] s2 =
                m_ee.getStats(StatsSelector.INDEX, tableIds, false, time);
            if ((s2 != null) && (s2.length > 0)) {
                VoltTable stats = s2[0];
                assert(stats != null);

                // rollup the index memory stats for this site
                while (stats.advanceRow()) {
                    //Assert column index matches name for ENG-4092
                    assert(stats.getColumnName(6).equals("TABLE_NAME"));
                    boolean isReplicated = tables.getIgnoreCase(stats.getString(6)).getIsreplicated();
                    boolean trackMemory = (!isReplicated) || m_isLowestSiteId;
                    assert(stats.getColumnName(11).equals("MEMORY_ESTIMATE"));
                    if (trackMemory) {
                        indexMem += stats.getLong(11);
                    }
                }
                stats.resetRowPosition();

                m_indexStats.setStatsTable(stats);
            }
            else {
                // the EE returned no index stats, which means there are no indexes.
                // Need to ensure the cached stats are cleared to reflect that
                m_indexStats.resetStatsTable();
            }

            // update the rolled up memory statistics
            if (m_memStats != null) {
                m_memStats.eeUpdateMemStats(m_siteId,
                                            tupleCount,
                                            tupleDataMem,
                                            tupleAllocatedMem,
                                            indexMem,
                                            stringMem,
                                            m_ee.getThreadLocalPoolAllocations());
            }
        }
    }
931333
def timing(self, stats, value):
        
        self.update_stats(stats, value, self.SC_TIMING)
875926
def display_queries(request, stats, queries):
    
    sort = request.REQUEST.get('sort_by', 'time')
    sort_buttons = RadioButtons('sort_by', sort, (
        ('order', 'by order'), ('time', 'time'), ('queries', 'query count')
    ))
    output = render_queries(queries, sort)
    output.reset()
    output = [html.escape(unicode(line)) for line in output.readlines()]
    response = HttpResponse(mimetype='text/html; charset=utf-8')
    response.content = (queries_template % {
        'sort_buttons': sort_buttons,
        'num_queries': len(queries),
        'queries': "".join(output),
        'rawqueries' : b64encode(cPickle.dumps(queries)),
        'rawstats': b64encode(pickle_stats(stats)),
        'url': request.path
    })
    return response
190394
def update_views(self):
        """"""
        # Call the father's method
        super(Plugin, self).update_views()

        # Add specifics informations
        # Alert and log
        for key in ['user', 'system', 'iowait']:
            if key in self.stats:
                self.views[key]['decoration'] = self.get_alert_log(self.stats[key], header=key)
        # Alert only
        for key in ['steal', 'total']:
            if key in self.stats:
                self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key)
        # Alert only but depend on Core number
        for key in ['ctx_switches']:
            if key in self.stats:
                self.views[key]['decoration'] = self.get_alert(self.stats[key], maximum=100 * self.stats['cpucore'], header=key)
        # Optional
        for key in ['nice', 'irq', 'iowait', 'steal', 'ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls']:
            if key in self.stats:
                self.views[key]['optional'] = True
85745
def _update_ned_query_history(
            self):
        
        self.log.debug('starting the ``_update_ned_query_history`` method')

        myPid = self.myPid

        # ASTROCALC UNIT CONVERTER OBJECT
        converter = unit_conversion(
            log=self.log
        )

        # UPDATE THE DATABASE HELPER TABLE TO GIVE DETAILS OF THE NED CONE
        # SEARCHES PERFORMED
        dataList = []
        for i, coord in enumerate(self.coordinateList):
            if isinstance(coord, str):
                ra = coord.split(" ")[0]
                dec = coord.split(" ")[1]
            elif isinstance(coord, tuple) or isinstance(coord, list):
                ra = coord[0]
                dec = coord[1]

            dataList.append(
                {"raDeg": ra,
                 "decDeg": dec,
                 "arcsecRadius": self.radiusArcsec}
            )

        if len(dataList) == 0:
            return None

        # CREATE TABLE IF NOT EXIST
        createStatement = """CREATE TABLE IF NOT EXISTS `tcs_helper_ned_query_history` (
  `primaryId` bigint(20) NOT NULL AUTO_INCREMENT,
  `raDeg` double DEFAULT NULL,
  `decDeg` double DEFAULT NULL,
  `dateCreated` datetime DEFAULT CURRENT_TIMESTAMP,
  `dateLastModified` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated` varchar(45) DEFAULT '0',
  `arcsecRadius` int(11) DEFAULT NULL,
  `dateQueried` datetime DEFAULT CURRENT_TIMESTAMP,
  `htm16ID` bigint(20) DEFAULT NULL,
  `htm13ID` int(11) DEFAULT NULL,
  `htm10ID` int(11) DEFAULT NULL,
  PRIMARY KEY (`primaryId`),
  KEY `idx_htm16ID` (`htm16ID`),
  KEY `dateQueried` (`dateQueried`),
  KEY `dateHtm16` (`dateQueried`,`htm16ID`),
  KEY `idx_htm10ID` (`htm10ID`),
  KEY `idx_htm13ID` (`htm13ID`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
        """
        writequery(
            log=self.log,
            sqlQuery=createStatement,
            dbConn=self.cataloguesDbConn
        )

        # USE dbSettings TO ACTIVATE MULTIPROCESSING
        insert_list_of_dictionaries_into_database_tables(
            dbConn=self.cataloguesDbConn,
            log=self.log,
            dictList=dataList,
            dbTableName="tcs_helper_ned_query_history",
            uniqueKeyList=[],
            dateModified=True,
            batchSize=10000,
            replace=True,
            dbSettings=self.settings["database settings"][
                "static catalogues"]
        )

        # INDEX THE TABLE FOR LATER SEARCHES
        add_htm_ids_to_mysql_database_table(
            raColName="raDeg",
            declColName="decDeg",
            tableName="tcs_helper_ned_query_history",
            dbConn=self.cataloguesDbConn,
            log=self.log,
            primaryIdColumnName="primaryId"
        )

        self.log.debug('completed the ``_update_ned_query_history`` method')
        return None
284255
def update(self):
        """"""
        # Had to convert it to string because datetime is not JSON serializable
        self.stats = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        # Add the time zone (issue #1249 and issue #1337)
        if 'tmzone' in localtime():
            self.stats += ' {}'.format(localtime().tm_zone)
        elif len(tzname) > 0:
            self.stats += ' {}'.format(tzname[1])

        return self.stats
675474
function updateNewIndicesAfterSlot(slot, indexDelta) {
                    // Adjust all the indexNews after this slot
                    for (slot = slot.next; slot; slot = slot.next) {
                        if (slot.firstInSequence) {
                            var indexNew = (slot.indexNew !== undefined ? slot.indexNew : slot.index);
                            if (indexNew !== undefined) {
                                slot.indexNew = indexNew + indexDelta;
                            }
                        }
                    }

                    // Adjust the overall count
                    countDelta += indexDelta;

                    indexUpdateDeferred = true;

                    // Increment currentRefreshID so any outstanding fetches don't cause trouble.  If a refresh is in progress,
                    // restart it (which will also increment currentRefreshID).
                    if (refreshInProgress) {
                        beginRefresh();
                    } else {
                        currentRefreshID++;
                    }
                }