1tracing(3) Library Functions Manual tracing(3)
2
3
4
6 tracing - Tracing
7
8 Runtime tracing is controlled by environment variables.
9
10 Tracing is switched on by setting MQTT_C_CLIENT_TRACE. A value of ON,
11 or stdout, prints to stdout, any other value is interpreted as a file
12 name to use.
13
14 The amount of trace detail is controlled with the
15 MQTT_C_CLIENT_TRACE_LEVEL environment variable - valid values are
16 ERROR, PROTOCOL, MINIMUM, MEDIUM and MAXIMUM (from least to most
17 verbose).
18
19 The variable MQTT_C_CLIENT_TRACE_MAX_LINES limits the number of lines
20 of trace that are output to a file. Two files are used at most, when
21 they are full, the last one is overwritten with the new trace entries.
22 The default size is 1000 lines.
23
24 MQTT Packet Tracing
25 A feature that can be very useful is printing the MQTT packets that are
26 sent and received. To achieve this, use the following environment
27 variable settings:
28
29 MQTT_C_CLIENT_TRACE=ON
30 MQTT_C_CLIENT_TRACE_LEVEL=PROTOCOL
31
32
33 The output you should see looks like this:
34
35 20130528 155936.813 3 stdout-subscriber -> CONNECT cleansession: 1 (0)
36 20130528 155936.813 3 stdout-subscriber <- CONNACK rc: 0
37 20130528 155936.813 3 stdout-subscriber -> SUBSCRIBE msgid: 1 (0)
38 20130528 155936.813 3 stdout-subscriber <- SUBACK msgid: 1
39 20130528 155941.818 3 stdout-subscriber -> DISCONNECT (0)
40
41
42 where the fields are:
43
44 1. date
45
46 2. time
47
48 3. socket number
49
50 4. client id
51
52 5. direction (-> from client to server, <- from server to client)
53
54 6. packet details
55
56 Default Level Tracing
57 This is an extract of a default level trace of a call to connect:
58
59 19700101 010000.000 (1152206656) (0)> MQTTClient_connect:893
60 19700101 010000.000 (1152206656) (1)> MQTTClient_connectURI:716
61 20130528 160447.479 Connecting to serverURI localhost:1883
62 20130528 160447.479 (1152206656) (2)> MQTTProtocol_connect:98
63 20130528 160447.479 (1152206656) (3)> MQTTProtocol_addressPort:48
64 20130528 160447.479 (1152206656) (3)< MQTTProtocol_addressPort:73
65 20130528 160447.479 (1152206656) (3)> Socket_new:599
66 20130528 160447.479 New socket 4 for localhost, port 1883
67 20130528 160447.479 (1152206656) (4)> Socket_addSocket:163
68 20130528 160447.479 (1152206656) (5)> Socket_setnonblocking:73
69 20130528 160447.479 (1152206656) (5)< Socket_setnonblocking:78 (0)
70 20130528 160447.479 (1152206656) (4)< Socket_addSocket:176 (0)
71 20130528 160447.479 (1152206656) (4)> Socket_error:95
72 20130528 160447.479 (1152206656) (4)< Socket_error:104 (115)
73 20130528 160447.479 Connect pending
74 20130528 160447.479 (1152206656) (3)< Socket_new:683 (115)
75 20130528 160447.479 (1152206656) (2)< MQTTProtocol_connect:131 (115)
76
77
78 where the fields are:
79
80 1. date
81
82 2. time
83
84 3. thread id
85
86 4. function nesting level
87
88 5. function entry (>) or exit (<)
89
90 6. function name : line of source code file
91
92 7. return value (if there is one)
93
94 Memory Allocation Tracing
95 Setting the trace level to maximum causes memory allocations and frees
96 to be traced along with the default trace entries, with messages like
97 the following:
98
99 20130528 161819.657 Allocating 16 bytes in heap at file /home/icraggs/workspaces/mqrtc/mqttv3c/src/MQTTPacket.c line 177 ptr 0x179f930
100
101 20130528 161819.657 Freeing 16 bytes in heap at file /home/icraggs/workspaces/mqrtc/mqttv3c/src/MQTTPacket.c line 201, heap use now 896 bytes
102
103
104 When the last MQTT client object is destroyed, if the trace is being
105 recorded and all memory allocated by the client library has not been
106 freed, an error message will be written to the trace. This can help
107 with fixing memory leaks. The message will look like this:
108
109 20130528 163909.208 Some memory not freed at shutdown, possible memory leak
110 20130528 163909.208 Heap scan start, total 880 bytes
111 20130528 163909.208 Heap element size 32, line 354, file /home/icraggs/workspaces/mqrtc/mqttv3c/src/MQTTPacket.c, ptr 0x260cb00
112 20130528 163909.208 Content
113 20130528 163909.209 Heap scan end
114
115
116Paho MQTT C Client Library Thu Jan 19 2023 tracing(3)