added some more debug output for profiling

This commit is contained in:
Sebastian Grewe 2013-05-23 10:02:11 +02:00
parent 27ea17166e
commit 1bdf5e3156
4 changed files with 32 additions and 4 deletions

View File

@ -62,6 +62,7 @@ class Statistics {
* @return array * @return array
**/ **/
public function getBlocksFound($limit=10) { public function getBlocksFound($limit=10) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $limit)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $limit)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT b.*, a.username as finder SELECT b.*, a.username as finder
@ -84,6 +85,7 @@ class Statistics {
* @return bool * @return bool
**/ **/
public function updateShareStatistics($aStats, $iBlockId) { public function updateShareStatistics($aStats, $iBlockId) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)"); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true; if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
// Catchall // Catchall
@ -98,6 +100,7 @@ class Statistics {
* @return data object Return our hashrateas an object * @return data object Return our hashrateas an object
**/ **/
public function getCurrentHashrate() { public function getCurrentHashrate() {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SUM(hashrate) AS hashrate FROM SELECT SUM(hashrate) AS hashrate FROM
@ -118,6 +121,7 @@ class Statistics {
* @return data object Our share rate in shares per second * @return data object Our share rate in shares per second
**/ **/
public function getCurrentShareRate() { public function getCurrentShareRate() {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM SELECT ROUND(SUM(sharerate) / 600, 2) AS sharerate FROM
@ -138,6 +142,7 @@ class Statistics {
* @return data array invalid and valid shares * @return data array invalid and valid shares
**/ **/
public function getRoundShares() { public function getRoundShares() {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data; if ($data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
@ -162,6 +167,7 @@ class Statistics {
* @return data array invalid and valid share counts * @return data array invalid and valid share counts
**/ **/
public function getUserShares($account_id) { public function getUserShares($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
@ -217,6 +223,7 @@ class Statistics {
* @return data int Current hashrate in khash/s * @return data int Current hashrate in khash/s
**/ **/
public function getWorkerHashrate($worker_id) { public function getWorkerHashrate($worker_id) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $worker_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT ROUND(COUNT(s.id) * POW(2,21)/600/1000) AS hashrate SELECT ROUND(COUNT(s.id) * POW(2,21)/600/1000) AS hashrate
@ -239,6 +246,7 @@ class Statistics {
* @return data array Users with shares, account or hashrate, account * @return data array Users with shares, account or hashrate, account
**/ **/
public function getTopContributors($type='shares', $limit=15) { public function getTopContributors($type='shares', $limit=15) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $type . $limit)) return $data;
switch ($type) { switch ($type) {
case 'shares': case 'shares':
@ -280,6 +288,7 @@ class Statistics {
* @return data array NOT FINISHED YET * @return data array NOT FINISHED YET
**/ **/
public function getHourlyHashrateByAccount($account_id) { public function getHourlyHashrateByAccount($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT

View File

@ -38,10 +38,8 @@ class Transaction {
return false; return false;
} }
public function addDebit($account_id, $amount, $type='AP') {
}
public function getTransactions($account_id, $start=0) { public function getTransactions($account_id, $start=0) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
t.id AS id, t.id AS id,
@ -75,6 +73,7 @@ class Transaction {
} }
public function getBalance($account_id) { public function getBalance($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS balance SELECT ROUND(IFNULL(t1.credit, 0) - IFNULL(t2.debit, 0) - IFNULL(t3.other, 0), 8) AS balance
FROM FROM

View File

@ -41,6 +41,7 @@ class User {
* @return bool * @return bool
**/ **/
public function checkLogin($username, $password) { public function checkLogin($username, $password) {
$this->debug->append("STA " . __METHOD__, 4);
$this->debug->append("Checking login for $username with password $password", 2); $this->debug->append("Checking login for $username with password $password", 2);
if ( $this->checkUserPassword($username, $password) ) { if ( $this->checkUserPassword($username, $password) ) {
$this->createSession($username); $this->createSession($username);
@ -56,6 +57,7 @@ class User {
* @return bool * @return bool
**/ **/
public function checkPin($userId, $pin=false) { public function checkPin($userId, $pin=false) {
$this->debug->append("STA " . __METHOD__, 4);
$this->debug->append("Confirming PIN for $userId and pin $pin", 2); $this->debug->append("Confirming PIN for $userId and pin $pin", 2);
$stmt = $this->mysqli->prepare("SELECT pin FROM $this->table WHERE id=? AND pin=? LIMIT 1"); $stmt = $this->mysqli->prepare("SELECT pin FROM $this->table WHERE id=? AND pin=? LIMIT 1");
$pin_hash = hash('sha256', $pin.$this->salt); $pin_hash = hash('sha256', $pin.$this->salt);
@ -76,6 +78,7 @@ class User {
* @return array Return result * @return array Return result
**/ **/
private function getSingle($value, $search='id', $field='id', $type="i") { private function getSingle($value, $search='id', $field='id', $type="i") {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1"); $stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param($type, $value); $stmt->bind_param($type, $value);
@ -94,6 +97,7 @@ class User {
* @return data array All users with payout setup * @return data array All users with payout setup
**/ **/
public function getAllAutoPayout() { public function getAllAutoPayout() {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
id, username, coin_address, ap_threshold id, username, coin_address, ap_threshold
@ -115,6 +119,7 @@ class User {
* @return data string Coin Address * @return data string Coin Address
**/ **/
public function getCoinAddress($userID) { public function getCoinAddress($userID) {
$this->debug->append("STA " . __METHOD__, 4);
return $this->getSingle($userID, 'coin_address', 'id'); return $this->getSingle($userID, 'coin_address', 'id');
} }
@ -124,6 +129,7 @@ class User {
* @return data string Coin Address * @return data string Coin Address
**/ **/
public function getDonatePercent($userID) { public function getDonatePercent($userID) {
$this->debug->append("STA " . __METHOD__, 4);
$dPercent = $this->getSingle($userID, 'donate_percent', 'id'); $dPercent = $this->getSingle($userID, 'donate_percent', 'id');
if ($dPercent > 100) $dPercent = 100; if ($dPercent > 100) $dPercent = 100;
if ($dPercent < 0) $dPercent = 0; if ($dPercent < 0) $dPercent = 0;
@ -137,6 +143,7 @@ class User {
* @return bool * @return bool
**/ **/
private function updateSingle($userID, $field) { private function updateSingle($userID, $field) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("UPDATE $this->table SET " . $field['name'] . " = ? WHERE userId = ? LIMIT 1"); $stmt = $this->mysqli->prepare("UPDATE $this->table SET " . $field['name'] . " = ? WHERE userId = ? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param($field['type'].'i', $field['value'], $userID); $stmt->bind_param($field['type'].'i', $field['value'], $userID);
@ -148,6 +155,7 @@ class User {
} }
private function checkStmt($bState) { private function checkStmt($bState) {
$this->debug->append("STA " . __METHOD__, 4);
if ($bState ===! true) { if ($bState ===! true) {
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error); $this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
$this->setErrorMessage('Internal application Error'); $this->setErrorMessage('Internal application Error');
@ -157,6 +165,7 @@ class User {
} }
public function updatePassword($userID, $current, $new1, $new2) { public function updatePassword($userID, $current, $new1, $new2) {
$this->debug->append("STA " . __METHOD__, 4);
if ($new1 !== $new2) { if ($new1 !== $new2) {
$this->setErrorMessage( 'New passwords do not match' ); $this->setErrorMessage( 'New passwords do not match' );
return false; return false;
@ -181,6 +190,7 @@ class User {
} }
public function updateAccount($userID, $address, $threshold, $donate) { public function updateAccount($userID, $address, $threshold, $donate) {
$this->debug->append("STA " . __METHOD__, 4);
$bUser = false; $bUser = false;
$threshold = min(250, max(0, floatval($threshold))); $threshold = min(250, max(0, floatval($threshold)));
if ($threshold < 1) $threshold = 0.0; if ($threshold < 1) $threshold = 0.0;
@ -197,6 +207,7 @@ class User {
} }
private function checkUserPassword($username, $password) { private function checkUserPassword($username, $password) {
$this->debug->append("STA " . __METHOD__, 4);
$user = array(); $user = array();
$stmt = $this->mysqli->prepare("SELECT username, id FROM $this->table WHERE username=? AND pass=? LIMIT 1"); $stmt = $this->mysqli->prepare("SELECT username, id FROM $this->table WHERE username=? AND pass=? LIMIT 1");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
@ -213,6 +224,7 @@ class User {
} }
private function createSession($username) { private function createSession($username) {
$this->debug->append("STA " . __METHOD__, 4);
$this->debug->append("Log in user to _SESSION", 2); $this->debug->append("Log in user to _SESSION", 2);
session_regenerate_id(true); session_regenerate_id(true);
$_SESSION['AUTHENTICATED'] = '1'; $_SESSION['AUTHENTICATED'] = '1';
@ -221,16 +233,19 @@ class User {
} }
public function logoutUser() { public function logoutUser() {
$this->debug->append("STA " . __METHOD__, 4);
session_destroy(); session_destroy();
session_regenerate_id(true); session_regenerate_id(true);
return true; return true;
} }
public function getTableName() { public function getTableName() {
$this->debug->append("STA " . __METHOD__, 4);
return $this->table; return $this->table;
} }
public function getUserData($userID) { public function getUserData($userID) {
$this->debug->append("STA " . __METHOD__, 4);
$this->debug->append("Fetching user information for user id: $userID"); $this->debug->append("Fetching user information for user id: $userID");
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT SELECT
@ -238,7 +253,6 @@ class User {
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold
FROM $this->table FROM $this->table
WHERE id = ? LIMIT 0,1"); WHERE id = ? LIMIT 0,1");
echo $this->mysqli->error;
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param('i', $userID); $stmt->bind_param('i', $userID);
if (!$stmt->execute()) { if (!$stmt->execute()) {
@ -254,6 +268,7 @@ class User {
} }
public function register($username, $password1, $password2, $pin, $email1='', $email2='') { public function register($username, $password1, $password2, $pin, $email1='', $email2='') {
$this->debug->append("STA " . __METHOD__, 4);
if (strlen($password1) < 8) { if (strlen($password1) < 8) {
$this->setErrorMessage( 'Password is too short, minimum of 8 characters required' ); $this->setErrorMessage( 'Password is too short, minimum of 8 characters required' );
return false; return false;

View File

@ -41,6 +41,7 @@ class Worker {
* @return bool * @return bool
**/ **/
public function updateWorkers($account_id, $data) { public function updateWorkers($account_id, $data) {
$this->debug->append("STA " . __METHOD__, 4);
$username = $this->user->getUserName($account_id); $username = $this->user->getUserName($account_id);
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// Prefix the WebUser to Worker name // Prefix the WebUser to Worker name
@ -61,6 +62,7 @@ class Worker {
* @return mixed array Workers and their settings or false * @return mixed array Workers and their settings or false
**/ **/
public function getWorkers($account_id) { public function getWorkers($account_id) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare(" $stmt = $this->mysqli->prepare("
SELECT id, username, password, SELECT id, username, password,
( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active, ( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active,
@ -81,6 +83,7 @@ class Worker {
* @return data mixed int count if any workers are active, false otherwise * @return data mixed int count if any workers are active, false otherwise
**/ **/
public function getCountAllActiveWorkers() { public function getCountAllActiveWorkers() {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("SELECT COUNT(DISTINCT username) AS total FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)"); $stmt = $this->mysqli->prepare("SELECT COUNT(DISTINCT username) AS total FROM " . $this->share->getTableName() . " WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
if (!$stmt->execute()) { if (!$stmt->execute()) {
@ -103,6 +106,7 @@ class Worker {
* @return bool * @return bool
**/ **/
public function addWorker($account_id, $workerName, $workerPassword) { public function addWorker($account_id, $workerName, $workerPassword) {
$this->debug->append("STA " . __METHOD__, 4);
$username = $this->user->getUserName($account_id); $username = $this->user->getUserName($account_id);
$workerName = "$username.$workerName"; $workerName = "$username.$workerName";
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, username, password) VALUES(?, ?, ?)"); $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, username, password) VALUES(?, ?, ?)");
@ -125,6 +129,7 @@ class Worker {
* @return bool * @return bool
**/ **/
public function deleteWorker($account_id, $id) { public function deleteWorker($account_id, $id) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ?"); $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ?");
if ($this->checkStmt($stmt)) { if ($this->checkStmt($stmt)) {
$stmt->bind_param('ii', $account_id, $id); $stmt->bind_param('ii', $account_id, $id);