static function query($query) { if (!self::$zq) { Monda::init_sql(); } if (!is_array($query)) { $args = func_get_args(); } else { $args = $query; } $psql = new \Nette\Database\SqlPreprocessor(self::$zq->connection); list($sql) = $psql->process($args); CliDebug::dbg("zquery(\n{$sql}\n)=\n"); if (Options::get("progress")) { CliDebug::progress("Z\r"); } $ret = self::$zq->queryArgs(array_shift($args), $args); CliDebug::dbg(sprintf("%d\n", count($ret))); self::$lastsql = $sql; return $ret; }
static function systemStats($secs = false) { if ($secs || !isset(self::$cpustatsstamp)) { if (!$secs) { $secs = 1; } CliDebug::dbg("Collecting system stats for {$secs} seconds\n"); $stat1 = file('/proc/stat'); $info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0])); sleep($secs); } else { if (microtime(true) - self::$cpustatsstamp < 1) { return Monda::systemStats(1); } else { CliDebug::dbg(sprintf("Collected system stats for last %.2f seconds\n", microtime(true) - self::$cpustatsstamp)); } $info1 = self::$cpustats; } $stat2 = file('/proc/stat'); $info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0])); $dif = array(); $dif['user'] = $info2[0] - $info1[0]; $dif['nice'] = $info2[1] - $info1[1]; $dif['sys'] = $info2[2] - $info1[2]; $dif['idle'] = $info2[3] - $info1[3]; $dif['iowait'] = $info2[4] - $info1[4]; $total = array_sum($dif); $cpu = array(); foreach ($dif as $x => $y) { $cpu[$x] = round($y / $total * 100, 1); } if (microtime(true) - self::$cpustatsstamp > 1) { self::$cpustats = $info2; self::$cpustatsstamp = microtime(true); } self::$jobstats = $cpu; return $cpu; }