1 /* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 22 23 #ifndef PFS_HOST_H 24 #define PFS_HOST_H 25 26 /** 27 @file storage/perfschema/pfs_host.h 28 Performance schema host (declarations). 29 */ 30 31 #include "pfs_lock.h" 32 #include "lf.h" 33 #include "pfs_con_slice.h" 34 35 struct PFS_global_param; 36 struct PFS_thread; 37 38 /** 39 @addtogroup Performance_schema_buffers 40 @{ 41 */ 42 43 struct PFS_host_key 44 { 45 /** 46 Hash search key. 47 This has to be a string for LF_HASH, 48 the format is "<hostname><0x00>" 49 */ 50 char m_hash_key[HOSTNAME_LENGTH + 1]; 51 uint m_key_length; 52 }; 53 54 struct PFS_ALIGNED PFS_host : PFS_connection_slice 55 { 56 public: init_refcountPFS_host57 inline void init_refcount(void) 58 { 59 PFS_atomic::store_32(& m_refcount, 1); 60 } 61 get_refcountPFS_host62 inline int get_refcount(void) 63 { 64 return PFS_atomic::load_32(& m_refcount); 65 } 66 inc_refcountPFS_host67 inline void inc_refcount(void) 68 { 69 PFS_atomic::add_32(& m_refcount, 1); 70 } 71 dec_refcountPFS_host72 inline void dec_refcount(void) 73 { 74 PFS_atomic::add_32(& m_refcount, -1); 75 } 76 77 void aggregate(void); 78 void aggregate_waits(void); 79 void aggregate_stages(void); 80 void aggregate_statements(void); 81 void aggregate_stats(void); 82 void release(void); 83 84 /* Internal lock. */ 85 pfs_lock m_lock; 86 PFS_host_key m_key; 87 const char *m_hostname; 88 uint m_hostname_length; 89 90 ulonglong m_disconnected_count; 91 92 private: 93 int m_refcount; 94 }; 95 96 int init_host(const PFS_global_param *param); 97 void cleanup_host(void); 98 int init_host_hash(void); 99 void cleanup_host_hash(void); 100 101 PFS_host *find_or_create_host(PFS_thread *thread, 102 const char *hostname, uint hostname_length); 103 104 PFS_host *sanitize_host(PFS_host *unsafe); 105 void purge_all_host(void); 106 107 /* For iterators and show status. */ 108 109 extern ulong host_max; 110 extern ulong host_lost; 111 112 /* Exposing the data directly, for iterators. */ 113 114 extern PFS_host *host_array; 115 116 extern LF_HASH host_hash; 117 118 /** @} */ 119 #endif 120 121