praat_statistics.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* praat_statistics.cpp
  2. *
  3. * Copyright (C) 1992-2012,2014-2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <time.h>
  19. #include <locale.h>
  20. #include <thread>
  21. #include "praatP.h"
  22. static struct {
  23. integer batchSessions, interactiveSessions;
  24. double memory;
  25. char32 dateOfFirstSession [Preferences_STRING_BUFFER_SIZE];
  26. } statistics;
  27. void praat_statistics_prefs () {
  28. Preferences_addInteger (U"PraatShell.batchSessions", & statistics.batchSessions, 0);
  29. Preferences_addInteger (U"PraatShell.interactiveSessions", & statistics.interactiveSessions, 0);
  30. Preferences_addDouble (U"PraatShell.memory", & statistics.memory, 0.0);
  31. Preferences_addString (U"PraatShell.dateOfFirstSession", & statistics.dateOfFirstSession [0], U"");
  32. }
  33. void praat_statistics_prefsChanged () {
  34. if (! statistics.dateOfFirstSession [0]) {
  35. time_t today = time (nullptr);
  36. char32 *newLine;
  37. str32cpy (statistics.dateOfFirstSession, Melder_peek8to32 (ctime (& today)));
  38. newLine = str32chr (statistics.dateOfFirstSession, U'\n');
  39. if (newLine) *newLine = '\0';
  40. }
  41. if (theCurrentPraatApplication -> batch)
  42. statistics.batchSessions += 1;
  43. else
  44. statistics.interactiveSessions += 1;
  45. }
  46. void praat_statistics_exit () {
  47. statistics.memory += Melder_allocationSize ();
  48. }
  49. /*@praat
  50. report$ = Report integer properties
  51. sizeOfInteger = extractNumber (report$, "An indexing integer is ")
  52. sizeOfPointer = extractNumber (report$, "A pointer is ")
  53. assert sizeOfInteger = sizeOfPointer
  54. sizeOfFileOffset = extractNumber (report$, "A file offset is ")
  55. assert sizeOfFileOffset = 64
  56. @*/
  57. void praat_reportIntegerProperties () {
  58. MelderInfo_open ();
  59. MelderInfo_writeLine (U"Integer properties of this edition of Praat on this computer:\n");
  60. MelderInfo_writeLine (U"A boolean is ", sizeof (bool) * 8, U" bits.");
  61. MelderInfo_writeLine (U"A \"short integer\" is ", sizeof (short) * 8, U" bits.");
  62. MelderInfo_writeLine (U"An \"integer\" is ", sizeof (int) * 8, U" bits.");
  63. MelderInfo_writeLine (U"A \"long integer\" is ", sizeof (long) * 8, U" bits.");
  64. MelderInfo_writeLine (U"A \"long long integer\" is ", sizeof (long long) * 8, U" bits.");
  65. MelderInfo_writeLine (U"An indexing integer is ", sizeof (integer) * 8, U" bits.");
  66. MelderInfo_writeLine (U"A pointer is ", sizeof (void *) * 8, U" bits.");
  67. MelderInfo_writeLine (U"A memory object size is ", sizeof (size_t) * 8, U" bits.");
  68. MelderInfo_writeLine (U"A file offset is ", sizeof (off_t) * 8, U" bits.");
  69. MelderInfo_close ();
  70. }
  71. void praat_reportTextProperties () {
  72. MelderInfo_open ();
  73. MelderInfo_writeLine (U"Text properties of this edition of Praat on this computer:\n");
  74. MelderInfo_writeLine (U"Locale: ", Melder_peek8to32 (setlocale (LC_ALL, nullptr)));
  75. MelderInfo_writeLine (U"A \"char\" is ", 8, U" bits.");
  76. MelderInfo_writeLine (U"A \"char16_t\" is ", sizeof (char16_t) * 8, U" bits.");
  77. MelderInfo_writeLine (U"A \"wchar_t\" is ", sizeof (wchar_t) * 8, U" bits.");
  78. MelderInfo_writeLine (U"A \"char32_t\" is ", sizeof (char32_t) * 8, U" bits.");
  79. MelderInfo_close ();
  80. }
  81. void praat_reportSystemProperties () {
  82. #define xstr(s) str(s)
  83. #define str(s) #s
  84. MelderInfo_open ();
  85. MelderInfo_writeLine (U"System properties of this edition of Praat on this computer:\n");
  86. #ifdef _WIN32
  87. MelderInfo_writeLine (U"_WIN32 is \"" xstr (_WIN32) "\".");
  88. #endif
  89. #ifdef WINVER
  90. MelderInfo_writeLine (U"WINVER is \"" xstr (WINVER) "\".");
  91. #endif
  92. #ifdef _WIN32_WINNT
  93. MelderInfo_writeLine (U"_WIN32_WINNT is \"" xstr (_WIN32_WINNT) "\".");
  94. #endif
  95. #ifdef _WIN32_IE
  96. MelderInfo_writeLine (U"_WIN32_IE is \"" xstr (_WIN32_IE) "\".");
  97. #endif
  98. #ifdef UNICODE
  99. MelderInfo_writeLine (U"UNICODE is \"" xstr (UNICODE) "\".");
  100. #endif
  101. #ifdef _FILE_OFFSET_BITS
  102. MelderInfo_writeLine (U"_FILE_OFFSET_BITS is \"" xstr (_FILE_OFFSET_BITS) "\".");
  103. #endif
  104. #ifdef macintosh
  105. MelderInfo_writeLine (U"macintosh is \"" xstr (macintosh) "\".");
  106. #endif
  107. #ifdef linux
  108. MelderInfo_writeLine (U"linux is \"" xstr (linux) "\".");
  109. #endif
  110. MelderInfo_writeLine (U"The number of processors is ", std::thread::hardware_concurrency(), U".");
  111. #ifdef macintosh
  112. MelderInfo_writeLine (U"system version is ", Melder_systemVersion, U".");
  113. #endif
  114. MelderInfo_close ();
  115. }
  116. void praat_reportGraphicalProperties () {
  117. MelderInfo_open ();
  118. MelderInfo_writeLine (U"Graphical properties of this edition of Praat on this computer:\n");
  119. double x, y, width, height;
  120. Gui_getWindowPositioningBounds (& x, & y, & width, & height);
  121. MelderInfo_writeLine (U"Window positioning area: x = ", x, U", y = ", y,
  122. U", width = ", width, U", height = ", height);
  123. #if defined (macintosh)
  124. CGDirectDisplayID screen = CGMainDisplayID ();
  125. CGSize screenSize_mm = CGDisplayScreenSize (screen);
  126. double diagonal_mm = sqrt (screenSize_mm. width * screenSize_mm. width + screenSize_mm. height * screenSize_mm. height);
  127. double diagonal_inch = diagonal_mm / 25.4;
  128. MelderInfo_writeLine (U"\nScreen size: ", screenSize_mm. width, U" x ", screenSize_mm. height,
  129. U" mm (diagonal ", Melder_fixed (diagonal_mm, 1), U" mm = ", Melder_fixed (diagonal_inch, 1), U" inch)");
  130. size_t screenWidth_pixels = CGDisplayPixelsWide (screen);
  131. size_t screenHeight_pixels = CGDisplayPixelsHigh (screen);
  132. MelderInfo_writeLine (U"Screen \"resolution\": ", screenWidth_pixels, U" x ", screenHeight_pixels, U" pixels");
  133. double resolution = 25.4 * screenWidth_pixels / screenSize_mm. width;
  134. MelderInfo_writeLine (U"Screen resolution: ", Melder_fixed (resolution, 1), U" pixels/inch");
  135. #elif defined (_WIN32)
  136. /*for (int i = 0; i <= 88; i ++)
  137. MelderInfo_writeLine (U"System metric ", i, U": ", GetSystemMetrics (i));*/
  138. #endif
  139. MelderInfo_close ();
  140. }
  141. void praat_reportMemoryUse () {
  142. MelderInfo_open ();
  143. MelderInfo_writeLine (U"Memory use by Praat:\n");
  144. MelderInfo_writeLine (U"Currently in use:\n"
  145. U" Strings: ", MelderString_allocationCount () - MelderString_deallocationCount ());
  146. MelderInfo_writeLine (U" Arrays: ", NUM_getTotalNumberOfArrays ());
  147. MelderInfo_writeLine (U" Things: ", theTotalNumberOfThings,
  148. U" (objects in list: ", theCurrentPraatObjects -> n, U")");
  149. integer numberOfMotifWidgets =
  150. #if motif
  151. Gui_getNumberOfMotifWidgets ();
  152. MelderInfo_writeLine (U" Motif widgets: ", numberOfMotifWidgets);
  153. #else
  154. 0;
  155. #endif
  156. MelderInfo_writeLine (U" Other: ",
  157. Melder_allocationCount () - Melder_deallocationCount ()
  158. - theTotalNumberOfThings - NUM_getTotalNumberOfArrays ()
  159. - (MelderString_allocationCount () - MelderString_deallocationCount ())
  160. - numberOfMotifWidgets);
  161. MelderInfo_writeLine (
  162. U"\nMemory history of this session:\n"
  163. U" Total created: ", Melder_bigInteger (Melder_allocationCount ()), U" (", Melder_bigInteger (Melder_allocationSize ()), U" bytes)");
  164. MelderInfo_writeLine (U" Total deleted: ", Melder_bigInteger (Melder_deallocationCount ()));
  165. MelderInfo_writeLine (U" Reallocations: ", Melder_bigInteger (Melder_movingReallocationsCount ()), U" moving, ",
  166. Melder_bigInteger (Melder_reallocationsInSituCount ()), U" in situ");
  167. MelderInfo_writeLine (
  168. U" Strings created: ", Melder_bigInteger (MelderString_allocationCount ()), U" (", Melder_bigInteger (MelderString_allocationSize ()), U" bytes)");
  169. MelderInfo_writeLine (
  170. U" Strings deleted: ", Melder_bigInteger (MelderString_deallocationCount ()), U" (", Melder_bigInteger (MelderString_deallocationSize ()), U" bytes)");
  171. MelderInfo_writeLine (U"\nHistory of all sessions from ", statistics.dateOfFirstSession, U" until today:");
  172. MelderInfo_writeLine (U" Sessions: ", statistics.interactiveSessions, U" interactive, ",
  173. statistics.batchSessions, U" batch");
  174. MelderInfo_writeLine (U" Total memory use: ", Melder_bigInteger ((int64) statistics.memory + Melder_allocationSize ()), U" bytes");
  175. MelderInfo_writeLine (U"\nNumber of fixed menu commands: ", praat_getNumberOfMenuCommands ());
  176. MelderInfo_writeLine (U"Number of dynamic menu commands: ", praat_getNumberOfActions ());
  177. MelderInfo_close ();
  178. }
  179. void MelderCasual_memoryUse (integer message) {
  180. integer numberOfStrings = MelderString_allocationCount () - MelderString_deallocationCount ();
  181. integer numberOfArrays = NUM_getTotalNumberOfArrays ();
  182. integer numberOfThings = theTotalNumberOfThings;
  183. integer numberOfOther = Melder_allocationCount () - Melder_deallocationCount () - numberOfStrings - numberOfArrays - numberOfThings;
  184. Melder_casual (U"Memory ", message, U": ",
  185. numberOfStrings, U" strings, ", numberOfArrays, U" arrays, ", numberOfThings, U" things, ", numberOfOther, U" other.");
  186. }
  187. /* End of file praat_statistics.cpp */