You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.6 KiB

4 years ago
  1. #if MYSQL_6_9
  2. // Copyright � 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using System;
  24. using System.Diagnostics;
  25. using Externals.MySql.Data.MySqlClient.Properties;
  26. namespace Externals.MySql.Data.MySqlClient
  27. {
  28. internal class SystemPerformanceMonitor : PerformanceMonitor
  29. {
  30. private static PerformanceCounter procedureHardQueries;
  31. private static PerformanceCounter procedureSoftQueries;
  32. public SystemPerformanceMonitor(MySqlConnection connection) : base(connection)
  33. {
  34. string categoryName = Resources.PerfMonCategoryName;
  35. if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null)
  36. {
  37. try
  38. {
  39. procedureHardQueries = new PerformanceCounter(categoryName,
  40. "HardProcedureQueries", false);
  41. procedureSoftQueries = new PerformanceCounter(categoryName,
  42. "SoftProcedureQueries", false);
  43. }
  44. catch (Exception ex)
  45. {
  46. MySqlTrace.LogError(connection.ServerThread, ex.Message);
  47. }
  48. }
  49. }
  50. #if DEBUG
  51. private void EnsurePerfCategoryExist()
  52. {
  53. CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
  54. CounterCreationData ccd = new CounterCreationData();
  55. ccd.CounterType = PerformanceCounterType.NumberOfItems32;
  56. ccd.CounterName = "HardProcedureQueries";
  57. ccdc.Add(ccd);
  58. ccd = new CounterCreationData();
  59. ccd.CounterType = PerformanceCounterType.NumberOfItems32;
  60. ccd.CounterName = "SoftProcedureQueries";
  61. ccdc.Add(ccd);
  62. if (!PerformanceCounterCategory.Exists(Resources.PerfMonCategoryName))
  63. {
  64. PerformanceCounterCategory.Create(Resources.PerfMonCategoryName, null, PerformanceCounterCategoryType.MultiInstance, ccdc);
  65. }
  66. }
  67. #endif
  68. public override void AddHardProcedureQuery()
  69. {
  70. if (!Connection.Settings.UsePerformanceMonitor ||
  71. procedureHardQueries == null) return;
  72. procedureHardQueries.Increment();
  73. }
  74. public override void AddSoftProcedureQuery()
  75. {
  76. if (!Connection.Settings.UsePerformanceMonitor ||
  77. procedureSoftQueries == null) return;
  78. procedureSoftQueries.Increment();
  79. }
  80. }
  81. }
  82. #endif