Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Initiate profiling ID early #2

Merged
merged 1 commit into from
Aug 23, 2017

Conversation

AlarSuu
Copy link
Contributor

@AlarSuu AlarSuu commented Aug 22, 2017

Initiate profiling id in Xhgui_Saver class constructor. That allows to use the same profiling ID throughout your request and profiler results can be easily mapped back to the areas, where this ID is used.

@@ -22,6 +22,20 @@ public function __construct(MongoDb $db)
*/
public function insert($profile)
{
$profile = $this->setProfilingId($profile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tabulation is off -- this project uses spaces, you use tabs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit: 8e46f10

$profile['_id'] = Xhgui_Saver::getLastProfilingId();
}
return $profile;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could just turn this into a static getCurrentProfileId method that provides static variable (initialized to new MongoId on first call)
and then just call that from insert and you'll have the ability to call it from anywhere that requires it.

Does this make sense to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -23,7 +28,20 @@ public static function factory($config)
$mongo = new MongoClient($config['db.host'], $config['db.options']);
$mongo->{$config['db.db']}->results->findOne();
$profiles = new Xhgui_Profiles($mongo->{$config['db.db']});
// Get new profiling ID, if profiler is enabled
if (call_user_func($config['profiler.enable'])) {
self::$lastProfilingId = new MongoId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think profiler.enable function should be called for anything except profiler enabling, as we won't know what lies there.

The user should be responsible for starting the profiler or take into account that asking for current profiling id while the profiler isn't running doesn't return anything meaningful (a MongoId that won't be persisted)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. And as I moved the static method into the Profiling.php class, then there are no changes in Saver.php class. I reverted my changes in a separate commit:
c68ee22

@markstory
Copy link
Member

I'm not really clear on how/why this feature is needed. In what scenarios do you need this?

@lauripiisang
Copy link
Contributor

@markstory This is so you can combine other profiling tools or manual profiling results with XHGUI results by having the profiling ID available.

If there was a way to get some meaningful ID from xhprof without disabling it, I'd probably use that.

@lauripiisang
Copy link
Contributor

I'd use getCurrentProfileId over getLastProfilingId, but that's a matter of preference I guess.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants