/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsTimelineService.h"
#include "prlong.h"
#include "prprf.h"
#include "prenv.h"
#include "plhash.h"
#include "prlock.h"
#include "prinit.h"
#include "prinrval.h"
#include "prthread.h"
#ifdef MOZ_TIMELINE
#ifdef XP_MAC
#endif
// Notes about threading:
// We avoid locks as we always use thread-local-storage.
// This means every other thread has its own private copy of
// data, and this thread can't re-enter (as our implemenation
// doesn't call back out anywhere). Thus, we can avoid locks!
// TLS index
class TimelineThreadData {
public:
int indent;
};
/* Implementation file */
/*
* Timer structure stored in a hash table to keep track of named
* timers.
*/
class nsTimelineServiceTimer {
public:
void start();
/*
* Caller passes in "now" rather than having us calculate it so
* that we can avoid including timer overhead in the time being
* measured.
*/
void reset();
private:
};
#define TIMER_CHECK_OWNER() \
"Timer used by non-owning thread")
{
}
{
}
{
if (!mRunning) {
}
mRunning++;
}
{
mRunning--;
if (mRunning == 0) {
}
}
{
mStart = 0;
mAccum = 0;
}
{
if (!mRunning) {
} else {
}
return accum;
}
{
if (!mRunning) {
} else {
}
return accum;
}
#ifdef XP_MAC
/*
* PR_Now() on the Mac only gives us a resolution of seconds. Using
* PR_IntervalNow() gives us better resolution. with the drawback that
* the timeline is only good for about six hours.
*
* PR_IntervalNow() occasionally exhibits discontinuities on Windows,
* so we only use it on the Mac. Bleah!
*/
{
return now;
}
#else
{
return PR_Now();
}
#endif
{
// First request for this thread - allocate it.
new_data = new TimelineThreadData();
if (!new_data)
goto done;
// Fill it
goto done;
"Why are we creating new state when disabled?");
}
done:
if (new_data) // eeek - error during creation!
delete new_data;
return data;
}
extern "C" {
static void ThreadDestruct (void *data);
static PRStatus TimelineInit(void);
};
{
if (data)
delete (TimelineThreadData *)data;
}
/*
* PRCallOnceFN that initializes stuff for the timing service.
*/
{
char *timeStr;
char *fileName;
#ifdef XP_MAC
#endif
// NS_TIMELINE_INIT_TIME only makes sense for the main thread, so if it
// exists, set it there. If not, let normal thread management code take
// care of setting the init time.
#ifdef XP_MAC
#endif
}
// Get the log file.
#ifdef XP_MAC
fileName = "timeline.txt";
#else
#endif
0666)) != NULL) {
timelineFD = fd;
"NOTE: due to asynchrony, the indentation that you see does"
" not necessarily correspond to nesting in the code.\n\n");
}
// Runtime disable of timeline
if (PR_GetEnv("NS_TIMELINE_ENABLE"))
return PR_SUCCESS;
}
{
}
{
}
if (amount < 0) {
amount = 0;
indent = 0;
}
while (amount--) {
*buf++ = ' ';
}
return buf;
}
{
// messages from multiple threads to garble one another.
}
/*
* Make this public if we need it.
*/
{
return NS_OK;
}
{
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
return NS_ERROR_NOT_AVAILABLE;
timer = new nsTimelineServiceTimer;
if (!timer)
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
/*
* including time spent in TLS and PL_HashTableLookup in the
* timer.
*/
return NS_ERROR_FAILURE;
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
}
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
}
if (!str)
else
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_FAILURE;
}
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
{
if (gTimelineDisabled)
return NS_ERROR_NOT_AVAILABLE;
return NS_ERROR_NOT_AVAILABLE;
return NS_OK;
}
{
return rv;
}
return NS_TimelineIndent();
}
{
return rv;
}
}
{
/* member initializers and constructor code */
}
/* void mark (in string text); */
{
return NS_TimelineMark(text);
}
/* void startTimer (in string timerName); */
{
return NS_TimelineStartTimer(timerName);
}
/* void stopTimer (in string timerName); */
{
return NS_TimelineStopTimer(timerName);
}
/* void markTimer (in string timerName); */
{
return NS_TimelineMarkTimer(timerName);
}
/* void markTimerWithComment(in string timerName, in string comment); */
{
}
/* void resetTimer (in string timerName); */
{
return NS_TimelineResetTimer(timerName);
}
/* void indent (); */
{
return NS_TimelineIndent();
}
/* void outdent (); */
{
return NS_TimelineOutdent();
}
/* void enter (in string text); */
{
return NS_TimelineEnter(text);
}
/* void leave (in string text); */
{
return NS_TimelineLeave(text);
}
#endif /* MOZ_TIMELINE */