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

Revision 2828, 6.3 kB (checked in by patrickh, 8 years ago)

Updated the copyright to what ISU's lawyers decided they want now.
The vast majority of this was done using Kevin's auto-copyright.pl script
which definitely made this easier. All the copyright blocks now have
begin and end tags so that if and when we have to update the copyright
information again, it will be even simpler.

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