def _query(query_, debug = 0): """ Helper function for db_query(). """ if (lib_bootstrap.variable_get('dev_query', 0)): usec,sec = php.explode(' ', php.microtime()) timer = float(usec) + float(sec) # If devel.plugin query logging is enabled, prepend a comment # with the username and calling function # to the SQL string. This is useful when running mysql's # SHOW PROCESSLIST to learn what exact # code is issueing the slow query. bt = debug_backtrace() # t() may not be available yet so we don't wrap 'Anonymous' name = (lib_appglobals.user.name if (lib_appglobals.user.uid > 0) else \ variable_get('anonymous', 'Anonymous')) # php.str_replace() to prevent SQL injection via username # or anonymous name. name = php.str_replace(['*', '/'], '', name) query_ = '/* ' + name + ' : ' . bt[2]['function'] + ' */ ' + query_ result = DrupyMySQL.mysqli_query(lib_appglobals.active_db, query_) if (lib_bootstrap.variable_get('dev_query', 0)): query_ = bt[2]['function'] + "\n" + query_ usec,sec = php.explode(' ', php.microtime()) stop = float(usec) + float(sec) diff = stop - timer lib_appglobals.queries.append( [query_, diff] ) if (debug): print '<p>query: ' + query_ + '<br />error:' + \ DrupyMySQL.mysqli_error(lib_appglobals.active_db) + '</p>' if (not DrupyMySQL.mysqli_errno(lib_appglobals.active_db)): return result else: # Indicate to drupal_error_handler that this is a database error. DB_ERROR = True php.trigger_error(lib_bootstrap.check_plain(\ DrupyMySQL.mysqli_error(lib_appglobals.active_db) + \ "\nquery: " + query_), php.E_USER_WARNING) return False
def _query(query_, debug=0): """ Helper function for db_query(). """ if (lib_bootstrap.variable_get('dev_query', 0)): usec, sec = php.explode(' ', php.microtime()) timer = float(usec) + float(sec) # If devel.plugin query logging is enabled, prepend a comment # with the username and calling function # to the SQL string. This is useful when running mysql's # SHOW PROCESSLIST to learn what exact # code is issueing the slow query. bt = debug_backtrace() # t() may not be available yet so we don't wrap 'Anonymous' name = (lib_appglobals.user.name if (lib_appglobals.user.uid > 0) else \ variable_get('anonymous', 'Anonymous')) # php.str_replace() to prevent SQL injection via username # or anonymous name. name = php.str_replace(['*', '/'], '', name) query_ = '/* ' + name + ' : '.bt[2]['function'] + ' */ ' + query_ result = DrupyMySQL.mysqli_query(lib_appglobals.active_db, query_) if (lib_bootstrap.variable_get('dev_query', 0)): query_ = bt[2]['function'] + "\n" + query_ usec, sec = php.explode(' ', php.microtime()) stop = float(usec) + float(sec) diff = stop - timer lib_appglobals.queries.append([query_, diff]) if (debug): print '<p>query: ' + query_ + '<br />error:' + \ DrupyMySQL.mysqli_error(lib_appglobals.active_db) + '</p>' if (not DrupyMySQL.mysqli_errno(lib_appglobals.active_db)): return result else: # Indicate to drupal_error_handler that this is a database error. DB_ERROR = True php.trigger_error(lib_bootstrap.check_plain(\ DrupyMySQL.mysqli_error(lib_appglobals.active_db) + \ "\nquery: " + query_), php.E_USER_WARNING) return False
def timer_read(name): """ Read the current timer value without stopping the timer. @param name The name of the timer. @return The current timer value in ms. """ if (php.isset(lib_appglobals.timers[name], 'start')): (usec, sec) = php.explode(' ', php.microtime()) stop = float(usec) + float(sec) diff = round((stop - lib_appglobals.timers[name]['start']) * 1000, 2) if (php.isset(lib_appglobals.timers[name], 'time')): diff += lib_appglobals.timers[name]['time'] return diff
def timer_read(name): """ Read the current timer value without stopping the timer. @param name The name of the timer. @return The current timer value in ms. """ if php.isset(lib_appglobals.timers[name], "start"): (usec, sec) = php.explode(" ", php.microtime()) stop = float(usec) + float(sec) diff = round((stop - lib_appglobals.timers[name]["start"]) * 1000, 2) if php.isset(lib_appglobals.timers[name], "time"): diff += lib_appglobals.timers[name]["time"] return diff
def timer_start(name): """ Start the timer with the specified name. If you start and stop the same timer multiple times, the measured intervals will be accumulated. @param name The name of the timer. """ if lib_appglobals.timers == None: lib_appglobals.timers = {} if not php.isset(lib_appglobals.timers, name): lib_appglobals.timers[name] = {} (usec, sec) = php.explode(' ', php.microtime()) lib_appglobals.timers[name]['start'] = float(usec) + float(sec) lib_appglobals.timers[name]['count'] = \ ((lib_appglobals.timers[name]['count'] + 1) if \ php.isset(lib_appglobals.timers[name],'count') else 1)
def timer_start(name): """ Start the timer with the specified name. If you start and stop the same timer multiple times, the measured intervals will be accumulated. @param name The name of the timer. """ if lib_appglobals.timers == None: lib_appglobals.timers = {} if not php.isset(lib_appglobals.timers, name): lib_appglobals.timers[name] = {} (usec, sec) = php.explode(" ", php.microtime()) lib_appglobals.timers[name]["start"] = float(usec) + float(sec) lib_appglobals.timers[name]["count"] = ( (lib_appglobals.timers[name]["count"] + 1) if php.isset(lib_appglobals.timers[name], "count") else 1 )