profiler.panel.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // utilize custom extension for Group Summary
  2. var summary = new Ext.ux.grid.GroupSummary();
  3. xBug.stores.Parser = new Ext.data.GroupingStore({
  4. autoDestroy: true,
  5. autoLoad: false,
  6. url : xBug.config.connector_url,
  7. baseParams : {
  8. action : 'mgr/xbug/profile'
  9. },
  10. reader : new Ext.data.JsonReader({
  11. successProperty : 'success',
  12. totalProperty : 'total',
  13. root : 'parser',
  14. fields : [{name : 'tag'}, {name : 'outerTag'}, {name : 'processTime'}, {name : 'cacheable'}]
  15. }),
  16. groupField : 'tag',
  17. listeners : {
  18. 'load' : function(store, records, opts) {
  19. xBug.stores.Profile.loadData({
  20. total : 1,
  21. success : true,
  22. profiles : store.reader.jsonData.profiles
  23. });
  24. xBug.stores.Cache.loadData({
  25. total : 1,
  26. success : true,
  27. cache : store.reader.jsonData.cache
  28. });
  29. var total_cache = Ext.get('total_cache');
  30. total_cache.update(store.reader.jsonData.totals.cache);
  31. var total_query = Ext.get('total_query');
  32. total_query.update(store.reader.jsonData.totals.profiles);
  33. var total_parsing = Ext.get('total_parsing');
  34. total_parsing.update(store.reader.jsonData.totals.parser);
  35. },
  36. 'exception' : function(misc) {
  37. console.log('Exception when loading profile data from server');
  38. }
  39. }
  40. });
  41. xBug.grid.Parser = new Ext.grid.GridPanel ({
  42. store: xBug.stores.Parser,
  43. view: new Ext.grid.GroupingView({
  44. forceFit: true,
  45. startCollapsed : true
  46. }),
  47. columns: [{header: 'Tag', dataIndex: 'tag', width: 150, fixed: true, align: 'right', sortable: true, summaryType: 'count',
  48. summaryRenderer: function(v, params, data){
  49. return ((v === 0 || v > 1) ? '(' + v +' Tags processed)' : '(1 Tag processed)');
  50. }},
  51. {header: 'outerTag', dataIndex: 'outerTag'},
  52. {header: 'Processing Time (S)', dataIndex : 'processTime', width: 150, fixed: true, align : 'right', sortable: true, summaryType: 'sum'},
  53. {header: 'cacheable', dataIndex: 'cacheable', width: 100, fixed: true, align: 'right', sortable: true}],
  54. autoWidth: true,
  55. height: 400,
  56. frame: false,
  57. title: 'Parser Data',
  58. id: 'xbug-parser-grid',
  59. margins: { top: 5, right : 0, bottom : 5, left : 0},
  60. plugins: summary
  61. });
  62. xBug.stores.Profile = new Ext.data.JsonStore({
  63. autoDestroy: true,
  64. autoLoad: false,
  65. url : null,
  66. fields : [{name : 'id'}, {name : 'duration'}, {name : 'sql'}],
  67. root : 'profiles'
  68. });
  69. xBug.grid.Profile = new Ext.grid.GridPanel ({
  70. store: xBug.stores.Profile,
  71. columns: [{header: 'ID', dataIndex: 'id', width: 50, fixed: true, align: 'right'},
  72. {header: 'Duration (S)', dataIndex: 'duration', width: 100, fixed: true, align: 'right', sortable: true},
  73. {header: 'Query', dataIndex: 'sql'}],
  74. autoWidth: true,
  75. height: 400,
  76. frame: false,
  77. title: 'SQL Profiles',
  78. id: 'xbug-profile-grid',
  79. margins: { top: 5, right: 0, bottom: 5, left: 0},
  80. viewConfig: {
  81. forceFit: true
  82. }
  83. });
  84. xBug.stores.Cache = new Ext.data.JsonStore({
  85. autoDestroy: true,
  86. autoLoad: false,
  87. url : null,
  88. fields : [{name : 'key'}, {name : 'processTime'}, {name : 'hit'}],
  89. root : 'cache'
  90. });
  91. xBug.grid.Cache = new Ext.grid.GridPanel ({
  92. store: xBug.stores.Cache,
  93. columns: [{header: 'KEY', dataIndex: 'key', align: 'right', width: 200, fixed : true, align: 'left'},
  94. {header: 'Duration (S)', dataIndex: 'processTime', width: 300, fixed: true, align: 'right', sortable: true},
  95. {header: 'Cache Hit', dataIndex: 'hit', sortable: true,width: 100, fixed: true,align: 'right'}],
  96. autoWidth: true,
  97. height: 400,
  98. frame: false,
  99. title: 'Cache Hit/Miss and cache retrieval times',
  100. id: 'xbug-cache-grid',
  101. margins: { top: 5, right: 0, bottom: 5, left: 0},
  102. viewConfig: {
  103. forceFit: true
  104. }
  105. });
  106. xBug.panel.Profiler = function(config) {
  107. config = config || {};
  108. Ext.apply(config, {
  109. id : 'xbug-profiler',
  110. baseCls: 'xbug-formpanel',
  111. cls: 'container',
  112. title : '<h2>' + _('xbug.profiler') + '</h2>' + '<p>' + _('xbug.profiler.desc') + '</p>',
  113. frame : false,
  114. border: false,
  115. allowDrop: true,
  116. xtype : 'modx-formpanel ',
  117. renderTo : 'xbug-panel-profiler-div',
  118. items : [{
  119. id : 'xbug-profiler-form',
  120. padding : 10,
  121. border : false,
  122. frame : true,
  123. autoWidth : true,
  124. items : [{
  125. layout : 'column',
  126. border: false
  127. ,anchor: '100%'
  128. ,defaults: {
  129. labelSeparator: ''
  130. ,labelAlign: 'top'
  131. ,border: false
  132. ,msgTarget: 'under'
  133. },
  134. items : [{
  135. defaults: { msgTarget: 'under' }
  136. ,items : [{
  137. xtype: 'label'
  138. ,forId: 'domain'
  139. ,html: '<p><b>Domain</b></p>'
  140. ,cls: 'desc-under'
  141. },{
  142. xtype : 'textfield',
  143. width : '300px',
  144. fieldLabel : 'Domain Name',
  145. id : 'domain',
  146. description : 'Domain name to be tested, defaults to site_url. Always end domain with /'
  147. },{
  148. xtype: 'label'
  149. ,forId: 'domain'
  150. ,html: '<p>Domain name to be tested, defaults to site_url. Always end domain with /</p>'
  151. ,cls: 'desc-under'
  152. },{
  153. xtype: 'label'
  154. ,forId: 'url'
  155. ,html: '<p><b>URI to be tested</b></p>'
  156. ,cls: 'desc-under'
  157. },{
  158. xtype : 'textfield',
  159. fieldLabel : 'URI or resource id',
  160. name : 'resource',
  161. width : '300px',
  162. id : 'url',
  163. description : 'Resource ID or URI from site without domain'
  164. },{
  165. xtype: 'label'
  166. ,forId: 'url'
  167. ,html: '<p>Resource ID or URI from site without domain</p>'
  168. ,cls: 'desc-under'
  169. }]
  170. },{
  171. items :[{
  172. xtype: 'label'
  173. ,forId: 'parameters'
  174. ,html: '<p><b>GET Parameters</b></p>'
  175. ,cls: 'desc-under'
  176. },{
  177. xtype : 'textfield',
  178. fieldLabel : 'URL parameters',
  179. name : 'url-params',
  180. width : '300px',
  181. id : 'parameters',
  182. description : 'GET parameters in format &somevar=1&othervar=2',
  183. allowDrop : false
  184. },{
  185. xtype: 'label'
  186. ,forId: 'parameters'
  187. ,html: '<p>GET parameters in format &somevar=1&othervar=2</p>'
  188. ,cls: 'desc-under'
  189. },{
  190. xtype: 'label'
  191. ,forId: 'post-parameters'
  192. ,html: '<p><b>POST Parameters</b></p>'
  193. ,cls: 'desc-under'
  194. },{
  195. xtype : 'textfield',
  196. fieldLabel : 'POST parameters',
  197. name : 'post-params',
  198. width : '300px',
  199. id : 'post-parameters',
  200. description : 'POST parameters in format &somevar=1&othervar=2',
  201. allowDrop : false
  202. },{
  203. xtype: 'label'
  204. ,forId: 'post-parameters'
  205. ,html: '<p>POST parameters in format &somevar=1&othervar=2</p>'
  206. ,cls: 'desc-under'
  207. },{
  208. xtype: 'label'
  209. ,forId: 'cookie-parameters'
  210. ,html: '<p><b>COOKIE Parameters</b></p>'
  211. ,cls: 'desc-under'
  212. },{
  213. xtype : 'textfield',
  214. fieldLabel : 'COOKIE parameters',
  215. name : 'cookie-params',
  216. width : '300px',
  217. id : 'cookie-parameters',
  218. description : 'COOKIE parameters in format somevar=1;othervar=2',
  219. allowDrop : false
  220. },{
  221. xtype: 'label'
  222. ,forId: 'cookie-parameters'
  223. ,html: '<p>COOKIE parameters in format somevar=1;othervar=2</p>'
  224. ,cls: 'desc-under'
  225. }]
  226. }]
  227. },{
  228. xtype : 'toolbar',
  229. hideBorders: true,
  230. items : [{
  231. xtype : 'checkbox',
  232. name : 'clear_cache',
  233. id : 'clear_cache',
  234. boxLabel : 'Refresh cache before page load'
  235. },{
  236. xtype : 'tbspacer',
  237. width : '20'
  238. },{
  239. xtype : 'button',
  240. name : 'profile',
  241. text : 'Profile Page',
  242. handler : this.sendRequest
  243. }]
  244. },{
  245. xtype : 'toolbar',
  246. hideBorders: true,
  247. items : [{
  248. xtype : 'label',
  249. html : 'Total parsing time <b id="total_parsing">0</b> seconds'
  250. },{
  251. xtype : 'tbspacer',
  252. width : '20'
  253. },{
  254. xtype : 'label',
  255. html : 'Total query time <b id="total_query">0</b> seconds'
  256. },{
  257. xtype : 'tbspacer',
  258. width : '20'
  259. },{
  260. xtype : 'label',
  261. html : 'Total cache time <b id="total_cache">0</b> seconds'
  262. }]
  263. }]
  264. },{
  265. xtype : 'panel',
  266. autoHeight : true,
  267. height : 800,
  268. items : [xBug.grid.Parser.show(),
  269. xBug.grid.Profile.show(),
  270. xBug.grid.Cache.show()]
  271. }],
  272. listeners : {
  273. added : function(evt) {
  274. this.onReady(evt);
  275. }
  276. }
  277. });
  278. xBug.panel.Profiler.superclass.constructor.call(this, config);
  279. }
  280. Ext.extend(xBug.panel.Profiler, MODx.FormPanel, {
  281. onReady: function(r) {
  282. this.isReady = true;
  283. this.loadDropZones();
  284. },
  285. loadDropZones: function() {
  286. var flds = this.getForm().items;
  287. flds.each(function(fld) {
  288. if (fld.isFormField && (
  289. fld.isXType('textfield') || fld.isXType('textarea')
  290. ) && !fld.isXType('combo')) {
  291. var el = fld.getEl();
  292. if (el) {
  293. new MODx.load({
  294. xtype: 'modx-treedrop'
  295. ,target: fld
  296. ,targetEl: el.dom
  297. });
  298. }
  299. }
  300. });
  301. },sendRequest : function () {
  302. var url = Ext.getCmp('url').getValue();
  303. var clear_cache = Ext.getCmp('clear_cache').getValue() ? 1 : 0;
  304. var domain = Ext.getCmp('domain').getValue();
  305. var getvars = "'" + Ext.getCmp('parameters').getValue() + "'";
  306. var postvars = "'" + Ext.getCmp('post-parameters').getValue() + "'";
  307. var cookievars = "'" + Ext.getCmp('cookie-parameters').getValue() + "'";
  308. var id = url;
  309. var pat = new RegExp(/\[\[\~[0-9]*\]\]/);
  310. if (pat.test(url)) {
  311. var match = url.match(/\d+/);
  312. id = match[0];
  313. }
  314. Ext.getCmp('xbug-profiler').getEl().mask('Please wait for page loader to load page');
  315. Ext.Ajax.request({
  316. url: xBug.config.connectorUrl+'?action=mgr/xbug/loadpage&url=' + id + "&domain=" +domain + "&clear_cache=" + clear_cache + "&get=" + getvars +
  317. "&post=" + postvars + "&cookie=" + cookievars,
  318. success: function(response, opts) {
  319. xBug.stores.Parser.load();
  320. Ext.getCmp('xbug-profiler').getEl().unmask();
  321. },
  322. failure: function(response, opts) {
  323. console.log('server-side failure with status code ' + response.status);
  324. Ext.getCmp('xbug-profiler').getEl().unmask();
  325. }
  326. });
  327. }
  328. });
  329. Ext.reg('xbug-panel-profiler', xBug.panel.Profiler);