Back to index

lightning-sunbird  0.9+nobinonly
nsITimelineService.idl
Go to the documentation of this file.
00001 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsISupports.idl"
00039 
00040 %{C++
00041 #ifdef MOZ_TIMELINE
00042 %}
00043       
00077 [scriptable, uuid(93276790-3daf-11d5-b67d-000064657374)]
00078 interface nsITimelineService : nsISupports
00079 {
00084     void mark(in string text);
00085 
00090     void indent();
00091 
00095     void outdent();
00096 
00101     void enter(in string text);
00102     void leave(in string text);
00103 
00104     void startTimer(in string timerName);
00105 
00106     void stopTimer(in string timerName);
00107 
00108     void markTimer(in string timerName);
00109 
00110     void resetTimer(in string timerName);
00111 
00112     // Mark a timer, plus an additional comment
00113     void markTimerWithComment(in string timerName, in string comment);
00114 };
00115 
00116 %{C++
00117 #endif /* MOZ_TIMELINE */
00118 %}
00119 
00120 
00121 %{C++
00122 
00123 #ifdef MOZ_TIMELINE
00124 
00125 /*
00126  * These are equivalent to the corresponding nsITimelineService
00127  * methods, and can be called before XPCOM is initialized.
00128  */
00129 extern "C" NS_COM nsresult NS_TimelineMark(const char *text, ...);
00130 extern "C" NS_COM nsresult NS_TimelineForceMark(const char *text, ...);
00131 extern "C" NS_COM nsresult NS_TimelineStartTimer(const char *timerName);
00132 extern "C" NS_COM nsresult NS_TimelineStopTimer(const char *timerName);
00133 extern "C" NS_COM nsresult NS_TimelineResetTimer(const char *timerName);
00134 extern "C" NS_COM nsresult NS_TimelineMarkTimer(const char *timerName, const char *str=nsnull);
00135 extern "C" NS_COM nsresult NS_TimelineIndent();
00136 extern "C" NS_COM nsresult NS_TimelineOutdent();
00137 extern "C" NS_COM nsresult NS_TimelineEnter(const char *text);
00138 extern "C" NS_COM nsresult NS_TimelineLeave(const char *text);
00139 
00140 /*
00141  * Use these macros for the above calls so we can easily compile them
00142  * out.
00143  */
00144 #define NS_TIMELINE_MARK(text) NS_TimelineMark(text)
00145 #define NS_TIMELINE_MARKV(args) NS_TimelineMark args
00146 #define NS_TIMELINE_INDENT() NS_TimelineIndent()
00147 #define NS_TIMELINE_OUTDENT() NS_TimelineOutdent()
00148 #define NS_TIMELINE_ENTER(text) NS_TimelineEnter(text)
00149 #define NS_TIMELINE_LEAVE(text) NS_TimelineLeave(text)
00150 #define NS_TIMELINE_START_TIMER(timerName) NS_TimelineStartTimer(timerName)
00151 #define NS_TIMELINE_STOP_TIMER(timerName) NS_TimelineStopTimer(timerName)
00152 #define NS_TIMELINE_MARK_TIMER(timerName) NS_TimelineMarkTimer(timerName)
00153 #define NS_TIMELINE_RESET_TIMER(timerName) NS_TimelineResetTimer(timerName)
00154 #define NS_TIMELINE_MARK_TIMER1(timerName, str) NS_TimelineMarkTimer(timerName, str)
00155 
00156 /*
00157  * Helper class to time functions. Use only static strings.
00158  */
00159 class nsFunctionTimer {
00160 public:
00161     const char *mTimer;
00162     PRBool mMark;
00163     const char *mMarkStr;
00164     nsFunctionTimer(const char *timer, PRBool mark = PR_TRUE, const char *markStr = nsnull)
00165         : mTimer(timer), mMark(mark), mMarkStr(markStr)
00166     {
00167         NS_TIMELINE_START_TIMER(mTimer);
00168     }
00169 
00170     ~nsFunctionTimer()
00171     {
00172         NS_TIMELINE_STOP_TIMER(mTimer);
00173         if (mMark)
00174             if (mMarkStr)
00175                 NS_TIMELINE_MARK_TIMER1(mTimer, mMarkStr);
00176             else
00177                 NS_TIMELINE_MARK_TIMER(mTimer);
00178     }
00179 };
00180 
00181 /*
00182  * NS_TIMELINE_MARK_ macros for various data types.  Each of these
00183  * macros replaces "%s" in its "text" argument with a string
00184  * representation of its last argument.
00185  * 
00186  * Please feel free to add more NS_TIMELINE_MARK_ macros for
00187  * various data types so that code using NS_TIMELINE is uncluttered.
00188  * Don't forget the empty versions in the #else section below for
00189  * non-timeline builds.
00190  */
00191 #define NS_TIMELINE_MARK_URI(text, uri) \
00192     { \
00193         nsCAutoString spec; \
00194         if (uri) { \
00195             uri->GetSpec(spec); \
00196         } \
00197         if (!spec.IsEmpty()) { \
00198             NS_TimelineMark(text, spec.get()); \
00199         } else { \
00200             NS_TimelineMark(text, "??"); \
00201         } \
00202     }
00203 
00204 #define NS_TIMELINE_MARK_CHANNEL(text, channel) \
00205     { \
00206         nsCOMPtr<nsIURI> uri; \
00207         if (channel) { \
00208             channel->GetURI(getter_AddRefs(uri)); \
00209         } \
00210         NS_TIMELINE_MARK_URI(text, uri); \
00211     }
00212 
00213 #define NS_TIMELINE_MARK_LOADER(text, loader) \
00214     { \
00215         nsCOMPtr<nsIRequest> request; \
00216         loader->GetRequest(getter_AddRefs(request)); \
00217         nsCOMPtr<nsIChannel> channel(do_QueryInterface(request)); \
00218         NS_TIMELINE_MARK_CHANNEL(text, channel); \
00219     }
00220 #define NS_TIMELINE_MARK_FUNCTION(timer) nsFunctionTimer functionTimer(timer)
00221 #define NS_TIMELINE_MARK_FUNCTION1(timer, str) nsFunctionTimer functionTimer(timer, PR_TRUE, str)
00222 #define NS_TIMELINE_TIME_FUNCTION(timer) nsFunctionTimer functionTimer(timer, PR_FALSE) /* no mark, only time */
00223 
00224 #else /* !defined(MOZ_TIMELINE) */
00225 #define NS_TIMELINE_MARK(text)
00226 #define NS_TIMELINE_MARKV(args)
00227 #define NS_TIMELINE_INDENT()
00228 #define NS_TIMELINE_OUTDENT()
00229 #define NS_TIMELINE_START_TIMER(timerName)
00230 #define NS_TIMELINE_STOP_TIMER(timerName)
00231 #define NS_TIMELINE_MARK_TIMER(timerName)
00232 #define NS_TIMELINE_RESET_TIMER(timerName)
00233 #define NS_TIMELINE_MARK_TIMER1(timerName, str)
00234 #define NS_TIMELINE_ENTER(text)
00235 #define NS_TIMELINE_LEAVE(text)
00236 #define NS_TIMELINE_MARK_URI(text, uri)
00237 #define NS_TIMELINE_MARK_FUNCTION(timer)
00238 #define NS_TIMELINE_TIME_FUNCTION(timer)
00239 #define NS_TIMELINE_MARK_CHANNEL(text, channel)
00240 #define NS_TIMELINE_MARK_LOADER(text, loader);
00241 #endif /* defined(MOZ_TIMELINE) */ 
00242 %}