root/juggler/tags/1.0.7/Performance/vjPerfDataBuffer.h

Revision 8789, 6.3 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34
35
36
37 #ifndef _VJ_PERF_DATA_BUFFER_H_
38 #define _VJ_PERF_DATA_BUFFER_H_
39
40 #include <vjConfig.h>
41 #include <Environment/vjTimedUpdate.h>
42 #include <Performance/vjTimeStamp.h>
43 #include <Sync/vjMutex.h>
44 #include <Kernel/vjDebug.h>
45
46 //---------------------------------------------------------------
47 //: temporary storage for performance data
48 //
49 // Problem: gathering up the performance data and shipping it out
50 //          to wherever should happen independently of the
51 //          process that's generating the data.
52 // <p>
53 // Solution: the vjPerfDataBuffer is used as a temporary storage
54 //           for perfdata.  Each unit in the buffer contains
55 //           an integer index and a timestamp. the index is used
56 //           in case there are multiple points inside the
57 //           process body where timestamps are generated
58 //           (i.e. 1 = start of frame, 2 = before sync,
59 //           3 = between sync and buffer swap.
60 // <p>
61 // One process can write to the buffer (using the set() fn)
62 // while another simultaneously reads from it using the
63 // write() function.  The system is implemented so that the
64 // writing process never has to wait.  However, this means
65 // that if the writer gets far enough ahead of the reader
66 // that there are no more free buffers, the PerfDataBuffer
67 // will start throwing away data until there is a free buffer.
68 // The 'lost' field approximates the number of data samples
69 // lost; it is reported and reset at the conclusion of every
70 // write() call.
71 //
72 //----------------------------------------------------------------
73 class vjPerfDataBuffer: public vjTimedUpdate {
74
75     struct buf_entry {
76
77         //: an index for the point in the proc. that we're at
78         int              phase;
79        
80         //: time stamp associated with this point.
81         vjTimeStamp      ts;
82        
83         buf_entry() {
84             phase = 0;
85         }
86     };
87
88
89
90     buf_entry*  buffer;
91     int         numbufs;
92     int         lost;
93     vjMutex     lost_lock;
94
95     int         read_begin;
96     int         write_pos;
97
98     //: Buffer is currently active
99     bool        active;
100
101 public:
102     char*       name;
103     int         nindex;
104
105  public:
106
107     //: constructor
108     //! PRE: true
109     //! POST: self is created and has _numbufs buffers
110     //! ARGS: _numbufs - number of buffers to allocate
111     //+       (default 50)
112     vjPerfDataBuffer (char* _name, int _numbufs, int _nindex) {
113         init (_name, _numbufs, _nindex);
114     }
115
116     vjPerfDataBuffer (const std::string& _name, int _numbufs, int _nindex) {
117         init (_name.c_str(), _numbufs, _nindex);
118     }
119
120     //: destructor
121     //: POST: all memory & buffers have been freed.
122     virtual ~vjPerfDataBuffer ();
123
124
125
126     virtual std::string getName() {
127         return (std::string)name;
128     }
129
130     //: activates the buffer
131     //! POST: once this call is made, the buffer will start
132     //+       storing data whenever a set() is made and
133     //+       writing available data when requested.
134     void activate();
135
136
137
138     //: deactivates the buffer
139     //! POST: once this call is made, the buffer will,
140     //+       essentially, do nothing.  set() will not store
141     //+       any information and the write calls won't
142     //+       write anything.
143     void deactivate();
144
145
146
147     //: is the buffer active?
148     //! RETURNS: True - buffer is currently active
149     //! RETURNS: False - buffer is not active
150     bool isActive();
151
152
153     //: writes a new time entry to the buffer
154     //! POST: if a buffer is available, it is stamped with
155     //+       the current time and _phase.  If not, the
156     //+       'lost' counter is incremented.
157     //! ARGS: _phase - an integer index used to differentiate
158     //+       between different stamping points in the process
159     //+       that calls set. e.g. 1 = point right before
160     //+       entering some big computation, and 2 = point
161     //+       right after.
162     void set(int _phase);
163
164     void set (int _phase, vjTimeStamp& _value);
165
166     // for below: need a version w/ max # buffers to write
167
168     //: writes buffer contents to an ostream
169     //! POST: As many buffers as available are written to
170     //+       the ostream out and released so they can be
171     //+       used again by the writer.
172     //! ARGS: out - an ostream to write contents to.
173     //! NOTE: The format for a buffer is 'ind timestamp\n',
174     //+       e.g.: (for four buffers, say we have 3 indices)
175     //+       <br>1 15
176     //+       <br>2 25
177     //+       <br>3 27
178     //+       <br>1 42
179     void write (std::ostream& out);
180
181
182     //: just deletes all the current info in buffer.
183     //! NOTE: this is mainly a utility used in testing performance
184     //+       of the perf data collection
185     //! RETURNS: x - time in usecs between first and last points.
186     //+          which is only useful if you know how many pts
187     //+          there are...
188     void writeTotal (std::ostream& out, int preskip, int postskip, float discrep);
189
190
191     //: just empties out the buffer & throws away the data.
192     void dumpData();
193
194     private:
195     void init (const char* _name, int _numbufs, int _nindex);
196    
197 };
198
199
200
201 #endif
Note: See TracBrowser for help on using the browser.