मुझे एक ऐसा तरीका मिला जो मुझे लगता है कि हमारे उपयोग के मामले के लिए ठीक है।
<?php
/**
* This file is only used for doing realtime performance measurement
* Right now only the microtime is calculated, but in the future the
* xhproof module could be used: http://de2.php.net/manual/en/book.xhprof.php
*
* MAKE SURE TO NOT USE THIS FILE IN PRODUCTION FOR OTHER STUFF THAN REAL TIME
* PERFORMANCE MEASUREMENT
*/
$GLOBALS['PerformanceTwigExtensionMicrotime'] = microtime(true);
require_once __DIR__.'/app.php';
मैं भी एक टहनी विस्तार जो वैश्विक उपयोग करता है और बीता हुआ समय की गणना करता है पंजीकृत:
<?php
namespace Acme\DemoBundle\Extension;
class PerformanceTwigExtension extends \Twig_Extension {
public function getFunctions() {
return array(
'performance_exectime' => new \Twig_Function_Method($this, 'getExecTime')
);
}
public function getExecTime() {
if (!isset($GLOBALS['PerformanceTwigExtensionMicrotime'])) {
return 0;
}
$durationInMilliseconds = (microtime(true) - $GLOBALS['PerformanceTwigExtensionMicrotime']) * 1000;
return number_format($durationInMilliseconds, 3, '.', '');
}
public function getName() {
return "performance_extension";
}
}
जब हम चाहते हैं मैं वेब फ़ोल्डर में एक नया फ़ाइल performance.php जो इस तरह दिखता बनाया कुछ प्रदर्शन माप करने के लिए, हम बस performance.php का उपयोग कर सकते हैं। टेम्पलेट फ़ंक्शन को कॉल करने के लिए और फिर निष्पादन समय प्रदर्शित कर सकते हैं:
{{ performance_exectime() }}
यह आउटपुट 0 यदि प्रारंभ समय सेट नहीं है (उदाहरण के लिए जब सामान्य app.php प्रयोग किया जाता है), तो यह किसी भी मामले में उपयोग करने के लिए सुरक्षित है । दूसरी ओर, यदि कोई एंट्री पॉइंट के रूप में performance.php का उपयोग करने का निर्णय लेता है, तो इसे कुछ भी तोड़ना नहीं चाहिए क्योंकि केवल एक वैश्विक चर अलग है।
अंतर्निहित प्रोफाइलिंग सिस्टम के बारे में क्या? इसमें 2.1 में और भी शानदार विशेषताएं होंगी, जैसे एक विस्तृत समय ग्राफ, कुछ हद तक फायरबग और वेबकिट के ग्राफ के समान। – gilden
मैं इसे एक विशेष पृष्ठ पर उत्पादन वातावरण में करना चाहता हूं। अभी मुझे अंतर्दृष्टि नहीं है कि प्रोफाइलर कैसे काम करता है। क्या मैं इसे किसी भी तरह से "सक्रिय" कर सकता हूं जब मैं एक कार्यवाही करता हूं और अन्य सभी कार्यों पर कोई प्रदर्शन प्रभाव नहीं डालता? – Sgoettschkes
एक उत्पादन सर्वर पर प्रोफाइलिंग के लिए, आप शायद xhprof में देखना चाहते हैं ... – greg0ire