00001 // Filename: textMonitor.cxx 00002 // Created by: drose (12Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "textMonitor.h" 00020 00021 #include <indent.h> 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: TextMonitor::Constructor 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 TextMonitor:: 00029 TextMonitor() { 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: TextMonitor::get_monitor_name 00034 // Access: Public, Virtual 00035 // Description: Should be redefined to return a descriptive name for 00036 // the type of PStatsMonitor this is. 00037 //////////////////////////////////////////////////////////////////// 00038 string TextMonitor:: 00039 get_monitor_name() { 00040 return "Text Stats"; 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: TextMonitor::got_hello 00045 // Access: Public, Virtual 00046 // Description: Called when the "hello" message has been received 00047 // from the client. At this time, the client's hostname 00048 // and program name will be known. 00049 //////////////////////////////////////////////////////////////////// 00050 void TextMonitor:: 00051 got_hello() { 00052 nout << "Now connected to " << get_client_progname() << " on host " 00053 << get_client_hostname() << "\n"; 00054 } 00055 00056 //////////////////////////////////////////////////////////////////// 00057 // Function: TextMonitor::got_bad_version 00058 // Access: Public, Virtual 00059 // Description: Like got_hello(), this is called when the "hello" 00060 // message has been received from the client. At this 00061 // time, the client's hostname and program name will be 00062 // known. However, the client appears to be an 00063 // incompatible version and the connection will be 00064 // terminated; the monitor should issue a message to 00065 // that effect. 00066 //////////////////////////////////////////////////////////////////// 00067 void TextMonitor:: 00068 got_bad_version(int client_major, int client_minor, 00069 int server_major, int server_minor) { 00070 nout 00071 << "Rejected connection by " << get_client_progname() 00072 << " from " << get_client_hostname() 00073 << ". Client uses PStats version " 00074 << client_major << "." << client_minor 00075 << ", while server expects PStats version " 00076 << server_major << "." << server_minor << ".\n"; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: TextMonitor::new_data 00081 // Access: Public, Virtual 00082 // Description: Called as each frame's data is made available. There 00083 // is no gurantee the frames will arrive in order, or 00084 // that all of them will arrive at all. The monitor 00085 // should be prepared to accept frames received 00086 // out-of-order or missing. 00087 //////////////////////////////////////////////////////////////////// 00088 void TextMonitor:: 00089 new_data(int thread_index, int frame_number) { 00090 PStatView &view = get_view(thread_index); 00091 const PStatThreadData *thread_data = view.get_thread_data(); 00092 00093 if (frame_number == thread_data->get_latest_frame_number()) { 00094 view.set_to_frame(frame_number); 00095 00096 if (view.all_collectors_known()) { 00097 nout << "\rThread " 00098 << get_client_data()->get_thread_name(thread_index) 00099 << " frame " << frame_number << ", " 00100 << view.get_net_value() * 1000.0 << " ms (" 00101 << thread_data->get_frame_rate() << " Hz):\n"; 00102 const PStatViewLevel *level = view.get_top_level(); 00103 int num_children = level->get_num_children(); 00104 for (int i = 0; i < num_children; i++) { 00105 show_level(level->get_child(i), 2); 00106 } 00107 } 00108 } 00109 } 00110 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: TextMonitor::lost_connection 00114 // Access: Public, Virtual 00115 // Description: Called whenever the connection to the client has been 00116 // lost. This is a permanent state change. The monitor 00117 // should update its display to represent this, and may 00118 // choose to close down automatically. 00119 //////////////////////////////////////////////////////////////////// 00120 void TextMonitor:: 00121 lost_connection() { 00122 nout << "Lost connection.\n"; 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: TextMonitor::is_thread_safe 00127 // Access: Public, Virtual 00128 // Description: Should be redefined to return true if this monitor 00129 // class can handle running in a sub-thread. 00130 // 00131 // This is not related to the question of whether it can 00132 // handle multiple different PStatThreadDatas; this is 00133 // strictly a question of whether or not the monitor 00134 // itself wants to run in a sub-thread. 00135 //////////////////////////////////////////////////////////////////// 00136 bool TextMonitor:: 00137 is_thread_safe() { 00138 return true; 00139 } 00140 00141 //////////////////////////////////////////////////////////////////// 00142 // Function: TextMonitor::show_level 00143 // Access: Public 00144 // Description: 00145 //////////////////////////////////////////////////////////////////// 00146 void TextMonitor:: 00147 show_level(const PStatViewLevel *level, int indent_level) { 00148 int collector_index = level->get_collector(); 00149 00150 indent(nout, indent_level) 00151 << get_client_data()->get_collector_name(collector_index) 00152 << " = " << level->get_net_value() * 1000.0 << " ms\n"; 00153 00154 int num_children = level->get_num_children(); 00155 for (int i = 0; i < num_children; i++) { 00156 show_level(level->get_child(i), indent_level + 2); 00157 } 00158 }