textMonitor.cxx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Filename: textMonitor.cxx
  2. // Created by: drose (12Jul00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "textMonitor.h"
  19. #include "textStats.h"
  20. #include "pStatCollectorDef.h"
  21. #include "indent.h"
  22. ////////////////////////////////////////////////////////////////////
  23. // Function: TextMonitor::Constructor
  24. // Access: Public
  25. // Description:
  26. ////////////////////////////////////////////////////////////////////
  27. TextMonitor::
  28. TextMonitor(TextStats *server) : PStatMonitor(server) {
  29. }
  30. ////////////////////////////////////////////////////////////////////
  31. // Function: TextMonitor::get_monitor_name
  32. // Access: Public, Virtual
  33. // Description: Should be redefined to return a descriptive name for
  34. // the type of PStatsMonitor this is.
  35. ////////////////////////////////////////////////////////////////////
  36. string TextMonitor::
  37. get_monitor_name() {
  38. return "Text Stats";
  39. }
  40. ////////////////////////////////////////////////////////////////////
  41. // Function: TextMonitor::got_hello
  42. // Access: Public, Virtual
  43. // Description: Called when the "hello" message has been received
  44. // from the client. At this time, the client's hostname
  45. // and program name will be known.
  46. ////////////////////////////////////////////////////////////////////
  47. void TextMonitor::
  48. got_hello() {
  49. nout << "Now connected to " << get_client_progname() << " on host "
  50. << get_client_hostname() << "\n";
  51. }
  52. ////////////////////////////////////////////////////////////////////
  53. // Function: TextMonitor::got_bad_version
  54. // Access: Public, Virtual
  55. // Description: Like got_hello(), this is called when the "hello"
  56. // message has been received from the client. At this
  57. // time, the client's hostname and program name will be
  58. // known. However, the client appears to be an
  59. // incompatible version and the connection will be
  60. // terminated; the monitor should issue a message to
  61. // that effect.
  62. ////////////////////////////////////////////////////////////////////
  63. void TextMonitor::
  64. got_bad_version(int client_major, int client_minor,
  65. int server_major, int server_minor) {
  66. nout
  67. << "Rejected connection by " << get_client_progname()
  68. << " from " << get_client_hostname()
  69. << ". Client uses PStats version "
  70. << client_major << "." << client_minor
  71. << ", while server expects PStats version "
  72. << server_major << "." << server_minor << ".\n";
  73. }
  74. ////////////////////////////////////////////////////////////////////
  75. // Function: TextMonitor::new_data
  76. // Access: Public, Virtual
  77. // Description: Called as each frame's data is made available. There
  78. // is no gurantee the frames will arrive in order, or
  79. // that all of them will arrive at all. The monitor
  80. // should be prepared to accept frames received
  81. // out-of-order or missing.
  82. ////////////////////////////////////////////////////////////////////
  83. void TextMonitor::
  84. new_data(int thread_index, int frame_number) {
  85. PStatView &view = get_view(thread_index);
  86. const PStatThreadData *thread_data = view.get_thread_data();
  87. if (frame_number == thread_data->get_latest_frame_number()) {
  88. view.set_to_frame(frame_number);
  89. if (view.all_collectors_known()) {
  90. const PStatClientData *client_data = get_client_data();
  91. nout << "\rThread "
  92. << client_data->get_thread_name(thread_index)
  93. << " frame " << frame_number << ", "
  94. << view.get_net_value() * 1000.0 << " ms ("
  95. << thread_data->get_frame_rate() << " Hz):\n";
  96. const PStatViewLevel *level = view.get_top_level();
  97. int num_children = level->get_num_children();
  98. for (int i = 0; i < num_children; i++) {
  99. show_ms(level->get_child(i), 2);
  100. }
  101. int num_toplevel_collectors = client_data->get_num_toplevel_collectors();
  102. for (int tc = 0; tc < num_toplevel_collectors; tc++) {
  103. int collector = client_data->get_toplevel_collector(tc);
  104. if (client_data->has_collector(collector) &&
  105. client_data->get_collector_has_level(collector)) {
  106. PStatView &level_view = get_level_view(collector, thread_index);
  107. level_view.set_to_frame(frame_number);
  108. const PStatViewLevel *level = level_view.get_top_level();
  109. show_level(level, 2);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. ////////////////////////////////////////////////////////////////////
  116. // Function: TextMonitor::lost_connection
  117. // Access: Public, Virtual
  118. // Description: Called whenever the connection to the client has been
  119. // lost. This is a permanent state change. The monitor
  120. // should update its display to represent this, and may
  121. // choose to close down automatically.
  122. ////////////////////////////////////////////////////////////////////
  123. void TextMonitor::
  124. lost_connection() {
  125. nout << "Lost connection.\n";
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. // Function: TextMonitor::is_thread_safe
  129. // Access: Public, Virtual
  130. // Description: Should be redefined to return true if this monitor
  131. // class can handle running in a sub-thread.
  132. //
  133. // This is not related to the question of whether it can
  134. // handle multiple different PStatThreadDatas; this is
  135. // strictly a question of whether or not the monitor
  136. // itself wants to run in a sub-thread.
  137. ////////////////////////////////////////////////////////////////////
  138. bool TextMonitor::
  139. is_thread_safe() {
  140. return true;
  141. }
  142. ////////////////////////////////////////////////////////////////////
  143. // Function: TextMonitor::show_ms
  144. // Access: Public
  145. // Description:
  146. ////////////////////////////////////////////////////////////////////
  147. void TextMonitor::
  148. show_ms(const PStatViewLevel *level, int indent_level) {
  149. int collector_index = level->get_collector();
  150. const PStatClientData *client_data = get_client_data();
  151. const PStatCollectorDef &def = client_data->get_collector_def(collector_index);
  152. indent(nout, indent_level)
  153. << def._name << " = " << level->get_net_value() * 1000.0 << " ms\n" ;
  154. int num_children = level->get_num_children();
  155. for (int i = 0; i < num_children; i++) {
  156. show_ms(level->get_child(i), indent_level + 2);
  157. }
  158. }
  159. ////////////////////////////////////////////////////////////////////
  160. // Function: TextMonitor::show_level
  161. // Access: Public
  162. // Description:
  163. ////////////////////////////////////////////////////////////////////
  164. void TextMonitor::
  165. show_level(const PStatViewLevel *level, int indent_level) {
  166. int collector_index = level->get_collector();
  167. const PStatClientData *client_data = get_client_data();
  168. const PStatCollectorDef &def = client_data->get_collector_def(collector_index);
  169. indent(nout, indent_level)
  170. << def._name << " = " << level->get_net_value() << " "
  171. << def._level_units << "\n";
  172. int num_children = level->get_num_children();
  173. for (int i = 0; i < num_children; i++) {
  174. show_level(level->get_child(i), indent_level + 2);
  175. }
  176. }