/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ #ifndef timing_h__ #define timing_h__ #include "prtypes.h" #include "prtime.h" PR_BEGIN_EXTERN_C /** * Write a timing message to the timing log module, using * printf() formatting. The message will be pre-pended with * thread and timing information. Do not use this function directly; * rather, use the TIMING_MSG() macro, below. *

* This is based on NSPR2.0 logging, so it is not necessary to * terminate messages with a newline. * * @fmtstr The printf()-style format string. */ extern void TimingWriteMessage(const char* fmtstr, ...); /** * Queries whether the timing log is currently enabled. * * @return PR_TRUE if the timing log is currently enabled. */ extern PRBool TimingIsEnabled(void); /** * Sets the timing log's state. * * @param enabled PR_TRUE to enable, PR_FALSE to * disable. */ extern void TimingSetEnabled(PRBool enabled); /** * Start a unique "clock" with the given name. If the clock already * exists, this call will not re-start it. * * @param clock A C-string name for the clock. */ extern void TimingStartClock(const char* clock); /** * Stop the "clock" with the given name, returning the elapsed * time in result. This destroys the clock. *

* If the clock has already been stopped, this call will have * no effect. * * @param result If successful, returns the time recorded on * the clock (in microseconds). * @param clock The C-string name of the clock to stop. * @return PR_TRUE if the clock exists, was running, * and was successfully stopped. */ extern PRBool TimingStopClock(PRTime* result, const char* clock); /** * Return PR_TRUE if the clock with the specified * name exists and is running. */ extern PRBool TimingIsClockRunning(const char* clock); /** * Convert an elapsed time into a human-readable string. * * @param time An elapsed PRTime value. * @param buffer The buffer to use for conversion. * @param size The size of buffer. * @return A pointer to buffer. */ extern char* TimingElapsedTimeToString(PRTime time, char* buffer, PRUint32 size); PR_END_EXTERN_C #if defined(NO_TIMING) #define TIMING_MESSAGE(args) ((void) 0) #define TIMING_STARTCLOCK_NAME(op, name) ((void) 0) #define TIMING_STOPCLOCK_NAME(op, name, msg) ((void) 0) #define TIMING_STARTCLOCK_OBJECT(op, name) ((void) 0) #define TIMING_STOPCLOCK_OBJECT(op, name, msg) ((void) 0) #else /* !defined(NO_TIMING) */ /** * Use this macro to log timing information. It uses the * "double-parens" hack to allow you to pass arbitrarily formatted * strings; e.g., * *

 * TIMING_MESSAGE(("cache,%s,not found", url->address));
 * 
*/ #define TIMING_MESSAGE(args) TimingWriteMessage args /** * Use this macro to start a "clock" on an object using a pointer * to the object; e.g., * *
 * TIMING_STARTCLOCK_OBJECT("http:request", URL_s);
 * 
* * The clock should be uniquely identified by the op and * obj parameters. * * @param op A C-string that is the "operation" that is being * performed. * @param obj A pointer to an object. */ #define TIMING_STARTCLOCK_OBJECT(op, obj) \ do {\ char buf[256];\ PR_snprintf(buf, sizeof(buf), "%s,%08x", op, obj);\ TimingStartClock(buf);\ } while (0) /** * Use this macro to stop a "clock" on an object and print out * a message that indicates the total elapsed time on the clock; * e.g., * *
 * TIMING_STOPCLOCK_OBJECT("http:request", URL_s, "ok");
 * 
* * The op and obj parameters are used to * identify the clock to stop. * * @param op A C-string that is the "operation" that is being * performed. * @param obj A pointer to an object. * @param msg A message to include in the log entry. */ #define TIMING_STOPCLOCK_OBJECT(op, obj, msg) \ do {\ char buf[256];\ PR_snprintf(buf, sizeof(buf), "%s,%08x", op, obj);\ if (TimingIsClockRunning(buf)) {\ PRTime tmElapsed;\ PRUint32 nElapsed;\ TimingStopClock(&tmElapsed, buf);\ LL_L2UI(nElapsed, tmElapsed);\ TimingWriteMessage("clock,%s,%ld,%s", buf, nElapsed, msg);\ }\ } while (0) /** * Use this macro to start a "clock" on a "named" operation; e.g., * *
 * TIMING_STARTCLOCK_NAME("http:request", "http://www.cnn.com");
 * 
* * The clock should be uniquely identified by the op and * name parameters. * * @param op A C-string identifying the operation that is being * performed. * @param name A C-string that is the name for the timer. */ #define TIMING_STARTCLOCK_NAME(op, name) \ do {\ char buf[256];\ PR_snprintf(buf, sizeof(buf), "%s,%.64s", op, name);\ TimingStartClock(buf);\ } while (0) /** * Use this macro to stop a "clock" on a "named operation" and print out * a message that indicates the total elapsed time on the clock; * e.g., * *
 * TIMING_STOPCLOCK_NAME("http:request", "http://www.cnn.com", "ok");
 * 
* * The op and name parameters are used to * identify the clock to stop. * * @param op A C-string that is the "operation" that is being * performed. * @param name A C-string that is the name for the timer. * @param msg A message to include in the log entry. */ #define TIMING_STOPCLOCK_NAME(op, name, msg) \ do {\ char buf[256];\ PR_snprintf(buf, sizeof(buf), "%s,%.64s", op, name);\ if (TimingIsClockRunning(buf)) {\ PRTime tmElapsed;\ PRUint32 nElapsed;\ TimingStopClock(&tmElapsed, buf);\ LL_L2UI(nElapsed, tmElapsed);\ TimingWriteMessage("clock,%s,%ld,%s", buf, nElapsed, msg);\ }\ } while (0) #endif /* !defined(NO_TIMING) */ #endif /* timing_h__ */