1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Definitions for call trace related objects common to the service and
16 : // client libraries.
17 :
18 : #include "syzygy/trace/protocol/call_trace_defs.h"
19 :
20 : #include "base/logging.h"
21 : #include "base/strings/utf_string_conversions.h"
22 :
23 : // ETW Unique Identifiers.
24 : const GUID kCallTraceProvider = {
25 : // {06255E36-14B0-4e57-8964-2E3D675A0E77}
26 : 0x6255e36, 0x14b0, 0x4e57,
27 : { 0x89, 0x64, 0x2e, 0x3d, 0x67, 0x5a, 0xe, 0x77 } };
28 : const GUID kCallTraceEventClass = {
29 : // {44CAEED0-5432-4c2d-96FA-CEC50C742F01}
30 : 0x44caeed0, 0x5432, 0x4c2d,
31 : { 0x96, 0xfa, 0xce, 0xc5, 0xc, 0x74, 0x2f, 0x1 } };
32 : const GUID kSystemTraceControlGuid =
33 : // {9E814AAD-3204-11D2-9A82-006008A86939}
34 : { 0x9e814aad, 0x3204, 0x11d2,
35 : { 0x9a, 0x82, 0x00, 0x60, 0x08, 0xa8, 0x69, 0x39 } };
36 :
37 : // ETW flags and options
38 : const size_t kMinEtwBuffers = 15;
39 : const size_t kMinEtwBuffersPerProcessor = 3;
40 : const size_t kEtwBufferMultiplier = 5;
41 : const int kDefaultEtwTraceFlags = 0;
42 : const int kDefaultEtwKernelFlags = EVENT_TRACE_FLAG_PROCESS |
43 : EVENT_TRACE_FLAG_THREAD |
44 : EVENT_TRACE_FLAG_IMAGE_LOAD |
45 : EVENT_TRACE_FLAG_DISK_IO |
46 : EVENT_TRACE_FLAG_DISK_FILE_IO |
47 : EVENT_TRACE_FLAG_MEMORY_PAGE_FAULTS |
48 : EVENT_TRACE_FLAG_MEMORY_HARD_FAULTS |
49 : EVENT_TRACE_FLAG_FILE_IO;
50 :
51 : // Environment variable used for the RPC Instance ID suffix.
52 : const char kSyzygyRpcInstanceIdEnvVar[] = "SYZYGY_RPC_INSTANCE_ID";
53 : // Environment variable used to indicate that an RPC session is mandatory.
54 : const char kSyzygyRpcSessionMandatoryEnvVar[] =
55 : "SYZYGY_RPC_SESSION_MANDATORY";
56 :
57 : namespace {
58 :
59 : // Default RPC protocol and endpoint.
60 : const wchar_t* const kCallTraceRpcProtocol = L"ncalrpc";
61 : const wchar_t* const kCallTraceRpcEndpoint = L"syzygy-call-trace-svc";
62 : const wchar_t* const kCallTraceRpcMutex = L"syzygy-call-trace-svc-mutex";
63 : const wchar_t* const kCallTraceRpcEvent = L"syzygy-call-trace-svc-event";
64 :
65 : void MakeInstanceString(const base::StringPiece16& prefix,
66 : const base::StringPiece16& id,
67 E : std::wstring* output) {
68 E : DCHECK(output != NULL);
69 E : DCHECK(!prefix.empty());
70 :
71 E : output->assign(prefix.begin(), prefix.end());
72 E : if (!id.empty()) {
73 E : output->append(1, '-');
74 E : output->append(id.begin(), id.end());
75 : }
76 E : }
77 :
78 : } // namespace
79 :
80 : const TraceFileHeader::Signature TraceFileHeader::kSignatureValue = {
81 : 'S', 'Z', 'G', 'Y' };
82 :
83 E : void GetSyzygyCallTraceRpcProtocol(std::wstring* protocol) {
84 E : DCHECK(protocol != NULL);
85 E : protocol->assign(kCallTraceRpcProtocol);
86 E : }
87 :
88 : void GetSyzygyCallTraceRpcEndpoint(const base::StringPiece16& id,
89 E : std::wstring* endpoint) {
90 E : MakeInstanceString(kCallTraceRpcEndpoint, id, endpoint);
91 E : }
92 :
93 : void GetSyzygyCallTraceRpcMutexName(const base::StringPiece16& id,
94 E : std::wstring* mutex_name) {
95 E : MakeInstanceString(kCallTraceRpcMutex, id, mutex_name);
96 E : }
97 :
98 : void GetSyzygyCallTraceRpcEventName(const base::StringPiece16& id,
99 E : std::wstring* event_name) {
100 E : MakeInstanceString(kCallTraceRpcEvent, id, event_name);
101 E : }
|