Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xhprof_frame_begin & xhprof_frame_end #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extension/php_xhprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ PHP_FUNCTION(xhprof_enable);
PHP_FUNCTION(xhprof_disable);
PHP_FUNCTION(xhprof_sample_enable);
PHP_FUNCTION(xhprof_sample_disable);
PHP_FUNCTION(xhprof_frame_begin);
PHP_FUNCTION(xhprof_frame_end);

PHP_METHOD(XhprofFrame, __construct);
PHP_METHOD(XhprofFrame, __destruct);
#endif /* PHP_XHPROF_H */
40 changes: 40 additions & 0 deletions extension/tests/xhprof_frame_01.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
XHProf: xhprof_frame_* procedural interface
Author: bd808
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function procedural() {
xhprof_frame_begin('frame1');
inner();
xhprof_frame_begin('frame2');
inner();
xhprof_frame_begin('frame3');
inner();
xhprof_frame_end();
xhprof_frame_end();
xhprof_frame_end();
}

xhprof_enable();
procedural();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>procedural : ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
procedural==>frame1 : ct= 1; wt=*;
39 changes: 39 additions & 0 deletions extension/tests/xhprof_frame_02.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
XHProf: xhprof_frame_* procedural interface, XHPROF_FLAGS_NO_BUILTINS
Author: bd808
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function procedural() {
xhprof_frame_begin('frame1');
inner();
xhprof_frame_begin('frame2');
inner();
xhprof_frame_begin('frame3');
inner();
xhprof_frame_end();
xhprof_frame_end();
xhprof_frame_end();
}

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS);
procedural();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>procedural : ct= 1; wt=*;
procedural==>frame1 : ct= 1; wt=*;
49 changes: 49 additions & 0 deletions extension/tests/xhprof_frame_03.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
XHProf: xhprof_frame_* object interface
Author: bd808
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
die('skip this test for PHP <5.5; __destruct order incompatible');
}
?>
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function objects() {
$frame1 = new XhprofFrame('frame1');
inner();
$frame2 = new XhprofFrame('frame2');
inner();
$frame3 = new XhprofFrame('frame3');
inner();
}

xhprof_enable();
objects();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>XhprofFrame::__construct : ct= 1; wt=*;
frame1==>XhprofFrame::__destruct : ct= 1; wt=*;
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>XhprofFrame::__construct : ct= 1; wt=*;
frame2==>XhprofFrame::__destruct : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>XhprofFrame::__construct : ct= 1; wt=*;
frame3==>XhprofFrame::__destruct : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>objects : ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
objects==>frame1 : ct= 1; wt=*;
36 changes: 36 additions & 0 deletions extension/tests/xhprof_frame_04.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
XHProf: xhprof_frame_* object interface, XHPROF_FLAGS_NO_BUILTINS
Author: bd808
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function objects() {
$frame1 = new XhprofFrame('frame1');
inner();
$frame2 = new XhprofFrame('frame2');
inner();
$frame3 = new XhprofFrame('frame3');
inner();
}

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS);
objects();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>objects : ct= 1; wt=*;
objects==>frame1 : ct= 1; wt=*;
49 changes: 49 additions & 0 deletions extension/tests/xhprof_frame_05.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
XHProf: xhprof_frame_* mixed procedural and object
Author: bd808
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
die('skip this test for PHP <5.5; __destruct order incompatible');
}
?>
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function mixed() {
$frame1 = new XhprofFrame('frame1');
inner();
xhprof_frame_begin('frame2');
inner();
$frame3 = new XhprofFrame('frame3');
inner();
unset($frame3);
xhprof_frame_end();
}

xhprof_enable();
mixed();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>XhprofFrame::__construct : ct= 1; wt=*;
frame1==>XhprofFrame::__destruct : ct= 1; wt=*;
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>XhprofFrame::__construct : ct= 1; wt=*;
frame3==>XhprofFrame::__destruct : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>mixed : ct= 1; wt=*;
main()==>xhprof_disable : ct= 1; wt=*;
mixed==>frame1 : ct= 1; wt=*;
38 changes: 38 additions & 0 deletions extension/tests/xhprof_frame_06.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
XHProf: xhprof_frame_* mixed procedural and object, XHPROF_FLAGS_NO_BUILTINS
Author: bd808
--FILE--
<?php

include_once dirname(__FILE__).'/common.php';

function inner() {
return;
}

function mixed() {
$frame1 = new XhprofFrame('frame1');
inner();
xhprof_frame_begin('frame2');
inner();
$frame3 = new XhprofFrame('frame3');
inner();
unset($frame3);
xhprof_frame_end();
}

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS);
mixed();
$output = xhprof_disable();
print_canonical($output);
echo "\n";
?>
--EXPECT--
frame1==>frame2 : ct= 1; wt=*;
frame1==>inner : ct= 1; wt=*;
frame2==>frame3 : ct= 1; wt=*;
frame2==>inner : ct= 1; wt=*;
frame3==>inner : ct= 1; wt=*;
main() : ct= 1; wt=*;
main()==>mixed : ct= 1; wt=*;
mixed==>frame1 : ct= 1; wt=*;
Loading