Thursday, June 19, 2008

Do Trace - Debug ( Profiling ) of PHP script by xdebug & kcachegrind


Step 1 : Install XDebug

xdebug is an open source debugger available for PHP. xdebug can be used to display more information in error traces. It can also be used to collect detailed code coverage & profiling information.

Installation

You need to install following packages to prepare environment for installation of pecl module xdebug.

sudo apt-get -y install php-pear php5-dev build-essential

Now we install xdebug using pecl.

sudo pecl install xdebug

Above command will download, compile & install xdebug on your system.

Configuration

Open usr/local/lib/php.ini and append following line.

zend_extension=/usr/lib/php5/20060613/xdebug.so

Be careful about that number part in the path as it could be different for you. Now restart apache by issuing following command.

sudo apache2ctl restart

Now try to view the output of your phpinfo() function. If you find xdebug word in that then it means you have successfully installed xdebug.

Stacktrace

xdebug.collect_params accepts values from 1 to 4. Where 1 refers to less verbosity & 4 refers to maximum verbosity while displaying stack traces. The easiest way of setting this option is using function ini_set in PHP.

ini_set("xdebug.collect_params", )

Get to know more stack trace options of xdebug.

var_dump

Once after installing xdebug when ever you call var_dump you are actually calling xdebug version of var_dump instead of built in one. By default xdebug version of var_dump gives you friendly info on the variables you are trying to inspect.

See more options on controlling display of var_dump information.

Debugging

xdebug uses DBGp protocol to communicate with external debuggers. Vim already has a plugin to do that. So you can debug php scripts from within vim.

Download php debugger plugin for vim.

Step 2: Enable Proiling

You need to add following line to /usr/local/lib/php.ini to enable profiling of php scripts.

xdebug.profiler_enable=1
Now restart the apache server by issuing following command.
sudo apache2ctl restart

When ever you access a php page through apache, xdebug will create a file something like cachegrind.out.15093. xdebug by default uses /tmp directory to dump files which contain profiling information. You can change this target directory by using xdebug option xdebug.profiler_output_dir and you can change result file name by using the option xdebug.profiler_output_name.

See more xdebug profiling options.

Some times you don't want to profile all requests. xdebug provides a selective mechanism to trigger profiling of specific requests. In order to enable this option you have to add following configuration option to php.ini.
xdebug.profiler_enable_trigger=On

Now you can trigger profiling of specific requests by adding XDEBUG_PROFILE to the query part of the GET request.

Analyzing Profiling results

We need to use kcachegrind to analyse profile file results. We can install kcachegrind by issuing following command.

sudo apt-get -y install kcachegrind

Now open your profle result file in kcachegrind and you can visuall inspect which part of your script is eating cpu resources. Callmap & Callgrap provide easy to understand visualizations to find bottlenecks in your script.

27 comments:

j said...

ralph lauren poloburberry polo shirtthe north face jacketcolumbia jacketspyder jacket

j said...

Modern tennis racquet in the manufacturing sector have been in use for close to the aerospace industry and military-industrial material products. Over the past two decades, metal materials and chemical materials to upgrade the high level of tennis racket manufacturer has laid a solid foundation. In today's big brands have more than tennis: Head junior tennis racket,Wilson tennis racquet, Wilson tennis racket,Head tennis racket,Babolat tennis racket......

crystal said...

Thank you so much!!polo shirt men'ssweate,cheap polo shirts cheap columbia jackets, lacoste sweater, ralph lauren polo shirts,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping

experience on mensclothingus.com。We have mens polo shirts.

crystal said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma, puma CAT,Puma shoes store gives some preview of puma

speed cat
,puma basket, puma speed, puma speed and other puma shoes. These puma sport items are at store recently and available for anyone.

crystal said...

Awesome!!!Best wishes for you !! wholesale polo shirts is the father of the

summer should be prepared to most commonly used item, it has both style and shape of polo clothing, and vest with a random function, so that in the short-sleeved

apply to both on many occasions, the pink and black color men's polo shirts

brought into effect, lightweight cotton, linen texture to demonstrate masculine temperament and sense of fashion

exhaustively. polo shirts for sale

crystal said...

Do not mean bad.Thank you so much!I just want to show some fashion things to all of you.I like ugg boots.black ugg boots,Loose T

-shirt or super-size clothing are the best partners, it allows you to exercise in relax.The classic style cheap uggs may fit someone.You should never design yourself into a monster of

no golden section point because beautiful cheap ugg boots.Also,for ladies,

in winter sheepskin boots are the excellent choice.ugg boots on sale

crystal said...

Wonderful!!You can find the father who desire fashionable, intellectual cheap

polos
simultaneously, you can find a psychologist to study the most harmonious of families should be pink mens clothing, so do not want to take the mature route for the father, buy cheap polos, the learn from such a walk in between the formal and casual

styling, refined style to create a sense of mild authority.

crystal said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades,ugg boots,polo clothing.gillette mach3 razor

blades
,gillette venus razor blades,gillette fusion blades are all the best choice for you.

crystal said...

Men's polo shirts was the shirt of choice for diverse groups of

teenagers

Brightly coloured polo shirts can make you look like a Day-glo

dirigible.

Wonderful!You can find the father who desire fashionable, intellectual polo shirt simultaneously

fdg said...

I like your blog. Thank you. They are really great . Ermunterung ++ .
Some new style Puma Speed is in fashion this year.
chaussure puma is Puma shoes in french . Many Franzose like seach “chaussure sport” by the internet when they need buy the Puma Shoes Or nike max shoes. The information age is really convenient .




By the way ,the nike max ltd is really good NIKE air shoes ,don’t forget buy the puma mens shoes and nike air max ltd by the internet when you need them . Do you know Nike Air Shoes is a best Air Shoes . another kinds of Nike shoes is better . For example , Nike Air Rift is good and Cheap Nike Shoes .the nike shox shoes is fitting to running.



Spring is coming, Do you think this season is not for Ugg Boots? maybe yes .but this season is best time that can buy the cheap ugg boots. Many sellers are selling discounted. Do not miss . Please view my fc2 blog and hair straighteners blog.
.thank you .


I like orange converse shoes ,I like to buy the cheap converse shoes by the internet shop . the puma shoes and the adidas shoes (or addidas shoes) are more on internet shop .i can buy the cheap nike shoes and cheap puma shoes online. It’s really convenient.
Many persons more like Puma basket shoes than nike air rift shoes . the Puma Cat shoes is a kind of Cheap Puma Shoes .
If you want to buy the Cheap Nike Air shoes ,you can buy them online. They are same as the Nike Air shoes authorized shop. Very high-caliber Air shoes and puma cat shoes . the cheap puma shoes as same as other.



polo shirts

ralph lauren polo shirts
chaussure puma

chaussure sport



chaussures puma

puma CAT

ed hardy clothing

ed hardy clothes



ed hardy womens

ed hardy sunglasses

fdg said...

http://www.seriousblogging.com/pumabasket
http://www.seriousblogging.com/pumabasket1
http://nikeshox.blog.shinobi.jp
http://pumabasket.blog.co.uk
http://fashionuggboots.arekao.jp
http://blog.goo.ne.jp/pumacat

tuo said...

I like your blog . They are really great. Ermunterung ++ .
some new style Air shoes is in fashion this year.Do you know Air Shoes is a best . another kinds of nike air rift is better . the Puma basket will make you feel very relaxed when you play basketball.If you want to buy the Cheap puma shoes shoes ,you can buy them online. Very high-caliber and cheap puma shoes as same as you buy from the authorized store..My younger sister's long hair is always chaotic. so i presented a hair straighteners to her for Christmas last year .she were very pleasantly surprised .

tuo said...

ralph lauren polo shirts
chaussure puma
puma CAT

ed hardy clothing
ed hardy sunglasses
Ugg Boots
hair straighteners
orange CONVERSE

tuo said...

You are currently spoilt for choice Polo Shirts On Sale with the selection of current star names to get put on the back of the polo ralph lauren, with such playres as Maldini, Toni, Di Rossi, Iaquinta, Pirlo, and Canavarro to name just a few cheappolos. And three are othre rising stars who might take your fancy burbrery polos, like Rossi, Balotelli, Pazzini and Aquilani. Ralph Lauren Polo Shirts are all going to be names that you’ll hear a lot more Burbrery Polo Shirts of in the future I’m sure.

tuo said...

In spite of the fact that many critics comment on ed hardy clothing as nothing but tattoo pattrens, being full of unnecessary and useless things, ed hardy clothes is widely acknowledged that ed hardy shirts draws the most attention of both common young people as well as many Hollywood welcomed stars for its punk rock styles. In fact, in today’s world, many ed hardy t-shirtsdesigns are more or less the same with each othre, and ed hardy mens and ed hardy womens , absolutely, brings a totally new shock in the fashion world for its design being out of ordinary ed hardy sunglasses.

J&D said...



辣妹視訊|美女視訊|視訊交友網|視訊聊天室|視訊交友|視訊美女|免費視訊|免費視訊聊天|視訊交友90739|免費視訊聊天室|成人聊天室|視訊聊天|視訊交友aooyy
哈啦聊天室|辣妺視訊|A片|色情A片|視訊|080視訊聊天室|視訊美女34c|視訊情人高雄網|視訊交友高雄網|0204貼圖區|sex520免費影片|情色貼圖|視訊ukiss|視訊ggoo|視訊美女ggoo|

080苗栗人聊天室|080中部人聊天室ut|ut影音視訊聊天室13077|視訊做愛|kk777視訊俱樂部|上班族聊天室|聊天室找一夜|情色交友|情色貼片|小瓢蟲情色論壇|aio交友愛情館|

哈拉聊天室|洪爺影城|kk123視訊俱樂部|6K聊天室|正妹視訊

情趣用品|情趣用品|情趣用品|情趣|情趣用品|情趣

Peejay Li said...

Thank you for sharing such a nice article.
chaussures puma
puma speed cat
Nike Tn Chaussures
requin tn
nike shox
puma shoes
puma CAT
puma basket
puma speed
baskets puma
puma sport
puma femmes
puma shox r4 torch
nike air max requin
nike shox r3
shox rival r3
tn plus
chaussures shox
nike shox r4 torch
air max tn requin
nike tn femme
pas cher nike
tn chaussures
nike rift
nike shox nz
chaussures shox
nike shox rival
shox rival
chaussures requin
jeans online
cheap armani jeans
cheap G-star jeans

lucyliu said...

nike air max 90
nike air max 95
nike air max tn
nike air rift
nike shox r4
nike air max 360
nike shox nz
puma mens shoes
puma shoes
puma speed
nike shoes
nike air
nike air shoes
puma cat
air max trainers
mens nike air max
nike shoes air max
nike shoes shox
air shoes
nike shoe cart
puma future
cheap puma
sports shoes
nike air rifts
nike air rift trainer
nike air
nike rift
nike rift shoes
cheap nike air rifts
bape shoes
jeans shop
diesel jeans
levis jeans

Sneakers hobbies said...

nice post!!
Do you like polo shirts? Where can buy the best quality and fashion cheap polo shirts? you can come to our outlets,we are the one of the most professional winter jackets and polo shirts.You also can buy the most cheap polo shirts wholesale,you order more,you can get more discount!

uwanna said...

Gucci
Gucci shop
Gucci bags
Gucci shoes
Replica GUCCI SHOES
wholesale gucci shoes
cheap Gucci handbags
Gucci ON sale
Gucci Belts
Gucci small accessories
Gucci hats & scarves
Gucci wallets
Gucci Handbags
Women Gucci shoes
Men Gucci shoes
discount gucci shoes
cheap Gucci shoes

Michael J said...

I love your blog very much,and i also want to introduce my products to all of you,them are nice and very fashion,if you like them,please contact us on our website or eamil us,thks very much for your attention.And this is my products below:
authentic gucci bags, gucci boots outlet
cheap gucci shoes, discount Gucci bags
newest gucci handbags, gucci handbags 2010
Juicy couture, authentic Juicy bags
Juicy handbags outlet, tiffany 2010
Tiffany, tiffany outlet
discount tiffany charms, cheap tiffany Bangles
Armani watches outlet, watch wholesale
discount DG watches, cheap Chanel watches
newest GUCCI watches, wholesale edhardy t shirt
Moncler, Mtb shoes
Moncler jackets, cheap Moncler coats
Moncler Vest, Moncler outlet
moncler polo t shirt, MBT boots
MBT shoes in fashion, cheap mbt shoes sale
discount mbt outlet 2010, MBT Walking Shoes

Michael J said...

I love your blog very much,and i also want to introduce my products to all of you,them are nice and very fashion,if you like them,please contact us on our website or eamil us,thks very much for your attention.And this is my products below:
BABYLISS
Benefit GHD
GHD IV Salon Styler
GHD MINI STYLER
GHD Precious Gift Set
Gold GHD
Kiss GHD
Pink GHD
Pure Black GHD
Pure White GHD
Purple GHD
Rare GHD
cheap ugg boots
discount ugg boots
ugg boots
classic ugg boots
ugg classic tall boots

ally said...

Fashion is all about lookingmoncler jackets good and being comfortable at the same time. monclermoncler coatsEvery woman loves being complimentedmoncler t-shirtmoncler vestmoncler outlet for her sense of style and elegance. ugg bootscheap ugg bootsdiscount ugg bootsNo woman wants to be labeled as outdated and old fashioned.ugg classic tall bootsclassic ugg bootsWomen are expected to be in constant touch with the latest trends in ordermoncler jacketsmonclernew moncler coats to adopt those trends and look fashionable and stylish. moncler vestmoncler outletmoncler polo t-shirtWomen need to make sure that whatever they wear, coach outletcoach handbagscoach bagsit should compliment their personality and they do not feel awkward while wearing it. coach totescoach outletlouis vuitton handbagsAn article about Gothic costume clothing and the importance of choosing Gothic choker. LV handbags 2010Louis Vuitton bagsLouis Vuitton totesThis article explores the wide variety of Gothicrain boots
rainweardiesel jeans chokers available from everyday to special occasions. Ture Religion Jeanslevis jeansabercrombie and fitch outletIt should inspire people to go shopping for their own Gothic chokers. ed hardy wholesaleed hardy outletcheap ed hardy wholesaleThe origins of the Flat cap span discount ed hardy wholesalewholesale ed hardy

ally said...

Fashion is all about lookingmoncler jackets good and being comfortable at the same time. monclermoncler coatsEvery woman loves being complimentedmoncler t-shirtmoncler vestmoncler outlet for her sense of style and elegance. ugg bootscheap ugg bootsdiscount ugg bootsNo woman wants to be labeled as outdated and old fashioned.ugg classic tall bootsclassic ugg bootsWomen are expected to be in constant touch with the latest trends in ordermoncler jacketsmonclernew moncler coats to adopt those trends and look fashionable and stylish. moncler vestmoncler outletmoncler polo t-shirtWomen need to make sure that whatever they wear, coach outletcoach handbagscoach bagsit should compliment their personality and they do not feel awkward while wearing it. coach totescoach outletlouis vuitton handbagsAn article about Gothic costume clothing and the importance of choosing Gothic choker. LV handbags 2010Louis Vuitton bagsLouis Vuitton totesThis article explores the wide variety of Gothicrain boots
rainweardiesel jeans chokers available from everyday to special occasions. Ture Religion Jeanslevis jeansabercrombie and fitch outletIt should inspire people to go shopping for their own Gothic chokers. ed hardy wholesaleed hardy outletcheap ed hardy wholesaleThe origins of the Flat cap span discount ed hardy wholesalewholesale ed hardy

ally said...

Fashion trends change on daily basis, like Gold GHD. Following the latest in designer shades has become a passion of everyone, now Burberry Sunglasses. If you are the type of a woman who loves to explore in fashion, our ED Hardy Sunglasses will definitely satisfy your taste. Cheap Ed Hardy Sunglasses is also OK. Ed hardy streak of clothing is expanded into its wholesale ED Hardy T-shirt chain so that a large number of fans and users can enjoy the cheap ED Hardy Clothing range easily with the help of numerous secured websites, actually, our ED Hardy Outlet. As we all know, in fact discount ED Hardy, is based on the creations of the world renowned tattoo artist Don Ed Hardy. Well, this question is bound to strike the minds of all individuals. Many people may say Prada shoes is a joke, but we can give you Prada Sunglasses, because we have Prada handbags. Almost everyone will agree that Prada Purses are some of the most beautiful designer handbags marketed today. Now we have one new product: Prada totes. The reason is simple: fashion prohibited by ugg boots, in other words, we can say it as Cheap ugg boots. Would you like to wear Discount ugg boots. We have two kinds of fashionable boots: classic ugg boots and ugg classic tall boots. Ankh Royalty--the Cultural Revolution. Straightens out the collar, the epaulette epaulet, the Ankh Royalty Clothing two-row buckle. Now welcome to our Ankh Royalty Outlet. And these are different products that bear the most famous names in the world of fashion, like Ankh Royalty T shirt by the way -Prada, Spyder, Moncler(Moncler jackets,or you can say Moncler coats, Moncler T-shirt, Moncler vest,and you can buy them from our discount Moncler outlet), GHD, ED Hardy, Ankh Royalty, Twisted Heart.

happyoutlet said...

He has in his office hours TEU,chi flat iron work schedule and social balance - juggling many students there.

If forced to cut short nap before go.chi flat irons Many students begin to fight, some Z, and often counting sheep a thing of the past.

"Sometimes cheap chi Straighteners I get only five hours sleep a night," said Goldin.

duckless said...

The original chi flat iron was released as a professional salon straightener. After gaining popularity on the market the cheap chi flat iron was later released for personal consumer use. If you are a professional stylist or someone who loves straightening their chi hair straightener before leaving for work the Chi original ceramic flat iron is one styling tool you cannot live without. Unlike other wholesale chi flat iron before its day the Chi model was developed with moist ceramic heat technology that does not burn or damage the wholesale chi hair straighteners.