PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/profilerlib.php

https://bitbucket.org/ceu/moodle_demo
PHP | 709 lines | 527 code | 59 blank | 123 comment | 136 complexity | 6f029c7e50a7857e093af2e06663c75f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?php
  2. ini_set('display_errors', "On");
  3. require_once 'PEAR.php';
  4. if(!function_exists('scandir'))
  5. {
  6. function scandir($dir, $sortorder = 0)
  7. {
  8. if(is_dir($dir))
  9. {
  10. $dirlist = opendir($dir);
  11. while( ($file = readdir($dirlist)) !== false)
  12. {
  13. if(!is_dir($file))
  14. {
  15. $files[] = $file;
  16. }
  17. }
  18. ($sortorder == 0) ? asort($files) : arsort($files);
  19. return $files;
  20. }
  21. else
  22. {
  23. return FALSE;
  24. break;
  25. }
  26. }
  27. }
  28. /**
  29. * Command-line options parsing class.
  30. *
  31. * @author Andrei Zmievski <andrei@php.net>
  32. *
  33. */
  34. class Console_Getopt {
  35. /**
  36. * Parses the command-line options.
  37. *
  38. * The first parameter to this function should be the list of command-line
  39. * arguments without the leading reference to the running program.
  40. *
  41. * The second parameter is a string of allowed short options. Each of the
  42. * option letters can be followed by a colon ':' to specify that the option
  43. * requires an argument, or a double colon '::' to specify that the option
  44. * takes an optional argument.
  45. *
  46. * The third argument is an optional array of allowed long options. The
  47. * leading '--' should not be included in the option name. Options that
  48. * require an argument should be followed by '=', and options that take an
  49. * option argument should be followed by '=='.
  50. *
  51. * The return value is an array of two elements: the list of parsed
  52. * options and the list of non-option command-line arguments. Each entry in
  53. * the list of parsed options is a pair of elements - the first one
  54. * specifies the option, and the second one specifies the option argument,
  55. * if there was one.
  56. *
  57. * Long and short options can be mixed.
  58. *
  59. * Most of the semantics of this function are based on GNU getopt_long().
  60. *
  61. * @param array $args an array of command-line arguments
  62. * @param string $short_options specifies the list of allowed short options
  63. * @param array $long_options specifies the list of allowed long options
  64. *
  65. * @return array two-element array containing the list of parsed options and
  66. * the non-option arguments
  67. *
  68. * @access public
  69. *
  70. */
  71. function getopt2($args, $short_options, $long_options = null)
  72. {
  73. return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
  74. }
  75. /**
  76. * This function expects $args to start with the script name (POSIX-style).
  77. * Preserved for backwards compatibility.
  78. * @see getopt2()
  79. */
  80. function getopt($args, $short_options, $long_options = null)
  81. {
  82. return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
  83. }
  84. /**
  85. * The actual implementation of the argument parsing code.
  86. */
  87. function doGetopt($version, $args, $short_options, $long_options = null)
  88. {
  89. // in case you pass directly readPHPArgv() as the first arg
  90. if (PEAR::isError($args)) {
  91. return $args;
  92. }
  93. if (empty($args)) {
  94. return array(array(), array());
  95. }
  96. $opts = array();
  97. $non_opts = array();
  98. settype($args, 'array');
  99. if ($long_options) {
  100. sort($long_options);
  101. }
  102. /*
  103. * Preserve backwards compatibility with callers that relied on
  104. * erroneous POSIX fix.
  105. */
  106. if ($version < 2) {
  107. if (isset($args[0]{0}) && $args[0]{0} != '-') {
  108. array_shift($args);
  109. }
  110. }
  111. reset($args);
  112. while (list($i, $arg) = each($args)) {
  113. /* The special element '--' means explicit end of
  114. options. Treat the rest of the arguments as non-options
  115. and end the loop. */
  116. if ($arg == '--') {
  117. $non_opts = array_merge($non_opts, array_slice($args, $i + 1));
  118. break;
  119. }
  120. if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
  121. $non_opts = array_merge($non_opts, array_slice($args, $i));
  122. break;
  123. } elseif (strlen($arg) > 1 && $arg{1} == '-') {
  124. $error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
  125. if (PEAR::isError($error))
  126. return $error;
  127. } else {
  128. $error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
  129. if (PEAR::isError($error))
  130. return $error;
  131. }
  132. }
  133. return array($opts, $non_opts);
  134. }
  135. /**
  136. * @access private
  137. *
  138. */
  139. function _parseShortOption($arg, $short_options, &$opts, &$args)
  140. {
  141. for ($i = 0; $i < strlen($arg); $i++) {
  142. $opt = $arg{$i};
  143. $opt_arg = null;
  144. /* Try to find the short option in the specifier string. */
  145. if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
  146. {
  147. return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
  148. }
  149. if (strlen($spec) > 1 && $spec{1} == ':') {
  150. if (strlen($spec) > 2 && $spec{2} == ':') {
  151. if ($i + 1 < strlen($arg)) {
  152. /* Option takes an optional argument. Use the remainder of
  153. the arg string if there is anything left. */
  154. $opts[] = array($opt, substr($arg, $i + 1));
  155. break;
  156. }
  157. } else {
  158. /* Option requires an argument. Use the remainder of the arg
  159. string if there is anything left. */
  160. if ($i + 1 < strlen($arg)) {
  161. $opts[] = array($opt, substr($arg, $i + 1));
  162. break;
  163. } else if (list(, $opt_arg) = each($args))
  164. /* Else use the next argument. */;
  165. else
  166. return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
  167. }
  168. }
  169. $opts[] = array($opt, $opt_arg);
  170. }
  171. }
  172. /**
  173. * @access private
  174. *
  175. */
  176. function _parseLongOption($arg, $long_options, &$opts, &$args)
  177. {
  178. @list($opt, $opt_arg) = explode('=', $arg);
  179. $opt_len = strlen($opt);
  180. for ($i = 0; $i < count($long_options); $i++) {
  181. $long_opt = $long_options[$i];
  182. $opt_start = substr($long_opt, 0, $opt_len);
  183. /* Option doesn't match. Go on to the next one. */
  184. if ($opt_start != $opt)
  185. continue;
  186. $opt_rest = substr($long_opt, $opt_len);
  187. /* Check that the options uniquely matches one of the allowed
  188. options. */
  189. if ($opt_rest != '' && $opt{0} != '=' &&
  190. $i + 1 < count($long_options) &&
  191. $opt == substr($long_options[$i+1], 0, $opt_len)) {
  192. return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
  193. }
  194. if (substr($long_opt, -1) == '=') {
  195. if (substr($long_opt, -2) != '==') {
  196. /* Long option requires an argument.
  197. Take the next argument if one wasn't specified. */;
  198. if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
  199. return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
  200. }
  201. }
  202. } else if ($opt_arg) {
  203. return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
  204. }
  205. $opts[] = array('--' . $opt, $opt_arg);
  206. return;
  207. }
  208. return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
  209. }
  210. /**
  211. * Safely read the $argv PHP array across different PHP configurations.
  212. * Will take care on register_globals and register_argc_argv ini directives
  213. *
  214. * @access public
  215. * @return mixed the $argv PHP array or PEAR error if not registered
  216. */
  217. function readPHPArgv()
  218. {
  219. global $argv;
  220. if (!is_array($argv)) {
  221. if (!@is_array($_SERVER['argv'])) {
  222. if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
  223. return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
  224. }
  225. return $GLOBALS['HTTP_SERVER_VARS']['argv'];
  226. }
  227. return $_SERVER['argv'];
  228. }
  229. return $argv;
  230. }
  231. }
  232. /**
  233. * Profiler adapted from Pear::APD's pprofp script. Not quite there yet, I need
  234. * to get this to accept a similar list of arguments as the script does,
  235. * and process them the same way. Also make sure that the file being loaded
  236. * is the right one. Also support multiple pids used in one page load (up to 4 so far).
  237. * Then output all this in a nicely formatted table.
  238. */
  239. class Profiler
  240. {
  241. var $stimes;
  242. var $utimes;
  243. var $calls;
  244. var $c_stimes;
  245. var $c_utimes;
  246. var $mem;
  247. /**
  248. * Concatenates all the pprof files generated by apd_set_pprof_trace()
  249. * and returns the resulting string, which can then be processed by
  250. * get_profiling();
  251. * It also deletes these files once finished, in order to limit
  252. * cluttering of the filesystem. This can be switched off by
  253. * providing "false" as the only argument to this function.
  254. *
  255. * WARNING: If you switch cleanup off, profiling data will
  256. * accumulate from one pageload to the next.
  257. *
  258. * @param boolean $cleanup Whether to delete pprof files or not.
  259. * @return String Profiling raw data
  260. */
  261. function _get_pprofp($cleanup = true)
  262. {
  263. global $CFG, $USER;
  264. // List all files under our temporary directory
  265. $tempdir = $CFG->dataroot . '/temp/profile/' . $USER->id;
  266. if ($files = scandir($tempdir)) {
  267. // Concatenate the files
  268. print_r($files);
  269. } else {
  270. print "Error: Profiler could not read the directory $tempdir.";
  271. return false;
  272. }
  273. // Return a handle to the resulting file
  274. if(($DATA = fopen($dataFile, "r")) == FALSE) {
  275. return "Failed to open $dataFile for reading\n";
  276. }
  277. return $handle;
  278. }
  279. /**
  280. * Returns profiling information gathered using APD functions.
  281. * Accepts a numerical array of command-line arguments.
  282. *
  283. * @usage Profiler::get_profiling($args)
  284. * Sort options
  285. * -a Sort by alphabetic names of subroutines.
  286. * -l Sort by number of calls to subroutines
  287. * -m Sort by memory used in a function call.
  288. * -r Sort by real time spent in subroutines.
  289. * -R Sort by real time spent in subroutines (inclusive of child calls).
  290. * -s Sort by system time spent in subroutines.
  291. * -S Sort by system time spent in subroutines (inclusive of child calls).
  292. * -u Sort by user time spent in subroutines.
  293. * -U Sort by user time spent in subroutines (inclusive of child calls).
  294. * -v Sort by average amount of time spent in subroutines.
  295. * -z Sort by user+system time spent in subroutines. (default)
  296. *
  297. * Display options
  298. * -c Display Real time elapsed alongside call tree.
  299. * -i Suppress reporting for php builtin functions
  300. * -O <cnt> Specifies maximum number of subroutines to display. (default 15)
  301. * -t Display compressed call tree.
  302. * -T Display uncompressed call tree.
  303. *
  304. * Example array: array('-a', '-l');
  305. *
  306. * @param Array $args
  307. * @return String Profiling info
  308. */
  309. function get_profiling($args)
  310. {
  311. $con = new Console_Getopt;
  312. array_shift($args);
  313. $shortoptions = 'acg:hiIlmMrRsStTuUO:vzZ';
  314. $retval = $con->getopt( $args, $shortoptions);
  315. if(is_object($retval)) {
  316. usage();
  317. }
  318. $opt['O'] = 20;
  319. foreach ($retval[0] as $kv_array) {
  320. $opt[$kv_array[0]] = $kv_array[1];
  321. }
  322. $DATA = Profiler::_get_pprofp();
  323. $cfg = array();
  324. $this->parse_info('HEADER', $DATA, $cfg);
  325. $callstack = array();
  326. $calls = array();
  327. $indent_cur = 0;
  328. $file_hash = array();
  329. $this->mem = array();
  330. $t_rtime = 0;
  331. $t_stime = 0;
  332. $t_utime = 0;
  333. $c_rtimes = array();
  334. $this->c_stimes = array();
  335. $this->c_utimes = array();
  336. $rtimes = array();
  337. $this->stimes = array();
  338. $this->utimes = array();
  339. $rtotal = 0;
  340. $stotal = 0;
  341. $utotal = 0;
  342. $last_memory = 0;
  343. $symbol_hash = array();
  344. $symbol_type = array();
  345. while($line = fgets($DATA)) {
  346. $line = rtrim($line);
  347. if(preg_match("/^END_TRACE/", $line)){
  348. break;
  349. }
  350. list($token, $data) = preg_split("/ /",$line, 2);
  351. if($token == '!') {
  352. list ($index, $file) = preg_split("/ /", $data, 2);
  353. $file_hash[$index] = $file;
  354. continue;
  355. }
  356. if( $token == '&') {
  357. list ($index, $name, $type) = preg_split("/ /", $data, 3);
  358. $symbol_hash[$index] = $name;
  359. $symbol_type[$index] = $type;
  360. continue;
  361. }
  362. if( $token == '+') {
  363. list($index, $file, $line) = preg_split("/ /",$data, 3);
  364. if(array_key_exists('i',$opt) && $symbol_type[$index] == 1) {
  365. continue;
  366. }
  367. $index_cur = $index;
  368. $calls[$index_cur]++;
  369. array_push($callstack, $index_cur);
  370. if(array_key_exists('T', $opt)) {
  371. if(array_key_exists('c', $opt)) {
  372. $retstring .= sprintf("%2.02f ", $rtotal/1000000);
  373. }
  374. $retstring .= str_repeat(" ", $indent_cur).$symbol_hash[$index_cur]."\n";
  375. if(array_key_exists('m', $opt)) {
  376. $retstring .= str_repeat(" ", $indent_cur)."C: $file_hash[$file]:$line M: $memory\n";
  377. }
  378. }
  379. elseif(array_key_exists('t', $opt)) {
  380. if ( $indent_last == $indent_cur && $index_last == $index_cur ) {
  381. $repcnt++;
  382. }
  383. else {
  384. if ( $repcnt ) {
  385. $repstr = ' ('.++$repcnt.'x)';
  386. }
  387. if(array_key_exists('c', $opt)) {
  388. $retstring .= sprintf("%2.02f ", $rtotal/1000000);
  389. }
  390. $retstring .= str_repeat(" ", $indent_last).$symbol_hash[$index_last].$repstr."\n";
  391. if(array_key_exists('m', $opt)) {
  392. $retstring .= str_repeat(" ", $indent_cur)."C: $file_hash[$file_last]:$line_last M: $memory\n";
  393. }
  394. $repstr = '';
  395. $repcnt = 0;
  396. $index_last = $index_cur;
  397. $indent_last = $indent_cur;
  398. $file_last = $file;
  399. $line_last = $line;
  400. }
  401. }
  402. $indent_cur++;
  403. continue;
  404. }
  405. if( $token == '@') {
  406. list($file_no, $line_no, $ut, $st, $rt) = preg_split("/ /", $data);
  407. $top = array_pop($callstack);
  408. $this->utimes[$top] += $ut;
  409. $utotal += $ut;
  410. $this->stimes[$top] += $st;
  411. $stotal += $st;
  412. $rtimes[$top] += $rt;
  413. $rtotal += $rt;
  414. array_push($callstack, $top);
  415. foreach ($callstack as $stack_element) {
  416. $this->c_utimes[$stack_element] += $ut;
  417. $this->c_stimes[$stack_element] += $st;
  418. $c_rtimes[$stack_element] += $rt;
  419. }
  420. continue;
  421. }
  422. if ($token == '-') {
  423. list ($index, $memory) = preg_split("/ /", $data, 2);
  424. if(array_key_exists('i',$opt) && $symbol_type[$index] == 1)
  425. {
  426. continue;
  427. }
  428. $this->mem[$index] += ($memory - $last_memory);
  429. $last_memory = $memory;
  430. $indent_cur--;
  431. $tmp = array_pop($callstack);
  432. continue;
  433. }
  434. }
  435. $this->parse_info('FOOTER', $DATA, $cfg);
  436. $sort = 'by_time';
  437. if(array_key_exists('l', $opt)) { $sort = 'by_calls'; }
  438. if(array_key_exists('m', $opt)) { $sort = 'by_mem'; }
  439. if(array_key_exists('a', $opt)) { $sort = 'by_name'; }
  440. if(array_key_exists('v', $opt)) { $sort = 'by_avgcpu'; }
  441. if(array_key_exists('r', $opt)) { $sort = 'by_rtime'; }
  442. if(array_key_exists('R', $opt)) { $sort = 'by_c_rtime'; }
  443. if(array_key_exists('s', $opt)) { $sort = 'by_stime'; }
  444. if(array_key_exists('S', $opt)) { $sort = 'by_c_stime'; }
  445. if(array_key_exists('u', $opt)) { $sort = 'by_utime'; }
  446. if(array_key_exists('U', $opt)) { $sort = 'by_c_utime'; }
  447. if(array_key_exists('Z', $opt)) { $sort = 'by_c_time'; }
  448. if( !count($symbol_hash)) {
  449. continue;
  450. }
  451. $retstring .= sprintf("
  452. Trace for %s
  453. Total Elapsed Time = %4.2f
  454. Total System Time = %4.2f
  455. Total User Time = %4.2f
  456. ", $cfg['caller'], $rtotal/1000000, $stotal/1000000, $utotal/1000000);
  457. $retstring .= "\n
  458. Real User System secs/ cumm
  459. %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name
  460. --------------------------------------------------------------------------------------\n";
  461. $l = 0;
  462. $itotal = 0;
  463. $percall = 0;
  464. $cpercall = 0;
  465. uksort($symbol_hash, $sort);
  466. foreach (array_keys($symbol_hash) as $j) {
  467. if(array_key_exists('i', $opt) && $symbol_type[$j] == 1) {
  468. continue;
  469. }
  470. if ($l++ < $opt['O']) {
  471. $pcnt = 100*($this->stimes[$j] + $this->utimes[$j])/($utotal + $stotal + $itotal);
  472. $c_pcnt = 100* ($this->c_stimes[$j] + $this->c_utimes[$j])/($utotal + $stotal + $itotal);
  473. $rsecs = $rtimes[$j]/1000000;
  474. $ssecs = $this->stimes[$j]/1000000;
  475. $usecs = $this->utimes[$j]/1000000;
  476. $c_rsecs = $c_rtimes[$j]/1000000;
  477. $c_ssecs = $this->c_stimes[$j]/1000000;
  478. $c_usecs = $this->c_utimes[$j]/1000000;
  479. $ncalls = $calls[$j];
  480. if(array_key_exists('z', $opt)) {
  481. $percall = ($usecs + $ssecs)/$ncalls;
  482. $cpercall = ($c_usecs + $c_ssecs)/$ncalls;
  483. if($utotal + $stotal) {
  484. $pcnt = 100*($this->stimes[$j] + $this->utimes[$j])/($utotal + $stotal);
  485. }
  486. else {
  487. $pcnt = 100;
  488. }
  489. }
  490. if(array_key_exists('Z', $opt)) {
  491. $percall = ($usecs + $ssecs)/$ncalls;
  492. $cpercall = ($c_usecs + $c_ssecs)/$ncalls;
  493. if($utotal + $stotal) {
  494. $pcnt = 100*($this->c_stimes[$j] + $this->c_utimes[$j])/($utotal + $stotal);
  495. }
  496. else {
  497. $pcnt = 100;
  498. }
  499. }
  500. if(array_key_exists('r', $opt)) {
  501. $percall = ($rsecs)/$ncalls;
  502. $cpercall = ($c_rsecs)/$ncalls;
  503. if($rtotal) {
  504. $pcnt = 100*$rtimes[$j]/$rtotal;
  505. }
  506. else {
  507. $pcnt = 100;
  508. }
  509. }
  510. if(array_key_exists('R', $opt)) {
  511. $percall = ($rsecs)/$ncalls;
  512. $cpercall = ($c_rsecs)/$ncalls;
  513. if($rtotal) {
  514. $pcnt = 100*$c_rtimes[$j]/$rtotal;
  515. }
  516. else {
  517. $pcnt = 100;
  518. }
  519. }
  520. if(array_key_exists('u', $opt)) {
  521. $percall = ($usecs)/$ncalls;
  522. $cpercall = ($c_usecs)/$ncalls;
  523. if($utotal) {
  524. $pcnt = 100*$this->utimes[$j]/$utotal;
  525. }
  526. else {
  527. $pcnt = 100;
  528. }
  529. }
  530. if(array_key_exists('U', $opt)) {
  531. $percall = ($usecs)/$ncalls;
  532. $cpercall = ($c_usecs)/$ncalls;
  533. if($utotal) {
  534. $pcnt = 100*$this->c_utimes[$j]/$utotal;
  535. }
  536. else {
  537. $pcnt = 100;
  538. }
  539. }
  540. if(array_key_exists('s', $opt)) {
  541. $percall = ($ssecs)/$ncalls;
  542. $cpercall = ($c_ssecs)/$ncalls;
  543. if($stotal) {
  544. $pcnt = 100*$this->stimes[$j]/$stotal;
  545. }
  546. else {
  547. $pcnt = 100;
  548. }
  549. }
  550. if(array_key_exists('S', $opt)) {
  551. $percall = ($ssecs)/$ncalls;
  552. $cpercall = ($c_ssecs)/$ncalls;
  553. if($stotal) {
  554. $pcnt = 100*$this->c_stimes[$j]/$stotal;
  555. }
  556. else {
  557. $pcnt = 100;
  558. }
  559. }
  560. // $cpercall = ($c_usecs + $c_ssecs)/$ncalls;
  561. $mem_usage = $this->mem[$j];
  562. $name = $symbol_hash[$j];
  563. $retstring .= sprintf("%3.01f %2.02f %2.02f %2.02f %2.02f %2.02f %2.02f %4d %2.04f %2.04f %12d %s\n",
  564. $pcnt, $rsecs, $c_rsecs, $usecs, $c_usecs, $ssecs, $c_ssecs, $ncalls, $percall, $cpercall, $mem_usage, $name);
  565. return $retstring;
  566. }
  567. }
  568. return $retstring;
  569. }
  570. function usage() {
  571. return <<<EOD
  572. Profiler::get_profiling(\$args)
  573. Sort options
  574. -a Sort by alphabetic names of subroutines.
  575. -l Sort by number of calls to subroutines
  576. -m Sort by memory used in a function call.
  577. -r Sort by real time spent in subroutines.
  578. -R Sort by real time spent in subroutines (inclusive of child calls).
  579. -s Sort by system time spent in subroutines.
  580. -S Sort by system time spent in subroutines (inclusive of child calls).
  581. -u Sort by user time spent in subroutines.
  582. -U Sort by user time spent in subroutines (inclusive of child calls).
  583. -v Sort by average amount of time spent in subroutines.
  584. -z Sort by user+system time spent in subroutines. (default)
  585. Display options
  586. -c Display Real time elapsed alongside call tree.
  587. -i Suppress reporting for php builtin functions
  588. -O <cnt> Specifies maximum number of subroutines to display. (default 15)
  589. -t Display compressed call tree.
  590. -T Display uncompressed call tree.
  591. EOD;
  592. exit(1);
  593. }
  594. function parse_info($tag, $datasource, &$cfg) {
  595. while($line = fgets($datasource)) {
  596. $line = rtrim($line);
  597. if(preg_match("/^END_$tag$/", $line)) {
  598. break;
  599. }
  600. if(preg_match("/(\w+)=(.*)/", $line, $matches)) {
  601. $cfg[$matches[1]] = $matches[2];
  602. }
  603. }
  604. }
  605. function num_cmp($a, $b) {
  606. if (intval($a) > intval($b)) { return 1;}
  607. elseif(intval($a) < intval($b)) { return -1;}
  608. else {return 0;}
  609. }
  610. function by_time($a,$b) {
  611. return $this->num_cmp(($this->stimes[$b] + $this->utimes[$b]),($this->stimes[$a] + $this->utimes[$a]));
  612. }
  613. function by_c_time($a,$b) {
  614. return $this->num_cmp(($this->c_stimes[$b] + $this->c_utimes[$b]),($this->c_stimes[$a] + $this->c_utimes[$a]));
  615. }
  616. function by_avgcpu($a,$b) {
  617. return $this->num_cmp(($this->stimes[$b] + $this->utimes[$b])/$this->calls[$b],($this->stimes[$a] + $this->utimes[$a])/$this->calls[$a]);
  618. }
  619. function by_calls($a, $b) {
  620. return $this->num_cmp($this->calls[$b], $this->calls[$a]);
  621. }
  622. function by_rtime($a,$b) {
  623. return $this->num_cmp($this->rtimes[$b], $this->rtimes[$a]);
  624. }
  625. function by_c_rtime($a,$b) {
  626. return $this->num_cmp($this->c_rtimes[$b], $this->c_rtimes[$a]);
  627. }
  628. function by_stime($a,$b) {
  629. return $this->num_cmp($this->stimes[$b], $this->stimes[$a]);
  630. }
  631. function by_c_stime($a,$b) {
  632. return $this->num_cmp($this->c_stimes[$b], $this->c_stimes[$a]);
  633. }
  634. function by_utime($a,$b) {
  635. return $this->num_cmp($this->utimes[$b], $this->utimes[$a]);
  636. }
  637. function by_c_utime($a,$b) {
  638. return $this->num_cmp($this->c_utimes[$b], $this->c_utimes[$a]);
  639. }
  640. function by_mem($a, $b) {
  641. return $this->num_cmp($this->mem[$b], $this->mem[$a]);
  642. }
  643. }
  644. ?>