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.cc @ 35a1421e

History | View | Annotate | Download (2.68 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
#include "node_dtrace.h"
23
#include "node_win32_etw_provider.h"
24
#include "node_etw_provider.h"
25

    
26
namespace node {
27

    
28
using namespace v8;
29

    
30
HMODULE advapi;
31
REGHANDLE node_provider;
32
EventRegisterFunc event_register;
33
EventUnregisterFunc event_unregister;
34
EventWriteFunc event_write;
35
int events_enabled;
36

    
37
// This callback is called by ETW when consumers of our provider
38
// are enabled or disabled.
39
// The callback is dispatched on ETW thread.
40
void NTAPI etw_events_enable_callback(
41
  LPCGUID SourceId,
42
  ULONG IsEnabled,
43
  UCHAR Level,
44
  ULONGLONG MatchAnyKeyword,
45
  ULONGLONG MatchAllKeywords,
46
  PEVENT_FILTER_DESCRIPTOR FilterData,
47
  PVOID CallbackContext) {
48
  if (IsEnabled) {
49
    events_enabled++;
50
  } else {
51
    events_enabled--;
52
  }
53
}
54

    
55

    
56
void init_etw() {
57
  events_enabled = 0;
58

    
59
  advapi = LoadLibrary("advapi32.dll");
60
  if (advapi) {
61
    event_register = (EventRegisterFunc)
62
      GetProcAddress(advapi, "EventRegister");
63
    event_unregister = (EventUnregisterFunc)
64
      GetProcAddress(advapi, "EventUnregister");
65
    event_write = (EventWriteFunc)GetProcAddress(advapi, "EventWrite");
66

    
67
    if (event_register) {    
68
      DWORD status = event_register(&NODE_ETW_PROVIDER,
69
                                    etw_events_enable_callback,
70
                                    NULL,
71
                                    &node_provider);
72
      assert(status == ERROR_SUCCESS);
73
    }
74
  }
75
}
76

    
77

    
78
void shutdown_etw() {
79
  if (advapi && event_unregister && node_provider) {
80
    event_unregister(node_provider);
81
    node_provider = 0;
82
  }
83

    
84
  events_enabled = 0;
85

    
86
  if (advapi) {
87
    FreeLibrary(advapi);
88
    advapi = NULL;
89
  }
90
}
91
}