Panda3D
 All Classes Functions Variables Enumerations
pStatThread.I
1 // Filename: pStatThread.I
2 // Created by: drose (11Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: PStatThread::Default Constructor
18 // Access: Private
19 // Description: Normally, this constructor is called only from
20 // PStatClient. Use one of the constructors below to
21 // create your own Thread.
22 ////////////////////////////////////////////////////////////////////
23 INLINE PStatThread::
24 PStatThread() {
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: PStatThread::Constructor
29 // Access: Published
30 // Description: Normally, this constructor is called only from
31 // PStatClient. Use one of the constructors below to
32 // create your own Thread.
33 ////////////////////////////////////////////////////////////////////
34 INLINE PStatThread::
35 PStatThread(PStatClient *client, int index) :
36  _client(client),
37  _index(index)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: PStatThread::Constructor
43 // Access: Public
44 // Description: Creates a new named thread. This will be used to
45 // unify tasks that share a common thread, and
46 // differentiate tasks that occur in different threads.
47 ////////////////////////////////////////////////////////////////////
48 INLINE PStatThread::
49 PStatThread(Thread *thread, PStatClient *client) {
50 #ifdef DO_PSTATS
51  if (client == (PStatClient *)NULL) {
52  client = PStatClient::get_global_pstats();
53  }
54 
55  int thread_index = thread->get_pstats_index();
56  if (thread_index != -1) {
57  (*this) = PStatThread(client, thread_index);
58 
59  } else {
60  // This is the first time we have encountered this current Thread.
61  // Make a new PStatThread object for it.
62  (*this) = client->make_thread(thread);
63  }
64 #else
65  _client = (PStatClient *)NULL;
66  _index = 0;
67 #endif
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: PStatThread::Copy Constructor
72 // Access: Public
73 // Description:
74 ////////////////////////////////////////////////////////////////////
75 INLINE PStatThread::
76 PStatThread(const PStatThread &copy) :
77  _client(copy._client),
78  _index(copy._index)
79 {
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: PStatThread::Copy Assignment Operator
84 // Access: Public
85 // Description:
86 ////////////////////////////////////////////////////////////////////
87 INLINE void PStatThread::
88 operator = (const PStatThread &copy) {
89  _client = copy._client;
90  _index = copy._index;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: PStatThread::new_frame
95 // Access: Public
96 // Description: This must be called at the start of every "frame",
97 // whatever a frame may be deemed to be, to accumulate
98 // all the stats that have collected so far for the
99 // thread and ship them off to the server.
100 //
101 // Calling PStatClient::thread_tick() will automatically
102 // call this for any threads with the indicated sync
103 // name.
104 ////////////////////////////////////////////////////////////////////
105 INLINE void PStatThread::
107 #ifdef DO_PSTATS
108  _client->get_impl()->new_frame(_index);
109 #endif
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: PStatThread::add_frame
114 // Access: Public
115 // Description: This is a slightly lower-level version of new_frame
116 // that also specifies the data to send for this frame.
117 ////////////////////////////////////////////////////////////////////
118 INLINE void PStatThread::
119 add_frame(const PStatFrameData &frame_data) {
120 #ifdef DO_PSTATS
121  _client->get_impl()->add_frame(_index, frame_data);
122 #endif
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: PStatThread::get_index
127 // Access: Published
128 // Description: Returns the index number of this particular thread
129 // within the PStatClient.
130 ////////////////////////////////////////////////////////////////////
131 INLINE int PStatThread::
132 get_index() const {
133  return _index;
134 }
Contains the raw timing and level data for a single frame.
A lightweight class that represents a single thread of execution to PStats.
Definition: pStatThread.h:31
int get_pstats_index() const
Returns the PStats index associated with this thread, or -1 if no index has yet been associated with ...
Definition: thread.I:60
A thread; that is, a lightweight process.
Definition: thread.h:51
void new_frame()
This must be called at the start of every "frame", whatever a frame may be deemed to be...
Definition: pStatThread.I:106
Manages the communications to report statistics via a network connection to a remote PStatServer...
Definition: pStatClient.h:261
void add_frame(const PStatFrameData &frame_data)
This is a slightly lower-level version of new_frame that also specifies the data to send for this fra...
Definition: pStatThread.I:119
int get_index() const
Returns the index number of this particular thread within the PStatClient.
Definition: pStatThread.I:132