The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

102 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. namespace
  20. {
  21. struct PortIOStats
  22. {
  23. PortIOStats (const char* nm) : name (nm) {}
  24. const char* const name;
  25. int byteCount = 0;
  26. int messageCount = 0;
  27. int bytesPerSec = 0;
  28. int largestMessageBytes = 0;
  29. int lastMessageBytes = 0;
  30. void update (double elapsedSec)
  31. {
  32. if (byteCount > 0)
  33. {
  34. bytesPerSec = (int) (byteCount / elapsedSec);
  35. byteCount = 0;
  36. juce::Logger::writeToLog (getString());
  37. }
  38. }
  39. juce::String getString() const
  40. {
  41. return juce::String (name) + ": "
  42. + "count=" + juce::String (messageCount).paddedRight (' ', 7)
  43. + "rate=" + (juce::String (bytesPerSec / 1024.0f, 1) + " Kb/sec").paddedRight (' ', 11)
  44. + "largest=" + (juce::String (largestMessageBytes) + " bytes").paddedRight (' ', 11)
  45. + "last=" + (juce::String (lastMessageBytes) + " bytes").paddedRight (' ', 11);
  46. }
  47. void registerMessage (int numBytes) noexcept
  48. {
  49. byteCount += numBytes;
  50. ++messageCount;
  51. lastMessageBytes = numBytes;
  52. largestMessageBytes = juce::jmax (largestMessageBytes, numBytes);
  53. }
  54. };
  55. static PortIOStats inputStats { "Input" }, outputStats { "Output" };
  56. static uint32 startTime = 0;
  57. static inline void resetOnSecondBoundary()
  58. {
  59. auto now = juce::Time::getMillisecondCounter();
  60. double elapsedSec = (now - startTime) / 1000.0;
  61. if (elapsedSec >= 1.0)
  62. {
  63. inputStats.update (elapsedSec);
  64. outputStats.update (elapsedSec);
  65. startTime = now;
  66. }
  67. }
  68. static inline void registerBytesOut (int numBytes)
  69. {
  70. outputStats.registerMessage (numBytes);
  71. resetOnSecondBoundary();
  72. }
  73. static inline void registerBytesIn (int numBytes)
  74. {
  75. inputStats.registerMessage (numBytes);
  76. resetOnSecondBoundary();
  77. }
  78. }
  79. juce::String getMidiIOStats()
  80. {
  81. return inputStats.getString() + " " + outputStats.getString();
  82. }
  83. } // namespace juce