summaryrefslogtreecommitdiffstats
path: root/storage/innobase/include/mariadb_stats.h
blob: e9051c0c08b0d6165db398f25b63661dd55b3e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*****************************************************************************

Copyright (c) 2023, MariaDB Foundation

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA

*****************************************************************************/

#ifndef mariadb_stats_h
#define mariadb_stats_h

/* Include file to handle mariadbd handler specific stats */

#include "ha_handler_stats.h"
#include "my_rdtsc.h"

/* Not active threads are ponting to this structure */
extern thread_local ha_handler_stats mariadb_dummy_stats;

/* Points to either THD->handler_stats or mariad_dummy_stats */
extern thread_local ha_handler_stats *mariadb_stats;

/*
  Returns 1 if MariaDB wants engine status
*/

inline bool mariadb_stats_active()
{
  return mariadb_stats->active != 0;
}

inline bool mariadb_stats_active(ha_handler_stats *stats)
{
  return stats->active != 0;
}

/* The following functions increment different engine status */

inline void mariadb_increment_pages_accessed()
{
  mariadb_stats->pages_accessed++;
}

inline void mariadb_increment_pages_updated(ulonglong count)
{
  mariadb_stats->pages_updated+= count;
}

inline void mariadb_increment_pages_read()
{
  mariadb_stats->pages_read_count++;
}

inline void mariadb_increment_undo_records_read()
{
  mariadb_stats->undo_records_read++;
}

/*
  The following has to be identical code as measure() in sql_analyze_stmt.h

  One should only call this if mariadb_stats_active() is true.
*/

inline ulonglong mariadb_measure()
{
#if (MY_TIMER_ROUTINE_CYCLES)
    return my_timer_cycles();
#else
    return my_timer_microseconds();
#endif
}

/*
  Call this only of start_time != 0
  See buf0rea.cc for an example of how to use it efficiently
*/

inline void mariadb_increment_pages_read_time(ulonglong start_time)
{
  ha_handler_stats *stats= mariadb_stats;
  ulonglong end_time= mariadb_measure();
  /* Check that we only call this if active, see example! */
  DBUG_ASSERT(start_time);
  DBUG_ASSERT(mariadb_stats_active(stats));

  stats->pages_read_time+= (end_time - start_time);
}


/*
  Helper class to set mariadb_stats temporarly for one call in handler.cc
*/

class mariadb_set_stats
{
public:
  uint flag;
  mariadb_set_stats(ha_handler_stats *stats)
  {
    mariadb_stats= stats ? stats : &mariadb_dummy_stats;
  }
  ~mariadb_set_stats()
  {
    mariadb_stats= &mariadb_dummy_stats;
  }
};

#endif /* mariadb_stats_h */