]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarXHprof/xhprof_lib/display/typeahead_common.php
Release 6.5.10
[Github/sugarcrm.git] / include / SugarXHprof / xhprof_lib / display / typeahead_common.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 //  Copyright (c) 2009 Facebook
4 //
5 //  Licensed under the Apache License, Version 2.0 (the "License");
6 //  you may not use this file except in compliance with the License.
7 //  You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 //  Unless required by applicable law or agreed to in writing, software
12 //  distributed under the License is distributed on an "AS IS" BASIS,
13 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 //  See the License for the specific language governing permissions and
15 //  limitations under the License.
16 //
17
18 /**
19  * AJAX endpoint for XHProf function name typeahead is implemented
20  * as a thin wrapper around this file. The wrapper must set up
21  * the global $xhprof_runs_impl to correspond to an object that
22  * implements the iXHProfRuns interface.
23  *
24  * @author(s)  Kannan Muthukkaruppan
25  *             Changhao Jiang
26  */
27
28
29 require_once $GLOBALS['XHPROF_LIB_ROOT'].'/utils/xhprof_lib.php';
30
31 // param name, its type, and default value
32 $params = array('q'          => array(XHPROF_STRING_PARAM, ''),
33                 'run'        => array(XHPROF_STRING_PARAM, ''),
34                 'run1'       => array(XHPROF_STRING_PARAM, ''),
35                 'run2'       => array(XHPROF_STRING_PARAM, ''),
36                 'source'     => array(XHPROF_STRING_PARAM, 'xhprof'),
37                 );
38
39 // pull values of these params, and create named globals for each param
40 xhprof_param_init($params);
41
42 if (!empty($run)) {
43
44   // single run mode
45   $raw_data = $xhprof_runs_impl->get_run($run, $source, $desc_unused);
46   $functions = xhprof_get_matching_functions($q, $raw_data);
47
48 } else if (!empty($run1) && !empty($run2)) {
49
50   // diff mode
51   $raw_data = $xhprof_runs_impl->get_run($run1, $source, $desc_unused);
52   $functions1 = xhprof_get_matching_functions($q, $raw_data);
53
54   $raw_data = $xhprof_runs_impl->get_run($run2, $source, $desc_unused);
55   $functions2 = xhprof_get_matching_functions($q, $raw_data);
56
57
58   $functions = array_unique(array_merge($functions1, $functions2));
59   asort($functions);
60 } else {
61   xhprof_error("no valid runs specified to typeahead endpoint");
62   $functions = array();
63 }
64
65 // If exact match is present move it to the front
66 if (in_array($q, $functions)) {
67   $old_functions = $functions;
68
69   $functions = array($q);
70   foreach ($old_functions as $f) {
71     // exact match case has already been added to the front
72     if ($f != $q) {
73       $functions[] = $f;
74     }
75   }
76 }
77
78 foreach ($functions as $f) {
79   echo $f."\n";
80 }
81