Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Refactor auto start code into \Tideways\Profiler::autoStart(); Cleanu…
Browse files Browse the repository at this point in the history
…p script. Remove usage of layer mode.
  • Loading branch information
beberlei committed Mar 30, 2015
1 parent ed67305 commit 0dafb83
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
45 changes: 44 additions & 1 deletion src/main/Tideways/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ public static function start($apiKey = null, $sampleRate = null)
return;
}

tideways_layers_enable(array(), self::$defaultOptions['transaction_function']);
tideways_enable(
TIDEWAYS_FLAGS_NO_USERLAND | TIDEWAYS_FLAGS_NO_BUILTINS,
array('tranasction_function' => self::$defaultOptions['transaction_function'])
);
self::$sampling = true;
}

Expand Down Expand Up @@ -800,4 +803,44 @@ public static function renderToolbarBootstrapHtml()
self::getProfileTraceUuid()
);
}

/**
* Check for auto starting the Profiler in Web and CLI (via Env Variable)
*/
public static function autoStart()
{
if (ini_get("tideways.auto_start") || isset($_SERVER["TIDEWAYS_AUTO_START"])) {
if (self::isStarted() === false) {
if (php_sapi_name() !== "cli") {
/**
* In Web context we auto start with the framework transaction name
* configured in INI or ENV variable.
*/
if (ini_get("tideways.framework")) {
self::detectFramework(ini_get("tideways.framework"));
} else if (isset($_SERVER['TIDEWAYS_FRAMEWORK'])) {
self::detectFramework($_SERVER["TIDEWAYS_FRAMEWORK"]);
}
self::start();
} else if (php_sapi_name() === "cli" && !empty($_SERVER["TIDEWAYS_SESSION"]) && isset($_SERVER['argv'])) {
self::start();
self::setTransactionName("cli:" . basename($_SERVER['argv'][0]));
}
}
}

if (self::requiresDelegateToOriginalPrependFile()) {
require_once ini_get("auto_prepend_file");
}
}

/**
* @return bool
*/
private static function requiresDelegateToOriginalPrependFile()
{
return ini_get('tideways.auto_prepend_library') &&
tideways_prepend_overwritten() &&
file_exists(ini_get("auto_prepend_file"));
}
}
23 changes: 2 additions & 21 deletions src/scripts/auto_start.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
<?php

/** Check for auto starting the Profiler in Web and CLI (via Env Variable) */
if (ini_get("tideways.auto_start") || isset($_SERVER["TIDEWAYS_AUTO_START"])) {
if (\Tideways\Profiler::isStarted() === false) {
if (php_sapi_name() !== "cli") {
/**
* In Web context we auto start with the framework transaction name
* configured in INI or ENV variable.
*/
if (ini_get("tideways.framework")) {
\Tideways\Profiler::detectFramework(ini_get("tideways.framework"));
} else if (isset($_SERVER['TIDEWAYS_FRAMEWORK'])) {
\Tideways\Profiler::detectFramework($_SERVER["TIDEWAYS_FRAMEWORK"]);
}
\Tideways\Profiler::start();
} else if (php_sapi_name() === "cli" && !empty($_SERVER["TIDEWAYS_SESSION"]) && isset($_SERVER['argv'])) {
\Tideways\Profiler::start();
\Tideways\Profiler::setTransactionName("cli:" . basename($_SERVER['argv'][0]));
}
}
}
// auto-starts the profiler if that is configured
\Tideways\Profiler::autoStart();

0 comments on commit 0dafb83

Please sign in to comment.