s/Context/EventTracer/g

This commit is contained in:
Shish 2019-07-05 20:49:47 +01:00
parent f0326dc3ab
commit ccb9c493d5
10 changed files with 63 additions and 58 deletions

View file

@ -31,7 +31,7 @@
"ifixit/php-akismet" : "1.*",
"google/recaptcha" : "~1.1",
"dapphp/securimage" : "3.6.*",
"shish/libcontext-php" : "dev-master",
"shish/eventtracer-php" : "dev-master",
"enshrined/svg-sanitize" : "0.8.2",
"bower-asset/jquery" : "1.12.3",

35
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b679340e0fc96ae78f8919db742d17da",
"content-hash": "b1d9675735299d17a988bc9dfc8e5973",
"packages": [
{
"name": "bower-asset/jquery",
@ -297,26 +297,33 @@
"type": "library"
},
{
"name": "shish/libcontext-php",
"name": "shish/eventtracer-php",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/shish/libcontext-php.git",
"reference": "f57c377e0a5e700fb4d9406e47051a3b7478170e"
"url": "https://github.com/shish/eventtracer-php.git",
"reference": "8fc0001dffa6cc68ee56e8681a2e27579eb70dca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/libcontext-php/zipball/f57c377e0a5e700fb4d9406e47051a3b7478170e",
"reference": "f57c377e0a5e700fb4d9406e47051a3b7478170e",
"url": "https://api.github.com/repos/shish/eventtracer-php/zipball/8fc0001dffa6cc68ee56e8681a2e27579eb70dca",
"reference": "8fc0001dffa6cc68ee56e8681a2e27579eb70dca",
"shasum": ""
},
"require": {
"php": ">=7.0"
"ext-json": "*",
"ext-posix": "*",
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "6.*"
"phpunit/phpunit": "^7"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
@ -329,13 +336,9 @@
"role": "Developer"
}
],
"description": "A performance monitoring thing",
"homepage": "https://github.com/shish/libcontext-php",
"keywords": [
"performance",
"profiler"
],
"time": "2017-09-21T13:25:55+00:00"
"description": "An API to write JSON traces as used by the Chrome Trace Viewer",
"homepage": "https://github.com/shish/eventtracer-php",
"time": "2019-07-05T14:44:25+00:00"
}
],
"packages-dev": [
@ -1815,7 +1818,7 @@
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"shish/libcontext-php": 20,
"shish/eventtracer-php": 20,
"bower-asset/tablesorter": 20
},
"prefer-stable": false,

View file

@ -4,12 +4,11 @@
* actually do anything as far as the app is concerned
*/
global $config, $database, $user, $page, $_shm_ctx;
global $config, $database, $user, $page, $_tracer;
require_once "core/sys_config.php";
require_once "core/polyfills.php";
require_once "core/util.php";
require_once "vendor/shish/libcontext-php/context.php";
require_once "vendor/autoload.php";
// set up and purify the environment
@ -17,8 +16,8 @@ _version_check();
_sanitise_environment();
// load base files
$_shm_ctx->log_start("Bootstrap");
$_shm_ctx->log_start("Opening files");
$_tracer->begin("Bootstrap");
$_tracer->begin("Opening files");
$_shm_files = array_merge(
zglob("core/*.php"),
zglob("core/{".ENABLED_MODS."}/*.php"),
@ -31,27 +30,27 @@ foreach ($_shm_files as $_shm_filename) {
}
unset($_shm_files);
unset($_shm_filename);
$_shm_ctx->log_endok();
$_tracer->end();
// connect to the database
$_shm_ctx->log_start("Connecting to DB");
$_tracer->begin("Connecting to DB");
$database = new Database();
$config = new DatabaseConfig($database);
$_shm_ctx->log_endok();
$_tracer->end();
// load the theme parts
$_shm_ctx->log_start("Loading themelets");
$_tracer->begin("Loading themelets");
foreach (_get_themelet_files(get_theme()) as $themelet) {
require_once $themelet;
}
unset($themelet);
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
$_shm_ctx->log_endok();
$_tracer->end();
// hook up event handlers
$_shm_ctx->log_start("Loading extensions");
$_tracer->begin("Loading extensions");
_load_event_listeners();
$_shm_ctx->log_endok();
$_tracer->end();
send_event(new InitExtEvent());
$_shm_ctx->log_endok();
$_tracer->end();

View file

@ -188,11 +188,14 @@ class Cache
public function get(string $key)
{
global $_tracer;
$_tracer->begin("Cache Query", null, ["key"=>$key]);
$val = $this->engine->get($key);
if ((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) {
$hit = $val === false ? "hit" : "miss";
file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND);
}
$_tracer->end();
if ($val !== false) {
$this->hits++;
return $val;

View file

@ -221,6 +221,8 @@ class Database
public function execute(string $query, array $args=[]): PDOStatement
{
global $_tracer;
$_tracer->begin("DB Query", null, ["query"=>$query]);
try {
if (is_null($this->db)) {
$this->connect_db();
@ -246,6 +248,8 @@ class Database
return $stmt;
} catch (PDOException $pdoe) {
throw new SCoreException($pdoe->getMessage()."<p><b>Query:</b> ".$query);
} finally {
$_tracer->end();
}
}

View file

@ -262,17 +262,21 @@ class Image
public static function query_accelerator($req)
{
global $_tracer;
$fp = @fsockopen("127.0.0.1", 21212);
if (!$fp) {
return null;
}
fwrite($fp, json_encode($req));
$_tracer->begin("Query Accelerator", null, ["req"=>$req_str]);
$req_str = json_encode($req);
fwrite($fp, $req_str);
$data = "";
while (($buffer = fgets($fp, 4096)) !== false) {
$data .= $buffer;
}
$_tracer->end();
if (!feof($fp)) {
die("Error: unexpected fgets() fail in query_accelerator($req)\n");
die("Error: unexpected fgets() fail in query_accelerator($req_str)\n");
}
fclose($fp);
return json_decode($data);

View file

@ -101,7 +101,7 @@ $_shm_event_count = 0;
*/
function send_event(Event $event): void
{
global $_shm_event_listeners, $_shm_event_count, $_shm_ctx;
global $_shm_event_listeners, $_shm_event_count, $_tracer;
if (!isset($_shm_event_listeners[get_class($event)])) {
return;
}
@ -109,31 +109,23 @@ function send_event(Event $event): void
// send_event() is performance sensitive, and with the number
// of times context gets called the time starts to add up
$ctx_enabled = constant('CONTEXT');
$tracer_enabled = constant('EVENT_TRACE');
if ($ctx_enabled) {
$_shm_ctx->log_start(get_class($event));
}
if ($tracer_enabled) $_tracer->begin(get_class($event));
// SHIT: http://bugs.php.net/bug.php?id=35106
$my_event_listeners = $_shm_event_listeners[get_class($event)];
ksort($my_event_listeners);
foreach ($my_event_listeners as $listener) {
if ($ctx_enabled) {
$_shm_ctx->log_start(get_class($listener));
}
if ($tracer_enabled) $_tracer->begin(get_class($listener));
if (method_exists($listener, $method_name)) {
$listener->$method_name($event);
}
if ($ctx_enabled) {
$_shm_ctx->log_endok();
}
if ($tracer_enabled) $_tracer->end();
if($event->stop_processing===true) {
break;
}
}
$_shm_event_count++;
if ($ctx_enabled) {
$_shm_ctx->log_endok();
}
if ($tracer_enabled) $_tracer->end();
}

View file

@ -33,7 +33,7 @@ _d("DEBUG", false); // boolean print various debugging details
_d("DEBUG_SQL", false); // boolean dump SQL queries to data/sql.log
_d("DEBUG_CACHE", false); // boolean dump cache queries to data/cache.log
_d("COVERAGE", false); // boolean activate xdebug coverage monitor
_d("CONTEXT", null); // string file to log performance data into
_d("EVENT_TRACE", null); // string file to log performance data into
_d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance

View file

@ -1,6 +1,4 @@
<?php
require_once "vendor/shish/libcontext-php/context.php";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -460,7 +458,7 @@ date and you should plan on moving elsewhere.
function _sanitise_environment(): void
{
global $_shm_ctx;
global $_tracer;
if (TIMEZONE) {
date_default_timezone_set(TIMEZONE);
@ -472,10 +470,7 @@ function _sanitise_environment(): void
error_reporting(E_ALL);
}
$_shm_ctx = new Context();
if (CONTEXT) {
$_shm_ctx->set_log(CONTEXT);
}
$_tracer = new EventTracer();
if (COVERAGE) {
_start_coverage();

View file

@ -83,9 +83,11 @@ EOD;
exit;
}
require_once "core/_bootstrap.php";
//$_tracer->mark(@$_SERVER["REQUEST_URI"]);
$_tracer->begin($_SERVER["REQUEST_URI"] ?? "No Request");
try {
require_once "core/_bootstrap.php";
$_shm_ctx->log_start(@$_SERVER["REQUEST_URI"], true, true);
// start the page generation waterfall
$user = _get_user();
@ -104,12 +106,15 @@ try {
if (function_exists("fastcgi_finish_request")) {
fastcgi_finish_request();
}
$_shm_ctx->log_endok();
} catch (Exception $e) {
if ($database && $database->transaction===true) {
$database->rollback();
}
_fatal_error($e);
$_shm_ctx->log_ender();
}
log_slow();
$_tracer->end();
if (EVENT_TRACE) {
$_tracer->flush(EVENT_TRACE);
}