2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _TRACE_H
2N/A#define _TRACE_H
2N/A
2N/A
2N/A
2N/A#include <cstdarg>
2N/A#include <string>
2N/A#include <vector>
2N/A#include <stack>
2N/A#include <pthread.h>
2N/A
2N/A#ifndef MAX_MSG_LEN
2N/A#define MAX_MSG_LEN 2048
2N/A#endif
2N/A
2N/A/*
2N/A * @memo Tracing, Logging, and debugging facility
2N/A * @field ONE_FIELD_DESCRIPTION
2N/A *
2N/A * @doc The Trace class provides stack tracing, and basic
2N/A * logging/debugging facilities.
2N/A */
2N/Aclass Trace {
2N/Apublic:
2N/A Trace(std::string myRoutine);
2N/A
2N/A ~Trace();
2N/A
2N/A std::string label() {
2N/A return (routine);
2N/A }
2N/A
2N/A void noMemory() {
2N/A message(1, "Out of memory");
2N/A }
2N/A
2N/A void debug(const char *fmt, ...) {
2N/A char msg[MAX_MSG_LEN];
2N/A va_list ap;
2N/A va_start(ap, fmt);
2N/A vsnprintf(msg, sizeof (msg), fmt, ap);
2N/A message(LOG_DEBUG, msg);
2N/A va_end(ap);
2N/A }
2N/A
2N/A void genericIOError(const char *fmt, ...) {
2N/A char msg[MAX_MSG_LEN];
2N/A va_list ap;
2N/A va_start(ap, fmt);
2N/A vsnprintf(msg, sizeof (msg), fmt, ap);
2N/A message(IO_ERROR, msg);
2N/A va_end(ap);
2N/A }
2N/A
2N/A void internalError(const char *fmt, ...) {
2N/A char msg[MAX_MSG_LEN];
2N/A va_list ap;
2N/A va_start(ap, fmt);
2N/A vsnprintf(msg, sizeof (msg), fmt, ap);
2N/A message(INTERNAL_ERROR, msg);
2N/A va_end(ap);
2N/A }
2N/A
2N/A void userError(const char *fmt, ...) {
2N/A char msg[MAX_MSG_LEN];
2N/A va_list ap;
2N/A va_start(ap, fmt);
2N/A vsnprintf(msg, sizeof (msg), fmt, ap);
2N/A message(USER_ERROR, msg);
2N/A va_end(ap);
2N/A }
2N/A
2N/A void stackTrace();
2N/A
2N/Aprivate:
2N/A std::string routine;
2N/A pthread_t tid;
2N/A static const int INTERNAL_ERROR = 3;
2N/A static const int STACK_TRACE = 4;
2N/A static const int IO_ERROR = 5;
2N/A static const int USER_ERROR = 6;
2N/A static const int LOG_DEBUG = 7;
2N/A void message(int priority, const char *msg);
2N/A static std::vector<std::vector<Trace *> > stacks;
2N/A static std::vector<std::string> indent;
2N/A};
2N/A
2N/A#endif /* _TRACE_H */