mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
enhancements from community member Clemens Pecinovsky to support writing output to a file
This commit is contained in:
parent
131f768d8d
commit
c9dd462b12
@ -25,7 +25,9 @@
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TextMonitor::
|
||||
TextMonitor(TextStats *server) : PStatMonitor(server) {
|
||||
TextMonitor(TextStats *server, ostream *outStream, bool show_raw_data ) : PStatMonitor(server) {
|
||||
_outStream = outStream; //[PECI]
|
||||
_show_raw_data = show_raw_data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -105,30 +107,30 @@ new_data(int thread_index, int frame_number) {
|
||||
if (view.all_collectors_known()) {
|
||||
const PStatClientData *client_data = get_client_data();
|
||||
|
||||
nout << "\rThread "
|
||||
(*_outStream) << "\rThread "
|
||||
<< client_data->get_thread_name(thread_index)
|
||||
<< " frame " << frame_number << ", "
|
||||
<< view.get_net_value() * 1000.0 << " ms ("
|
||||
<< thread_data->get_frame_rate() << " Hz):\n";
|
||||
|
||||
if (get_server()->_show_raw_data) {
|
||||
if (_show_raw_data) {
|
||||
const PStatFrameData &frame_data = thread_data->get_frame(frame_number);
|
||||
nout << "raw data:\n";
|
||||
(*_outStream) << "raw data:\n";
|
||||
int num_events = frame_data.get_num_events();
|
||||
for (int i = 0; i < num_events; ++i) {
|
||||
// The iomanipulators are much too clumsy.
|
||||
char formatted[32];
|
||||
sprintf(formatted, "%15.06lf", frame_data.get_time(i));
|
||||
nout << formatted;
|
||||
(*_outStream) << formatted;
|
||||
|
||||
if (frame_data.is_start(i)) {
|
||||
nout << " start ";
|
||||
(*_outStream) << " start ";
|
||||
} else {
|
||||
nout << " stop ";
|
||||
(*_outStream) << " stop ";
|
||||
}
|
||||
|
||||
int collector_index = frame_data.get_time_collector(i);
|
||||
nout << client_data->get_collector_fullname(collector_index) << "\n";
|
||||
(*_outStream) << client_data->get_collector_fullname(collector_index) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +154,7 @@ new_data(int thread_index, int frame_number) {
|
||||
}
|
||||
}
|
||||
}
|
||||
_outStream->flush();
|
||||
}
|
||||
|
||||
|
||||
@ -196,7 +199,7 @@ show_ms(const PStatViewLevel *level, int indent_level) {
|
||||
const PStatClientData *client_data = get_client_data();
|
||||
const PStatCollectorDef &def = client_data->get_collector_def(collector_index);
|
||||
|
||||
indent(nout, indent_level)
|
||||
indent((*_outStream), indent_level)
|
||||
<< def._name << " = " << level->get_net_value() * 1000.0 << " ms\n" ;
|
||||
|
||||
int num_children = level->get_num_children();
|
||||
@ -217,7 +220,7 @@ show_level(const PStatViewLevel *level, int indent_level) {
|
||||
const PStatClientData *client_data = get_client_data();
|
||||
const PStatCollectorDef &def = client_data->get_collector_def(collector_index);
|
||||
|
||||
indent(nout, indent_level)
|
||||
indent((*_outStream), indent_level)
|
||||
<< def._name << " = " << level->get_net_value() << " "
|
||||
<< def._level_units << "\n";
|
||||
|
||||
|
@ -18,6 +18,10 @@
|
||||
#include "pandatoolbase.h"
|
||||
#include "pStatMonitor.h"
|
||||
|
||||
//[PECI]
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
class TextStats;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -27,7 +31,7 @@ class TextStats;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class TextMonitor : public PStatMonitor {
|
||||
public:
|
||||
TextMonitor(TextStats *server);
|
||||
TextMonitor(TextStats *server, ostream *outStream, bool show_raw_data);
|
||||
TextStats *get_server();
|
||||
|
||||
virtual string get_monitor_name();
|
||||
@ -41,6 +45,10 @@ public:
|
||||
|
||||
void show_ms(const PStatViewLevel *level, int indent_level);
|
||||
void show_level(const PStatViewLevel *level, int indent_level);
|
||||
|
||||
private:
|
||||
ostream *_outStream; //[PECI]
|
||||
bool _show_raw_data;
|
||||
};
|
||||
|
||||
#include "textMonitor.I"
|
||||
|
@ -53,6 +53,12 @@ TextStats() {
|
||||
"time per collector.",
|
||||
&TextStats::dispatch_none, &_show_raw_data, NULL);
|
||||
|
||||
add_option
|
||||
("o", "filename", 0,
|
||||
"Filename where to print. If not given then stderr is being used.",
|
||||
&TextStats::dispatch_string, &_got_outputFileName, &_outputFileName);
|
||||
|
||||
_outFile = NULL;
|
||||
_port = pstats_port;
|
||||
}
|
||||
|
||||
@ -64,7 +70,8 @@ TextStats() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PStatMonitor *TextStats::
|
||||
make_monitor() {
|
||||
return new TextMonitor(this);
|
||||
|
||||
return new TextMonitor(this, _outFile, _show_raw_data);
|
||||
}
|
||||
|
||||
|
||||
@ -86,6 +93,12 @@ run() {
|
||||
|
||||
nout << "Listening for connections.\n";
|
||||
|
||||
if (_got_outputFileName) {
|
||||
_outFile = new ofstream(_outputFileName.c_str(), ios::out);
|
||||
} else {
|
||||
_outFile = &(nout);
|
||||
}
|
||||
|
||||
main_loop(&user_interrupted);
|
||||
nout << "Exiting.\n";
|
||||
}
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include "programBase.h"
|
||||
#include "pStatServer.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : TextStats
|
||||
// Description : A simple, scrolling-text stats server. Guaranteed to
|
||||
@ -33,8 +36,14 @@ public:
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
int _port;
|
||||
bool _show_raw_data;
|
||||
|
||||
//[PECI]
|
||||
bool _got_outputFileName;
|
||||
string _outputFileName;
|
||||
ostream *_outFile;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user