@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DarkConsoleXHProfPlugin extends DarkConsolePlugin {
4
5 protected $profileFilePHID;
6
7 public function getName() {
8 return pht('XHProf');
9 }
10
11 public function getColor() {
12 $data = $this->getData();
13 if ($data['profileFilePHID']) {
14 return '#ff00ff';
15 }
16 return null;
17 }
18
19 public function getDescription() {
20 return pht('Provides detailed PHP profiling information through XHProf.');
21 }
22
23 public function generateData() {
24 return array(
25 'profileFilePHID' => $this->profileFilePHID,
26 'profileURI' => (string)$this
27 ->getRequestURI()
28 ->alter('__profile__', 'page'),
29 );
30 }
31
32 public function getXHProfRunID() {
33 return $this->profileFilePHID;
34 }
35
36 public function renderPanel() {
37 $data = $this->getData();
38
39 $run = $data['profileFilePHID'];
40 $profile_uri = $data['profileURI'];
41
42 if (!DarkConsoleXHProfPluginAPI::isProfilerAvailable()) {
43 $href = PhabricatorEnv::getDoclink('Installation Guide');
44 $install_guide = phutil_tag(
45 'a',
46 array(
47 'href' => $href,
48 'class' => 'bright-link',
49 ),
50 pht('Installation Guide'));
51 return hsprintf(
52 '<div class="dark-console-no-content">%s</div>',
53 pht(
54 'The "xhprof" PHP extension is not available. Install xhprof '.
55 'to enable the XHProf console plugin. You can find instructions in '.
56 'the %s.',
57 $install_guide));
58 }
59
60 $result = array();
61
62 $header = phutil_tag(
63 'div',
64 array('class' => 'dark-console-panel-header'),
65 array(
66 phutil_tag(
67 'a',
68 array(
69 'href' => $profile_uri,
70 'class' => $run ? 'disabled button' : 'button button-green',
71 ),
72 pht('Profile Page')),
73 phutil_tag('h1', array(), pht('XHProf Profiler')),
74 ));
75 $result[] = $header;
76
77 if ($run) {
78 $result[] = phutil_tag(
79 'a',
80 array(
81 'href' => "/xhprof/profile/$run/",
82 'class' => 'bright-link',
83 'style' => 'float: right; margin: 1em 2em 0 0; font-weight: bold;',
84 'target' => '_blank',
85 ),
86 pht('Profile Permalink'));
87 $result[] = phutil_tag(
88 'iframe',
89 array('src' => "/xhprof/profile/$run/?frame=true"));
90 } else {
91 $result[] = phutil_tag(
92 'div',
93 array('class' => 'dark-console-no-content'),
94 pht(
95 'Profiling was not enabled for this page. Use the button above '.
96 'to enable it.'));
97 }
98
99 return phutil_implode_html("\n", $result);
100 }
101
102
103 public function willShutdown() {
104 $this->profileFilePHID = DarkConsoleXHProfPluginAPI::getProfileFilePHID();
105 }
106
107}