00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00027
00028 static void signal_handler(int) {
00029 user_interrupted = true;
00030 }
00031
00032
00033
00034
00035
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
00068
00069
00070
00071 PStatMonitor *TextStats::
00072 make_monitor() {
00073
00074 return new TextMonitor(this, _outFile, _show_raw_data);
00075 }
00076
00077
00078
00079
00080
00081
00082
00083 void TextStats::
00084 run() {
00085
00086
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
00109 pystub();
00110
00111 TextStats prog;
00112 prog.parse_command_line(argc, argv);
00113 prog.run();
00114 return 0;
00115 }