Back to index

lightning-sunbird  0.9+nobinonly
xpctools_private.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   John Bandhauer <jband@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /* All the XPCTools private declarations - only include locally. */
00042 
00043 #ifndef xpctoolsprivate_h___
00044 #define xpctoolsprivate_h___
00045 
00046 #include <string.h>
00047 #include <stdlib.h>
00048 #include "nscore.h"
00049 #include "nsISupports.h"
00050 #include "nsIServiceManager.h"
00051 #include "nsIComponentManager.h"
00052 #include "nsIGenericFactory.h"
00053 #include "nsIMemory.h"
00054 #include "nsIXPConnect.h"
00055 #include "nsCOMPtr.h"
00056 #include "nsIModule.h"
00057 #include "jsapi.h"
00058 #include "jshash.h"
00059 #include "jsprf.h"
00060 #include "jsinterp.h"
00061 #include "jscntxt.h"
00062 #include "jsdbgapi.h"
00063 
00064 #include "nsILocalFile.h"
00065 #include "nsCRT.h"
00066 
00067 #include "nsIJSRuntimeService.h"
00068 #include "nsHashtable.h"
00069 #include "nsAutoLock.h"
00070 
00071 #include "nsIXPCToolsCompiler.h"
00072 #include "nsIXPCToolsProfiler.h"
00073 
00074 class nsXPCToolsCompiler : public nsIXPCToolsCompiler
00075 {
00076 public:
00077   NS_DECL_ISUPPORTS
00078   NS_DECL_NSIXPCTOOLSCOMPILER
00079 
00080   nsXPCToolsCompiler();
00081   virtual ~nsXPCToolsCompiler();
00082   // XXX add additional members
00083 };
00084 
00085 /***************************************************************************/
00086 
00087 class ProfilerFunction;
00088 
00089 class ProfilerFile
00090 {
00091 public:
00092     ProfilerFile(const char* filename);
00093     ~ProfilerFile();
00094 
00095     
00096     ProfilerFunction* FindOrAddFunction(const char* aName,
00097                                         uintN aBaseLineNumber,
00098                                         uintN aLineExtent,
00099                                         size_t aTotalSize);
00100     void EnumerateFunctions(nsHashtableEnumFunc aEnumFunc, void* closure);
00101     const char* GetName() const {return mName;}
00102 
00103     ProfilerFile(); // not implemented
00104 private:
00105     char*           mName;
00106     nsHashtable*    mFunctionTable;
00107 };
00108 
00109 class ProfilerFunction
00110 {
00111 public:
00112     ProfilerFunction(const char* name, 
00113                      uintN lineno, uintn extent, size_t totalsize,
00114                      ProfilerFile* file);
00115     ~ProfilerFunction();
00116 
00117     const char*   GetName() const {return mName;}
00118     ProfilerFile* GetFile() const {return mFile;}
00119     uintN         GetBaseLineNumber() const {return mBaseLineNumber;}
00120     uintN         GetLineExtent() const {return mLineExtent;}
00121     size_t        GetTotalSize() const { return mTotalSize; }
00122     void          IncrementCallCount() {++mCallCount;}
00123     PRUint32      GetCallCount() {return mCallCount;}
00124     PRUint32      GetSum() {return mSum;}
00125     void          IncrementCompileCount() {++mCompileCount;}
00126     PRUint32      GetCompileCount() {return mCompileCount;}
00127     PRUint32      NowInMilliSecs()
00128         {PRUint64 now64 = LL_INIT(0,1000);
00129          PRUint32 now32;
00130          LL_DIV(now64,PR_Now(),now64);
00131          LL_L2UI(now32, now64);
00132          return now32;
00133         }
00134     void          SetStartTime() {mStartTime = NowInMilliSecs();}
00135     void          SetEndTime()
00136         {PRUint32 delta = NowInMilliSecs() - mStartTime;
00137          if(delta < mQuickTime)
00138             mQuickTime = delta;
00139          if (delta > mLongTime)
00140             mLongTime = delta;
00141          mSum += delta;}
00142     PRUint32      GetQuickTime() {return mQuickTime;}
00143     PRUint32      GetLongTime() {return mLongTime;}
00144 
00145     ProfilerFunction(); // not implemented
00146 
00147 private:
00148     char*           mName;
00149     uintN           mBaseLineNumber;
00150     uintN           mLineExtent;
00151     size_t          mTotalSize;     // JSFunction, JSScript, bytecode, &c, size
00152     ProfilerFile*   mFile;
00153     PRUint32        mCallCount;
00154     PRUint32        mCompileCount;
00155     PRUint32        mQuickTime;     // quickest delta in msec
00156     PRUint32        mLongTime;      // longest delta in msec
00157     PRUint32        mStartTime;     // time on enter
00158     PRUint32        mSum;
00159 };
00160 
00161 
00162 class nsXPCToolsProfiler : public nsIXPCToolsProfiler
00163 {
00164 public:
00165   NS_DECL_ISUPPORTS
00166   NS_DECL_NSIXPCTOOLSPROFILER
00167 
00168   nsXPCToolsProfiler();
00169   virtual ~nsXPCToolsProfiler();
00170 
00171 private:
00172     JSBool InitializeRuntime();
00173     JSBool VerifyRuntime();
00174 
00175     /* Taking the unusual step of making all data public to simplify
00176     *  the implemetation of the "C" static debugger hooks.  
00177     */
00178 
00179 public:
00180     PRLock*         mLock;
00181     JSRuntime*      mRuntime;
00182     nsHashtable*    mFileTable;
00183     nsHashtable*    mScriptTable;
00184 };
00185 
00186 
00187 #endif /* xpctoolsprivate_h___ */