root/juggler/tags/1.0.5/Performance/vjTimeStampSGI.h
| Revision 2828, 3.7 kB (checked in by patrickh, 8 years ago) | |
|---|---|
| |
| 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 | #ifndef _VJ_TIMESTAMP_SGI_ |
| 36 | #define _VJ_TIMESTAMP_SGI_ |
| 37 | |
| 38 | #include <vjConfig.h> |
| 39 | #include <sys/types.h> |
| 40 | |
| 41 | //----------------------------------------- |
| 42 | //:Time recorder for SGI systems |
| 43 | // |
| 44 | // This version of vjTimeStamp uses the SGI system cycle |
| 45 | // counter to collect timing information. The precision |
| 46 | // of this hardware timer varies on different machines. |
| 47 | // For example, on an SGI Onyx it's 21 nanoseconds, while |
| 48 | // it's 80 ns on an Octane. |
| 49 | // |
| 50 | // vjTimeStampPosix should never be instantiated directly. |
| 51 | // Instead, use vjTimeStamp, which will be typedefed to |
| 52 | // the correct implementation. |
| 53 | // |
| 54 | // @author Christopher Just |
| 55 | //----------------------------------------- |
| 56 | |
| 57 | class vjTimeStampSGI { |
| 58 | |
| 59 | public: |
| 60 | |
| 61 | //: Called at application initialization to open the counter |
| 62 | //! PRE: true |
| 63 | //! POST: cycle counter is initialized |
| 64 | //! RETURNS: true - succes |
| 65 | //! RETURNS: false - failure to open counter. Timestamp set() |
| 66 | //+ will set to the value 0. |
| 67 | static void initialize(); |
| 68 | |
| 69 | |
| 70 | |
| 71 | //: Constructor |
| 72 | //! PRE: initialize() has been called. |
| 73 | //! POST: self is created and set to the current counter val. |
| 74 | vjTimeStampSGI(); |
| 75 | |
| 76 | |
| 77 | |
| 78 | //: stamps the timestamp with the current time |
| 79 | //! PRE: true |
| 80 | //! POST: self's value is the current time |
| 81 | inline void set() { |
| 82 | val = (cyclecntrsize == 64) |
| 83 | ? *(unsigned long long*) iotimer_addr |
| 84 | : *(unsigned int*) iotimer_addr; |
| 85 | val = (val >= initval) |
| 86 | ? val - initval |
| 87 | : val + (maxval - initval); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | |
| 92 | //: assignment operator |
| 93 | vjTimeStampSGI& operator= (const vjTimeStampSGI& t2) { |
| 94 | val = t2.val; |
| 95 | return *this; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | |
| 100 | //: returns number of microseconds between self and t2 |
| 101 | //! PRE: t2 is stamped with an earlier time than self |
| 102 | //! |
| 103 | float operator - (const vjTimeStampSGI& t2) const; |
| 104 | |
| 105 | |
| 106 | |
| 107 | float usecs(); |
| 108 | |
| 109 | friend std::ostream& operator << (std::ostream& out, vjTimeStampSGI& ts); |
| 110 | |
| 111 | //: returns resolution of timer in microseconds |
| 112 | float getResolution(); |
| 113 | |
| 114 | private: |
| 115 | |
| 116 | static __psunsigned_t phys_addr, raddr; |
| 117 | static volatile void* iotimer_addr; |
| 118 | static volatile unsigned long long longcount; |
| 119 | static int fd, poffmask; |
| 120 | static float resolution; // in usecs. |
| 121 | static int cyclecntrsize; // either 32 or 64 bits. depends on hardware |
| 122 | static long long initval; |
| 123 | static long long maxval; |
| 124 | |
| 125 | long long val; // (in clockticks; resolution*clocktics = time in usecs |
| 126 | |
| 127 | }; |
| 128 | |
| 129 | #endif |
Note: See TracBrowser for help on using the browser.
