Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Profiler Class Reference
Inheritance diagram for Profiler:
Profiler Zend_Db_Profiler

Public Member Functions

 queryStart ($queryText, $queryType=null)
 
- Public Member Functions inherited from Profiler
 setHost ($host)
 
 setType ($type)
 
 queryStart ($queryText, $queryType=null)
 
 queryEnd ($queryId)
 
 queryEndLast ()
 
- Public Member Functions inherited from Zend_Db_Profiler
 __construct ($enabled=false)
 
 setEnabled ($enable)
 
 getEnabled ()
 
 setFilterElapsedSecs ($minimumSeconds=null)
 
 getFilterElapsedSecs ()
 
 setFilterQueryType ($queryTypes=null)
 
 getFilterQueryType ()
 
 clear ()
 
 queryClone (Zend_Db_Profiler_Query $query)
 
 queryStart ($queryText, $queryType=null)
 
 queryEnd ($queryId)
 
 getQueryProfile ($queryId)
 
 getQueryProfiles ($queryType=null, $showUnfinished=false)
 
 getTotalElapsedSecs ($queryType=null)
 
 getTotalNumQueries ($queryType=null)
 
 getLastQueryProfile ()
 

Data Fields

const TIMER_PREFIX = 'DB_QUERY'
 
const DEFAULT_CONNECTION_TYPE = 'database'
 
- Data Fields inherited from Zend_Db_Profiler
const CONNECT = 1
 
const QUERY = 2
 
const INSERT = 4
 
const UPDATE = 8
 
const DELETE = 16
 
const SELECT = 32
 
const TRANSACTION = 64
 
const STORED = 'stored'
 
const IGNORED = 'ignored'
 

Protected Member Functions

 _getTimerName ($operation)
 
 _parseQueryType ($queryText)
 

Protected Attributes

 $_queryTypes = ['select', 'insert', 'update', 'delete']
 
- Protected Attributes inherited from Profiler
 $_host = ''
 
 $_type = ''
 
- Protected Attributes inherited from Zend_Db_Profiler
 $_queryProfiles = array()
 
 $_enabled = false
 
 $_filterElapsedSecs = null
 
 $_filterTypes = null
 

Detailed Description

Definition at line 10 of file Profiler.php.

Member Function Documentation

◆ _getTimerName()

_getTimerName (   $operation)
protected

Form and return timer name

Parameters
string$operation
Returns
string

Definition at line 33 of file Profiler.php.

34  {
35  // default name of connection type
37 
38  // connection type to database
39  if (!empty($this->_type)) {
40  $timerName = $this->_type;
41  }
42 
43  // sql operation
44  $timerName .= '_' . $operation;
45 
46  // database host
47  if (!empty($this->_host)) {
48  $timerName .= '_' . $this->_host;
49  }
50 
51  return \Magento\Framework\Model\ResourceModel\Db\Profiler::TIMER_PREFIX . ':' . $timerName;
52  }

◆ _parseQueryType()

_parseQueryType (   $queryText)
protected

Parse query type and return

Parameters
string$queryText
Returns
string

Definition at line 60 of file Profiler.php.

61  {
62  $queryTypeParsed = strtolower(substr(ltrim($queryText), 0, 6));
63 
64  if (!in_array($queryTypeParsed, $this->_queryTypes)) {
65  $queryTypeParsed = 'query';
66  }
67 
68  return $queryTypeParsed;
69  }

◆ queryStart()

queryStart (   $queryText,
  $queryType = null 
)

Starts a query. Creates a new query profile object (\Zend_Db_Profiler_Query)

Parameters
string$queryTextSQL statement
integer$queryTypeOPTIONAL Type of query, one of the \Zend_Db_Profiler::* constants
Returns
integer|null

Definition at line 78 of file Profiler.php.

79  {
80  $result = parent::queryStart($queryText, $queryType);
81 
82  if ($result !== null) {
83  $queryTypeParsed = $this->_parseQueryType($queryText);
84  $timerName = $this->_getTimerName($queryTypeParsed);
85 
86  $tags = [];
87 
88  // connection type to database
89  $typePrefix = '';
90  if ($this->_type) {
91  $tags['group'] = $this->_type;
92  $typePrefix = $this->_type . ':';
93  }
94 
95  // sql operation
96  $tags['operation'] = $typePrefix . $queryTypeParsed;
97 
98  // database host
99  if ($this->_host) {
100  $tags['host'] = $this->_host;
101  }
102 
103  \Magento\Framework\Profiler::start($timerName, $tags);
104  }
105 
106  return $result;
107  }

Field Documentation

◆ $_queryTypes

$_queryTypes = ['select', 'insert', 'update', 'delete']
protected

Definition at line 25 of file Profiler.php.

◆ DEFAULT_CONNECTION_TYPE

const DEFAULT_CONNECTION_TYPE = 'database'

Default connection type for timer name creation

Definition at line 20 of file Profiler.php.

◆ TIMER_PREFIX

const TIMER_PREFIX = 'DB_QUERY'

Default connection type for timer name creation

Definition at line 15 of file Profiler.php.


The documentation for this class was generated from the following file: