The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / src / node_win32_etw_provider-inl.h @ b3a8e0da

History | View | Annotate | Download (10.9 KB)

1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21

    
22
#ifndef SRC_ETW_INL_H_
23
#define SRC_ETW_INL_H_
24

    
25
#include "node_win32_etw_provider.h"
26
#include "node_etw_provider.h"
27

    
28
namespace node {
29

    
30
using namespace v8;
31

    
32
// From node_win32_etw_provider.cc
33
extern REGHANDLE node_provider;
34
extern EventWriteFunc event_write;
35
extern int events_enabled;
36

    
37
#define ETW_WRITE_STRING_DATA(data_descriptor, data)                          \
38
  EventDataDescCreate(data_descriptor,                                        \
39
                      data,                                                   \
40
                      (strlen(data) + 1) * sizeof(char));
41

    
42
#define ETW_WRITE_INT32_DATA(data_descriptor, data)  \
43
  EventDataDescCreate(data_descriptor, data, sizeof(int32_t));
44

    
45
#define ETW_WRITE_INT64_DATA(data_descriptor, data)  \
46
  EventDataDescCreate(data_descriptor, data, sizeof(int64_t));
47

    
48
#define ETW_WRITE_ADDRESS_DATA(data_descriptor, data)  \
49
  EventDataDescCreate(data_descriptor, data, sizeof(intptr_t));
50

    
51
#define ETW_WRITE_INT16_DATA(data_descriptor, data)  \
52
  EventDataDescCreate(data_descriptor, data, sizeof(int16_t));
53

    
54
#define ETW_WRITE_WSTRING_DATA_LENGTH(data_descriptor, data, data_len_bytes)  \
55
  EventDataDescCreate(data_descriptor,                                        \
56
                      data,                                                   \
57
                      data_len_bytes);
58

    
59
#define ETW_WRITE_NET_CONNECTION(descriptors, conn)                           \
60
  ETW_WRITE_INT32_DATA(descriptors, &conn->fd);                               \
61
  ETW_WRITE_INT32_DATA(descriptors + 1, &conn->port);                         \
62
  ETW_WRITE_STRING_DATA(descriptors + 2, conn->remote);                       \
63
  ETW_WRITE_INT32_DATA(descriptors + 3, &conn->buffered);
64

    
65
#define ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req)                       \
66
  ETW_WRITE_STRING_DATA(descriptors, req->url);                               \
67
  ETW_WRITE_STRING_DATA(descriptors + 1, req->method);                        \
68
  ETW_WRITE_STRING_DATA(descriptors + 2, req->forwardedFor);
69

    
70
#define ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req)                       \
71
  ETW_WRITE_STRING_DATA(descriptors, req->url);                               \
72
  ETW_WRITE_STRING_DATA(descriptors + 1, req->method);
73

    
74
#define ETW_WRITE_GC(descriptors, type, flags)                                \
75
  ETW_WRITE_INT32_DATA(descriptors, &type);                                   \
76
  ETW_WRITE_INT32_DATA(descriptors + 1, &flags);
77

    
78
#define ETW_WRITE_V8ADDRESSCHANGE(descriptors, addr1, addr2)                  \
79
    ETW_WRITE_ADDRESS_DATA(descriptors, &addr1);                              \
80
    ETW_WRITE_ADDRESS_DATA(descriptors + 1, &addr2);
81

    
82
#define ETW_WRITE_JSMETHOD_LOADUNLOAD(descriptors,                            \
83
                                      context,                                \
84
                                      startAddr,                              \
85
                                      size,                                   \
86
                                      id,                                     \
87
                                      flags,                                  \
88
                                      rangeId,                                \
89
                                      sourceId,                               \
90
                                      line,                                   \
91
                                      col,                                    \
92
                                      name,                                   \
93
                                      name_len_bytes)                         \
94
    ETW_WRITE_ADDRESS_DATA(descriptors, &context);                            \
95
    ETW_WRITE_ADDRESS_DATA(descriptors + 1, &startAddr);                      \
96
    ETW_WRITE_INT64_DATA(descriptors + 2, &size);                             \
97
    ETW_WRITE_INT32_DATA(descriptors + 3, &id);                               \
98
    ETW_WRITE_INT16_DATA(descriptors + 4, &flags);                            \
99
    ETW_WRITE_INT16_DATA(descriptors + 5, &rangeId);                          \
100
    ETW_WRITE_INT64_DATA(descriptors + 6, &sourceId);                         \
101
    ETW_WRITE_INT32_DATA(descriptors + 7, &line);                             \
102
    ETW_WRITE_INT32_DATA(descriptors + 8, &col);                              \
103
    ETW_WRITE_WSTRING_DATA_LENGTH(descriptors + 9, name, name_len_bytes);
104

    
105

    
106
#define ETW_WRITE_EVENT(eventDescriptor, dataDescriptors)                     \
107
  DWORD status = event_write(node_provider,                                   \
108
                             &eventDescriptor,                                \
109
                             sizeof(dataDescriptors)/sizeof(*dataDescriptors),\
110
                             dataDescriptors);                                \
111
  assert(status == ERROR_SUCCESS);
112

    
113

    
114
void NODE_HTTP_SERVER_REQUEST(node_dtrace_http_server_request_t* req,
115
    node_dtrace_connection_t* conn, const char *remote, int port,
116
    const char *method, const char *url, int fd) {
117
  EVENT_DATA_DESCRIPTOR descriptors[7];
118
  ETW_WRITE_HTTP_SERVER_REQUEST(descriptors, req);
119
  ETW_WRITE_NET_CONNECTION(descriptors + 3, conn);
120
  ETW_WRITE_EVENT(NODE_HTTP_SERVER_REQUEST_EVENT, descriptors);
121
}
122

    
123

    
124
void NODE_HTTP_SERVER_RESPONSE(node_dtrace_connection_t* conn,
125
    const char *remote, int port, int fd) {
126
  EVENT_DATA_DESCRIPTOR descriptors[4];
127
  ETW_WRITE_NET_CONNECTION(descriptors, conn);
128
  ETW_WRITE_EVENT(NODE_HTTP_SERVER_RESPONSE_EVENT, descriptors);
129
}
130

    
131

    
132
void NODE_HTTP_CLIENT_REQUEST(node_dtrace_http_client_request_t* req,
133
    node_dtrace_connection_t* conn, const char *remote, int port,
134
    const char *method, const char *url, int fd) {
135
  EVENT_DATA_DESCRIPTOR descriptors[6];
136
  ETW_WRITE_HTTP_CLIENT_REQUEST(descriptors, req);
137
  ETW_WRITE_NET_CONNECTION(descriptors + 2, conn);
138
  ETW_WRITE_EVENT(NODE_HTTP_CLIENT_REQUEST_EVENT, descriptors);
139
}
140

    
141

    
142
void NODE_HTTP_CLIENT_RESPONSE(node_dtrace_connection_t* conn,
143
    const char *remote, int port, int fd) {
144
  EVENT_DATA_DESCRIPTOR descriptors[4];
145
  ETW_WRITE_NET_CONNECTION(descriptors, conn);
146
  ETW_WRITE_EVENT(NODE_HTTP_CLIENT_RESPONSE_EVENT, descriptors);
147
}
148

    
149

    
150
void NODE_NET_SERVER_CONNECTION(node_dtrace_connection_t* conn,
151
    const char *remote, int port, int fd) {
152
  EVENT_DATA_DESCRIPTOR descriptors[4];
153
  ETW_WRITE_NET_CONNECTION(descriptors, conn);
154
  ETW_WRITE_EVENT(NODE_NET_SERVER_CONNECTION_EVENT, descriptors);
155
}
156

    
157

    
158
void NODE_NET_STREAM_END(node_dtrace_connection_t* conn,
159
    const char *remote, int port, int fd) {
160
  EVENT_DATA_DESCRIPTOR descriptors[4];
161
  ETW_WRITE_NET_CONNECTION(descriptors, conn);
162
  ETW_WRITE_EVENT(NODE_NET_STREAM_END_EVENT, descriptors);
163
}
164

    
165

    
166
void NODE_GC_START(GCType type, GCCallbackFlags flags) {
167
  if (events_enabled > 0) {
168
    EVENT_DATA_DESCRIPTOR descriptors[2];
169
    ETW_WRITE_GC(descriptors, type, flags);
170
    ETW_WRITE_EVENT(NODE_GC_START_EVENT, descriptors);
171
  }
172
}
173

    
174

    
175
void NODE_GC_DONE(GCType type, GCCallbackFlags flags) {
176
  if (events_enabled > 0) {
177
    EVENT_DATA_DESCRIPTOR descriptors[2];
178
    ETW_WRITE_GC(descriptors, type, flags);
179
    ETW_WRITE_EVENT(NODE_GC_DONE_EVENT, descriptors);
180
  }
181
}
182

    
183

    
184
void NODE_V8SYMBOL_REMOVE(const void* addr1, const void* addr2) {
185
  if (events_enabled > 0) {
186
    EVENT_DATA_DESCRIPTOR descriptors[2];
187
    ETW_WRITE_V8ADDRESSCHANGE(descriptors, addr1, addr2);
188
    ETW_WRITE_EVENT(NODE_V8SYMBOL_REMOVE_EVENT, descriptors);
189
  }
190
}
191

    
192

    
193
void NODE_V8SYMBOL_MOVE(const void* addr1, const void* addr2) {
194
  if (events_enabled > 0) {
195
    EVENT_DATA_DESCRIPTOR descriptors[2];
196
    ETW_WRITE_V8ADDRESSCHANGE(descriptors, addr1, addr2);
197
    ETW_WRITE_EVENT(NODE_V8SYMBOL_MOVE_EVENT, descriptors);
198
  }
199
}
200

    
201

    
202
void NODE_V8SYMBOL_RESET() {
203
  if (events_enabled > 0) {
204
    int val = 0;
205
    EVENT_DATA_DESCRIPTOR descriptors[1];
206
    ETW_WRITE_INT32_DATA(descriptors, &val);
207
    ETW_WRITE_EVENT(NODE_V8SYMBOL_RESET_EVENT, descriptors);
208
  }
209
}
210

    
211
#define SETSYMBUF(s)  \
212
  wcscpy(symbuf, s);  \
213
  symbol_len = ARRAY_SIZE(s) - 1;
214

    
215
void NODE_V8SYMBOL_ADD(LPCSTR symbol,
216
                       int symbol_len,
217
                       const void* addr1,
218
                       int len) {
219
  if (events_enabled > 0) {
220
    wchar_t symbuf[128];
221
    if (symbol == NULL) {
222
      SETSYMBUF(L"NULL");
223
    } else {
224
      symbol_len = MultiByteToWideChar(CP_ACP, 0, symbol, symbol_len, symbuf, 128);
225
      if (symbol_len == 0) {
226
        SETSYMBUF(L"Invalid");
227
      } else {
228
        if (symbol_len > 127) {
229
          symbol_len = 127;
230
        }
231
        symbuf[symbol_len] = L'\0';
232
      }
233
    }
234
    void* context = NULL;
235
    INT64 size = (INT64)len;
236
    INT32 id = (INT32)addr1;
237
    INT16 flags = 0;
238
    INT16 rangeid = 1;
239
    INT32 col = 1;
240
    INT32 line = 1;
241
    INT64 sourceid = 0;
242
    EVENT_DATA_DESCRIPTOR descriptors[10];
243
    ETW_WRITE_JSMETHOD_LOADUNLOAD(descriptors,
244
                                  context,
245
                                  addr1,
246
                                  size,
247
                                  id,
248
                                  flags,
249
                                  rangeid,
250
                                  sourceid,
251
                                  line,
252
                                  col,
253
                                  symbuf,
254
                                  symbol_len * sizeof(symbuf[0]));
255
    ETW_WRITE_EVENT(MethodLoad, descriptors);
256
  }
257
}
258
#undef SETSYMBUF
259

    
260

    
261
bool NODE_HTTP_SERVER_REQUEST_ENABLED() { return events_enabled > 0; }
262
bool NODE_HTTP_SERVER_RESPONSE_ENABLED() { return events_enabled > 0; }
263
bool NODE_HTTP_CLIENT_REQUEST_ENABLED() { return events_enabled > 0; }
264
bool NODE_HTTP_CLIENT_RESPONSE_ENABLED() { return events_enabled > 0; }
265
bool NODE_NET_SERVER_CONNECTION_ENABLED() { return events_enabled > 0; }
266
bool NODE_NET_STREAM_END_ENABLED() { return events_enabled > 0; }
267
bool NODE_NET_SOCKET_READ_ENABLED() { return events_enabled > 0; }
268
bool NODE_NET_SOCKET_WRITE_ENABLED() { return events_enabled > 0; }
269
bool NODE_V8SYMBOL_ENABLED() { return events_enabled > 0; }
270
}
271
#endif  // SRC_ETW_INL_H_