1 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
2 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
3 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
4 //%% (c) Copyright 1993, 1994 Novell, Inc.
5 //%% $XConsortium: tt_trace_stream.C /main/3 1995/10/23 10:46:52 rswiston $
7 * @(#)tt_trace_stream.C 1.13 94/11/18
9 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
15 #include "util/tt_enumname.h"
16 #include "util/tt_port.h"
17 #include "util/tt_trace_stream.h"
18 #include "mp/mp_pattern.h"
19 #include "mp/mp_procid.h"
21 const int Tt_trace_buf_len = 4096;
23 _Tt_trace_stream::_Tt_trace_stream()
27 _Tt_trace_stream::_Tt_trace_stream(
30 _Tt_trace_parser( script )
35 _Tt_trace_stream::_Tt_trace_stream(
38 _Tt_trace_parser( scriptfd )
43 _Tt_trace_stream::~_Tt_trace_stream()
46 if (theFILE() != stderr) {
49 this->_Tt_ostream::operator=( (FILE *)0 );
56 // TT_WRN_STOPPED the script has turned off all tracing
57 // TT_ERR_INVALID syntax error in script
58 // TT_ERR_FILE could not open output file
61 _Tt_trace_stream::init()
65 return TT_ERR_INVALID;
67 if (! any_tracing()) {
68 return TT_WRN_STOPPED;
72 ::sprintf( buf, "%d:\t", getpid() );
76 if (sink_val().len() <= 0) {
77 this->_Tt_ostream::operator=( stderr );
79 FILE *fp = fopen( sink_val(), mode_val());
80 this->_Tt_ostream::operator=( fp );
82 _tt_syslog( 0, LOG_ERR, "tttracefile: %s: %m",
83 sink_val().operator const char *() );
86 fcntl(fileno(fp), F_SETFD, 1); /* Close on exec */
87 // Use line-buffering, in case of many writers
88 setvbuf( theFILE(), 0, _IOLBF, 0 );
94 _Tt_trace_stream::incr_indent() const
96 set_indent( indent().cat("\t") );
100 _Tt_trace_stream::decr_indent() const
102 set_indent( indent().left( indent().len() - 1 ) );
105 const _Tt_trace_stream &
107 _Tt_trace_stream &os,
111 if (os.attributes_val()) {
112 // prevents infinite recursion
113 os._Tt_ostream::operator <<( msg );
116 os << _tt_enumname( msg.message_class() );
117 os << " <" << msg.api_id() << "> ";
118 os << _tt_enumname( msg.state() );
119 char *conjunction = " because ";
120 switch (msg.state()) {
123 os << " by <" << msg.sender()->id() << ">";
126 conjunction = " result: ";
129 if (! msg.handler().is_null()) {
130 os << " by <" << msg.handler()->id() << ">";
132 os << conjunction << (Tt_status)msg.status();
137 os << " " << msg.op() << "()\n";