1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include
"nsISupports.idl"
45 * nsITimelineService is used to construct a timeline of program
46 * execution. The timeline is output to a file, either stderr or the
47 * value of the environment variable NS_TIMELINE_LOG_FILE. On the
48 * Mac, the timeline is output to the file named "timeline.txt". The
49 * reason it's different on the Mac is that the Mac environment
50 * initialization code happens after timeline initialization code.
52 * If NS_TIMELINE_INIT_TIME is set in the environment, that will be
53 * used as the time of startup; otherwise the current time when mark()
54 * is first called will be used.
56 * mark() is used to put marks on the timeline.
58 * indent() and outdent() are used to format the timeline a bit to
59 * show nesting. This doesn't produce perfect results in the face of
60 * asychrony and multiple threads.
62 * enter() and leave() are convenience functions that add marks to the
63 * timeline and do indentation.
65 * startTimer() and stopTimer() control named stop watches. If
66 * startTimer() is called more than once, an equal number of
67 * stopTimer() calls are needed to actually stop the timer. This
68 * makes these timers slightly useful in a threaded environment.
70 * markTimer() puts a mark on the timeline containing the total for
73 * Don't use nsITimelineService in C++ code; use the NS_TIMELINE
74 * macros instead. nsITimelineService exists so that JavaScript code
75 * can mark the timeline.
77 [scriptable
, uuid(93276790-3daf
-11d5
-b67d
-000064657374)]
78 interface nsITimelineService
: nsISupports
82 * Print "<elapsed time>: <text>\n" in the timeline log file.
84 void mark
(in string text
);
87 * causes subsequent marks to be indented for a more readable
93 * Causes subsequent marks to be outdented.
98 * enter/leave bracket code with "<text>..." and "...<text>" as
99 * well as indentation.
101 void enter
(in string text
);
102 void leave
(in string text
);
104 void startTimer
(in string timerName
);
106 void stopTimer
(in string timerName
);
108 void markTimer
(in string timerName
);
110 void resetTimer
(in string timerName
);
112 // Mark a timer, plus an additional comment
113 void markTimerWithComment
(in string timerName
, in string comment
);
117 #endif
/* MOZ_TIMELINE */
126 * These are equivalent to the corresponding nsITimelineService
127 * methods, and can be called before XPCOM is initialized.
129 extern
"C" NS_COM nsresult NS_TimelineMark
(const char *text
, ...
);
130 extern
"C" NS_COM nsresult NS_TimelineForceMark
(const char *text
, ...
);
131 extern
"C" NS_COM nsresult NS_TimelineStartTimer
(const char *timerName
);
132 extern
"C" NS_COM nsresult NS_TimelineStopTimer
(const char *timerName
);
133 extern
"C" NS_COM nsresult NS_TimelineResetTimer
(const char *timerName
);
134 extern
"C" NS_COM nsresult NS_TimelineMarkTimer
(const char *timerName
, const char *str
=nsnull
);
135 extern
"C" NS_COM nsresult NS_TimelineIndent
();
136 extern
"C" NS_COM nsresult NS_TimelineOutdent
();
137 extern
"C" NS_COM nsresult NS_TimelineEnter
(const char *text
);
138 extern
"C" NS_COM nsresult NS_TimelineLeave
(const char *text
);
141 * Use these macros for the above calls so we can easily compile them
144 #define NS_TIMELINE_MARK
(text
) NS_TimelineMark
(text
)
145 #define NS_TIMELINE_MARKV
(args
) NS_TimelineMark args
146 #define NS_TIMELINE_INDENT
() NS_TimelineIndent
()
147 #define NS_TIMELINE_OUTDENT
() NS_TimelineOutdent
()
148 #define NS_TIMELINE_ENTER
(text
) NS_TimelineEnter
(text
)
149 #define NS_TIMELINE_LEAVE
(text
) NS_TimelineLeave
(text
)
150 #define NS_TIMELINE_START_TIMER
(timerName
) NS_TimelineStartTimer
(timerName
)
151 #define NS_TIMELINE_STOP_TIMER
(timerName
) NS_TimelineStopTimer
(timerName
)
152 #define NS_TIMELINE_MARK_TIMER
(timerName
) NS_TimelineMarkTimer
(timerName
)
153 #define NS_TIMELINE_RESET_TIMER
(timerName
) NS_TimelineResetTimer
(timerName
)
154 #define NS_TIMELINE_MARK_TIMER1
(timerName
, str
) NS_TimelineMarkTimer
(timerName
, str
)
157 * Helper class to time functions. Use only static strings.
159 class nsFunctionTimer
{
163 const char *mMarkStr
;
164 nsFunctionTimer
(const char *timer
, PRBool mark
= PR_TRUE
, const char *markStr
= nsnull
)
165 : mTimer
(timer
), mMark
(mark
), mMarkStr
(markStr
)
167 NS_TIMELINE_START_TIMER
(mTimer
);
172 NS_TIMELINE_STOP_TIMER
(mTimer
);
175 NS_TIMELINE_MARK_TIMER1
(mTimer
, mMarkStr
);
177 NS_TIMELINE_MARK_TIMER
(mTimer
);
182 * NS_TIMELINE_MARK_ macros for various data types. Each of these
183 * macros replaces "%s" in its "text" argument with a string
184 * representation of its last argument.
186 * Please feel free to add more NS_TIMELINE_MARK_ macros for
187 * various data types so that code using NS_TIMELINE is uncluttered.
188 * Don't forget the empty versions in the #else section below for
189 * non-timeline builds.
191 #define NS_TIMELINE_MARK_URI
(text
, uri
) \
193 nsCAutoString spec
; \
195 uri
->GetSpec
(spec
); \
197 if
(!spec.IsEmpty
()) { \
198 NS_TimelineMark
(text
, spec.get
()); \
200 NS_TimelineMark
(text
, "??"); \
204 #define NS_TIMELINE_MARK_CHANNEL
(text
, channel
) \
206 nsCOMPtr
<nsIURI
> uri
; \
208 channel
->GetURI
(getter_AddRefs
(uri
)); \
210 NS_TIMELINE_MARK_URI
(text
, uri
); \
213 #define NS_TIMELINE_MARK_LOADER
(text
, loader
) \
215 nsCOMPtr
<nsIRequest
> request
; \
216 loader
->GetRequest
(getter_AddRefs
(request
)); \
217 nsCOMPtr
<nsIChannel
> channel
(do_QueryInterface
(request
)); \
218 NS_TIMELINE_MARK_CHANNEL
(text
, channel
); \
220 #define NS_TIMELINE_MARK_FUNCTION
(timer
) nsFunctionTimer functionTimer
(timer
)
221 #define NS_TIMELINE_MARK_FUNCTION1
(timer
, str
) nsFunctionTimer functionTimer
(timer
, PR_TRUE
, str
)
222 #define NS_TIMELINE_TIME_FUNCTION
(timer
) nsFunctionTimer functionTimer
(timer
, PR_FALSE
) /* no mark, only time */
224 #else
/* !defined(MOZ_TIMELINE) */
225 #define NS_TIMELINE_MARK
(text
)
226 #define NS_TIMELINE_MARKV
(args
)
227 #define NS_TIMELINE_INDENT
()
228 #define NS_TIMELINE_OUTDENT
()
229 #define NS_TIMELINE_START_TIMER
(timerName
)
230 #define NS_TIMELINE_STOP_TIMER
(timerName
)
231 #define NS_TIMELINE_MARK_TIMER
(timerName
)
232 #define NS_TIMELINE_RESET_TIMER
(timerName
)
233 #define NS_TIMELINE_MARK_TIMER1
(timerName
, str
)
234 #define NS_TIMELINE_ENTER
(text
)
235 #define NS_TIMELINE_LEAVE
(text
)
236 #define NS_TIMELINE_MARK_URI
(text
, uri
)
237 #define NS_TIMELINE_MARK_FUNCTION
(timer
)
238 #define NS_TIMELINE_TIME_FUNCTION
(timer
)
239 #define NS_TIMELINE_MARK_CHANNEL
(text
, channel
)
240 #define NS_TIMELINE_MARK_LOADER
(text
, loader
);
241 #endif
/* defined(MOZ_TIMELINE) */