Line data Source code
1 : // This file (trace_lvl.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
2 : // Sep 17, 2019. "TERMS AND CONDITIONS" governing this file are in the README
3 : // or COPYING file. If you do not have such a file, one can be obtained by
4 : // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
5 : // $RCSfile: .emacs.gnu,v $
6 : // rev="$Revision: 1702 $$Date: 2025-01-28 12:48:14 -0600 (Tue, 28 Jan 2025) $";
7 :
8 : // test TRACE(lvl++,...) and TLOG(
9 :
10 : // g++ -Wall -g -o trace_lvl{,.cc} -I$TRACE_INC && ./trace_lvl
11 :
12 : #include <stdio.h> // printf
13 : #define TRACE_USE_STATIC_STREAMER 1 // the use of TraceStreamer in the file assumes this and precludes non-static
14 : #include "TRACE/trace.h"
15 :
16 0 : void sub1(int lvl)
17 : {
18 0 : TRACE(lvl++ & 1 ? lvl : 2, "trace lvl=%d", lvl - 1);
19 0 : if (lvl > 110) return;
20 : sub1(lvl);
21 : }
22 :
23 0 : void sub2(int lvl)
24 : {
25 0 : TLOG(lvl++ & 1 ? lvl : 2) << "log lvl=" << lvl - 1;
26 0 : if (lvl > 110) return;
27 : sub2(lvl);
28 : }
29 :
30 : int
31 0 : main(/* int argc
32 : , char *argv[]*/ )
33 : {
34 : // The following is just shoved in here as a place to help develop the TRACE_STREAMER macro
35 : #define _lvl TLVL_INFO
36 : #define nam_or_fmt 0
37 : #define fmt_or_nam ""
38 0 : static TRACE_THREAD_LOCAL TraceStreamer steamer;
39 0 : for (TSTREAMER_T_ _tlog_((tlvle_t)(_lvl), TRACE_GET_STATIC());
40 0 : _tlog_.once-- && TRACE_INIT_CHECK(TRACE_NAME) &&
41 0 : (_tlog_.TLOG2(nam_or_fmt, fmt_or_nam),
42 0 : ((*_tlog_.tidp != -1) || ((*_tlog_.tidp= (_tlog_.nn[0] ? trace_name2TID(_tlog_.nn) : traceTID)) != -1))) &&
43 0 : trace_do_streamer(&_tlog_);
44 0 : steamer.str())
45 0 : steamer.init(*_tlog_.tidp, _tlog_.lvl, _tlog_.flgs, __FILE__, __LINE__, __FUNCTION__, &_tlog_.tv, _tlog_.ins,
46 : &TRACE_LOG_FUNCTION)
47 0 : << "hello";
48 :
49 0 : int lvlx= 0x107; // testing conversion between int and uint8_t
50 0 : TRACEN("test", lvlx, "test");
51 0 : TRACEN_("test", lvlx,
52 : "test"
53 : << "ing");
54 0 : sub1(2);
55 0 : usleep(1000000);
56 0 : sub2(2);
57 0 : return (0);
58 : } // main
|