Panda3D
|
00001 // Filename: textStats.cxx 00002 // Created by: drose (12Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "textStats.h" 00016 #include "textMonitor.h" 00017 00018 #include "pStatServer.h" 00019 #include "config_pstats.h" 00020 #include "pystub.h" 00021 00022 #include <signal.h> 00023 00024 static bool user_interrupted = false; 00025 00026 // This simple signal handler lets us know when the user has pressed 00027 // control-C, so we can clean up nicely. 00028 static void signal_handler(int) { 00029 user_interrupted = true; 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: TextStats::Constructor 00034 // Access: Public 00035 // Description: 00036 //////////////////////////////////////////////////////////////////// 00037 TextStats:: 00038 TextStats() { 00039 set_program_description 00040 ("This is a simple PStats server that listens on a TCP port for a " 00041 "connection from a PStatClient in a Panda player. It will then report " 00042 "frame rate and timing information sent by the player."); 00043 00044 add_option 00045 ("p", "port", 0, 00046 "Specify the TCP port to listen for connections on. By default, this " 00047 "is taken from the pstats-host Config variable.", 00048 &TextStats::dispatch_int, NULL, &_port); 00049 00050 add_option 00051 ("r", "", 0, 00052 "Show the raw frame data, in addition to boiling it down to a total " 00053 "time per collector.", 00054 &TextStats::dispatch_none, &_show_raw_data, NULL); 00055 00056 add_option 00057 ("o", "filename", 0, 00058 "Filename where to print. If not given then stderr is being used.", 00059 &TextStats::dispatch_string, &_got_outputFileName, &_outputFileName); 00060 00061 _outFile = NULL; 00062 _port = pstats_port; 00063 } 00064 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: TextStats::make_monitor 00068 // Access: Public 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 PStatMonitor *TextStats:: 00072 make_monitor() { 00073 00074 return new TextMonitor(this, _outFile, _show_raw_data); 00075 } 00076 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: TextStats::run 00080 // Access: Public 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 void TextStats:: 00084 run() { 00085 // Set up a global signal handler to catch Interrupt (Control-C) so 00086 // we can clean up nicely if the user stops us. 00087 signal(SIGINT, &signal_handler); 00088 00089 if (!listen(_port)) { 00090 nout << "Unable to open port.\n"; 00091 exit(1); 00092 } 00093 00094 nout << "Listening for connections.\n"; 00095 00096 if (_got_outputFileName) { 00097 _outFile = new ofstream(_outputFileName.c_str(), ios::out); 00098 } else { 00099 _outFile = &(nout); 00100 } 00101 00102 main_loop(&user_interrupted); 00103 nout << "Exiting.\n"; 00104 } 00105 00106 00107 int main(int argc, char *argv[]) { 00108 // A call to pystub() to force libpystub.so to be linked in. 00109 pystub(); 00110 00111 TextStats prog; 00112 prog.parse_command_line(argc, argv); 00113 prog.run(); 00114 return 0; 00115 }