ProfileIPC.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef __SUPPORT_PROFILEIPC_H
00014 #define __SUPPORT_PROFILEIPC_H
00015 
00016 #include <support/SupportDefs.h>
00017 
00018 #if BUILD_TYPE == BUILD_TYPE_DEBUG
00019 
00020 #include <support/Debug.h>
00021 #include <support/ITextStream.h>
00022 #include <support/Locker.h>
00023 #include <support/Autolock.h>
00024 #include <support/CallStack.h>
00025 #include <support/KeyedVector.h>
00026 
00027 #if _SUPPORTS_NAMESPACE
00028 namespace palmos {
00029 namespace support {
00030 #endif
00031 
00032 struct ipc_call_state
00033 {
00034     SCallStack  stack;
00035     nsecs_t startTime;
00036 
00037 protected:
00038     // Must provide subclass that does stack.Update().
00039     inline ipc_call_state() { }
00040     inline ~ipc_call_state() { }
00041 };
00042 
00043 struct ipc_stats
00044 {
00045 #if 1 // FIXME: Linux
00046     mutable SysCriticalSectionType  cs;
00047 #else
00048     mutable CriticalSectionType cs;
00049 #endif  
00050             int32_t             dumpPeriod;
00051             int32_t             maxItems;
00052             int32_t             printSymbols;
00053             const char*         printLabel;
00054             size_t              hits;
00055             nsecs_t             startTime;
00056             size_t              totalCalls;
00057 
00058             ipc_stats*          nextReady;
00059 
00060             struct ipc_item
00061             {
00062                 size_t      count;
00063                 nsecs_t     time;
00064                 
00065                 inline ipc_item()
00066                     :   count(0), time(0)
00067                 {
00068                 }
00069                 inline ipc_item(const ipc_item& o)
00070                     :   count(o.count), time(o.time)
00071                 {
00072                 }
00073             };
00074 
00075             SKeyedVector<SCallStack, ipc_item>
00076                                 calls;
00077     
00078                                 ipc_stats(  int32_t _dumpPeriod, int32_t _maxItems,
00079                                             int32_t _printSymbols, const char* _printLabel);
00080     virtual                     ~ipc_stats();
00081     
00082             void                lock() const;
00083             void                unlock() const;
00084             
00085             void                beginCall(ipc_call_state& state);
00086             void                finishCall(ipc_call_state& state);
00087 
00088             void                print();
00089 
00090             void                reset();
00091 
00092 private:
00093                                 ipc_stats(const ipc_stats& o);
00094 };
00095 
00096 #if _SUPPORTS_NAMESPACE
00097 } } // namespace palmos::support
00098 #endif
00099 
00100 #endif  // BUILD_TYPE == BUILD_TYPE_DEBUG
00101 
00102 #endif  // __SUPPORT_PROFILEIPC_H