Ongoing work to get macros for timing modules up and running. Not part of the build.

This commit is contained in:
nisheeth%netscape.com 1999-10-25 20:59:35 +00:00
Родитель 0c4c0d6d30
Коммит e7cf95d67c
3 изменённых файлов: 139 добавлений и 57 удалений

Просмотреть файл

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "stopwatch.h"
class nsStackBasedTimer {
public:
nsStackBasedTimer(Stopwatch* aStopwatch) { sw = aStopwatch; }
~nsStackBasedTimer() { if (sw) sw->Stop(); }
void Start(void) { if (sw) sw->Start(PR_FALSE); }
void Stop(void) { if (sw) sw->Stop(); }
void Reset() { if (sw) sw->Reset(); }
void SaveState() { if (sw) sw->SaveState(); }
void RestoreState() { if (sw) sw->RestoreState(); }
private:
Stopwatch* sw;
}

Просмотреть файл

@ -23,10 +23,17 @@
#ifdef MOZ_PERF_METRICS
#include "stopwatch.h"
#include "nsStackBasedTimer.h"
// This should be set from preferences at runtime. For now, make it a compile time flag.
#define ENABLE_DEBUG_OUTPUT PR_FALSE
// Uncomment and re-build to use the Mac Instrumentation SDK on a Mac.
// #define MOZ_TIMER_USE_MAC_ISDK
// Uncomment and re-build to use the
// #define MOZ_TIMER_USE_QUANTIFY
// Timer macros for the Mac
#ifdef XP_MAC
@ -34,7 +41,6 @@
#include "InstrumentationHelpers.h"
// Macro to create a timer on the stack.
# define MOZ_TIMER_CREATE(name, msg) \
static InstTraceClassRef name = 0; StInstrumentationLog __traceLog((msg), name)
@ -50,12 +56,68 @@
if (ENABLE_DEBUG_OUTPUT) printf msg
# define MOZ_TIMER_MACISDK_LOGDATA(msg, data) \
do { traceLog.LogMiddleEventWithData((s), (d)); } while (0)
do { traceLog.LogMiddleEventWithData((msg), (data)); } while (0)
#else
#define MOZ_TIMER_USE_STOPWATCH
#endif // MOZ_TIMER_USE_MAC_ISDK
#endif // XP_MAC
// Timer macros for Windows
#ifdef XP_WIN
#ifdef MOZ_TIMER_USE_QUANTIFY
#include "pure.h"
# define MOZ_TIMER_CREATE(name, msg)
# define MOZ_TIMER_RESET(name, msg) \
QuantifyClearData(); printf msg
# define MOZ_TIMER_START(name, msg) \
QuantifyStartRecordingData(); printf msg
# define MOZ_TIMER_STOP(name, msg) \
QuantifyStopRecordingData(); printf msg
# define MOZ_TIMER_SAVE(name, msg)
# define MOZ_TIMER_RESTORE(name, msg)
# define MOZ_TIMER_LOG(msg) \
do { \
char* str = __mysprintf msg; \
QuantifyAddAnnotation(str); \
delete [] str; \
} while (0)
# define MOZ_TIMER_DEBUGLOG(msg) \
if (ENABLE_DEBUG_OUTPUT) printf msg
# define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
#else
#define MOZ_TIMER_USE_STOPWATCH
#endif // MOZ_TIMER_USE_QUANTIFY
#endif // XP_WIN
// Timer macros for Unix
#ifdef XP_UNIX
#define MOZ_TIMER_USE_STOPWATCH
#endif // XP_UNIX
#ifdef MOZ_TIMER_USE_STOPWATCH
# define MOZ_TIMER_CREATE(name, msg) \
static Stopwatch __sw_name; nsFunctionTimer name(__sw_name, msg)
static Stopwatch __sw_name; nsStackBasedTimer name(&__sw_name)
# define MOZ_TIMER_RESET(name, msg) \
name.Reset(); printf msg
@ -79,64 +141,19 @@
if (ENABLE_DEBUG_OUTPUT) printf msg
# define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
#endif
#endif
// Timer macros for Windows
#ifdef XP_WIN
#endif
// Timer macros for Unix
#ifdef XP_UNIX
#endif
#endif // MOZ_TIMER_USE_STOPWATCH
#else
# define MOZ_TIMER_CREATE(id)
# define MOZ_TIMER_RESET(id, msg)
# define MOZ_TIMER_START(id, msg)
# define MOZ_TIMER_STOP(id, msg)
# define MOZ_TIMER_SAVE(id, msg)
# define MOZ_TIMER_RESTORE(id, msg)
# define MOZ_TIMER_LOG(id, msg)
# define MOZ_TIMER_CREATE(name, msg)
# define MOZ_TIMER_RESET(name, msg)
# define MOZ_TIMER_START(name, msg)
# define MOZ_TIMER_STOP(name, msg)
# define MOZ_TIMER_SAVE(name, msg)
# define MOZ_TIMER_RESTORE(name, msg)
# define MOZ_TIMER_LOG(name, msg)
# define MOZ_TIMER_DEBUGLOG(msg)
# define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
#endif
// To be removed.
#ifdef MOZ_PERF_METRICS
static PRLogModuleInfo* gLogStopwatchModule = PR_NewLogModule("timing");
#if 0
#define RAPTOR_TRACE_STOPWATCHES 0x1
#define RAPTOR_STOPWATCH_TRACE(_args) \
PR_BEGIN_MACRO \
PR_LOG(gLogStopwatchModule, RAPTOR_TRACE_STOPWATCHES, _args); \
PR_END_MACRO
#endif
#define RAPTOR_STOPWATCH_TRACE(_args) \
PR_BEGIN_MACRO \
printf _args ; \
PR_END_MACRO
#else
#define RAPTOR_TRACE_STOPWATCHES
#define RAPTOR_STOPWATCH_TRACE(_args)
#endif
#ifdef DEBUG_STOPWATCH
#define RAPTOR_STOPWATCH_DEBUGTRACE(_args) \
PR_BEGIN_MACRO \
printf _args ; \
PR_END_MACRO
#else
#define RAPTOR_STOPWATCH_DEBUGTRACE(_args)
#endif
#endif // MOZ_PERF_METRICS
#endif // __NSTIMER_H

Просмотреть файл

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTimer.h"
#include <stdarg.h>
char* __mysprintf(char* aFormatString, ... )
{
va_list argList;
int size = vprintf(aFormatString, argList);
char* buf = new(sizeof(char) * size);
vsprintf(buf, aFormatString, argList);
return buf;
}