forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genXplatLttng.py
765 lines (596 loc) · 25.6 KB
/
genXplatLttng.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
##
## Licensed to the .NET Foundation under one or more agreements.
## The .NET Foundation licenses this file to you under the MIT license.
## See the LICENSE file in the project root for more information.
##
## Sample LTTng Instrumentation code that is generated:
##
## HEADER:
## #define GCFinalizersEnd_TRACEPOINT_ARGS \
##TP_ARGS(\
## const unsigned int ,Count\
##)
##TRACEPOINT_EVENT_CLASS(
## DotNETRuntime,
## GCFinalizersEnd,
## GCFinalizersEnd_TRACEPOINT_ARGS,
## TP_FIELDS(
## ctf_integer(unsigned int, Count, Count)
## )
##)
##
##CPP :
##
##extern "C" BOOL EventXplatEnabledGCFinalizersEnd(){ return TRUE;}
##extern "C" ULONG FireEtXplatGCFinalizersEnd(
## const unsigned int Count
##)
##{
## ULONG Error = ERROR_WRITE_FAULT;
## if (!EventXplatEnabledGCFinalizersEnd()){ return ERROR_SUCCESS;}
##
##
## tracepoint(
## DotNETRuntime,
## GCFinalizersEnd,
## Count
## );
## Error = ERROR_SUCCESS;
##
##return Error;
##}
##
###define GCFinalizersEndT_TRACEPOINT_INSTANCE(name) \
##TRACEPOINT_EVENT_INSTANCE(\
## DotNETRuntime,\
## GCFinalizersEnd,\
## name ,\
## GCFinalizersEnd_TRACEPOINT_ARGS \
##)
#
import os
from genXplatEventing import *
stdprolog="""
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/******************************************************************
DO NOT MODIFY. AUTOGENERATED FILE.
This file is generated using the logic from <root>/src/scripts/genXplatLttng.py
******************************************************************/
"""
stdprolog_cmake="""
#
#
#******************************************************************
#DO NOT MODIFY. AUTOGENERATED FILE.
#This file is generated using the logic from <root>/src/scripts/genXplatLttng.py
#******************************************************************
"""
specialCaseSizes = { "BulkType" : { "Values" : "Values_ElementSize" }, "GCBulkRootCCW" : { "Values" : "Values_ElementSize" }, "GCBulkRCW" : { "Values" : "Values_ElementSize" }, "GCBulkRootStaticVar" : { "Values" : "Values_ElementSize" } }
lttngDataTypeMapping ={
#constructed types
"win:null" :" ",
"win:Int64" :"const __int64",
"win:ULong" :"const ULONG",
"win:count" :"*",
"win:Struct" :"const BYTE *",
#actual spec
"win:GUID" :"const int",
"win:AnsiString" :"const char*",
"win:UnicodeString" :"const char*",
"win:Double" :"const double",
"win:Int32" :"const signed int",
"win:Boolean" :"const BOOL",
"win:UInt64" :"const unsigned __int64",
"win:UInt32" :"const unsigned int",
"win:UInt16" :"const unsigned short",
"win:UInt8" :"const unsigned char",
"win:Pointer" :"const size_t",
"win:Binary" :"const BYTE"
}
ctfDataTypeMapping ={
#constructed types
"win:Int64" :"ctf_integer",
"win:ULong" :"ctf_integer",
"win:count" :"ctf_sequence",
"win:Struct" :"ctf_sequence",
#actual spec
"win:GUID" :"ctf_sequence",
"win:AnsiString" :"ctf_string",
"win:UnicodeString" :"ctf_string",
"win:Double" :"ctf_float",
"win:Int32" :"ctf_integer",
"win:Boolean" :"ctf_integer",
"win:UInt64" :"ctf_integer",
"win:UInt32" :"ctf_integer",
"win:UInt16" :"ctf_integer",
"win:UInt8" :"ctf_integer", #actually a character
"win:Pointer" :"ctf_integer",
"win:Binary" :"ctf_sequence"
}
MAX_LTTNG_ARGS = 9
def shouldPackTemplate(template):
return template.num_params > MAX_LTTNG_ARGS or len(template.structs) > 0 or len(template.arrays) > 0
def generateArgList(template):
header = "TP_ARGS( \\\n"
footer = ")\n"
if "MethodILToNative" in template.name:
pass
if shouldPackTemplate(template):
args = " const unsigned int, length, \\\n"
args += " const char *, __data__ \\\n"
else:
fnSig = template.signature
args = []
for params in fnSig.paramlist:
fnparam = fnSig.getParam(params)
wintypeName = fnparam.winType
typewName = lttngDataTypeMapping[wintypeName]
winCount = fnparam.count
countw = lttngDataTypeMapping[winCount]
arg = " " + typewName
if countw != " ":
arg += countw
arg += ", " + fnparam.name
args.append(arg)
args = ", \\\n".join(args) + " \\\n"
return header + args + footer
def generateFieldList(template):
header = " " + " TP_FIELDS(\n"
footer = "\n )\n)\n"
if shouldPackTemplate(template):
field_list = " ctf_integer(ULONG, length, length)\n"
field_list += " ctf_sequence(char, __data__, __data__, ULONG, length)"
else:
fnSig = template.signature
field_list = []
for params in fnSig.paramlist:
fnparam = fnSig.getParam(params)
wintypeName = fnparam.winType
winCount = fnparam.count
countw = lttngDataTypeMapping[winCount]
typewName = lttngDataTypeMapping[wintypeName].replace("const ","")
field_body = None
ctf_type = None
varname = fnparam.name
if fnparam.prop:
#this is an explicit struct treat as a sequence
ctf_type = "ctf_sequence"
sizeofseq = fnparam.prop
field_body = ", ".join((typewName, varname, varname, "size_t", sizeofseq))
else:
ctf_type = ctfDataTypeMapping[wintypeName]
if ctf_type == "ctf_string":
field_body = ", ".join((varname, varname))
elif ctf_type == "ctf_integer" or ctf_type == "ctf_float":
field_body = ", ".join((typewName, varname, varname))
elif ctf_type == "ctf_sequence":
raise Exception("ctf_sequence needs to have its memory expilicitly laid out")
else:
raise Exception("no such ctf intrinsic called: " + ctf_type)
field_list.append(" %s(%s)" % (ctf_type, field_body))
field_list = "\n".join(field_list)
return header + field_list + footer
def generateLttngHeader(providerName, allTemplates, eventNodes):
lTTngHdr = []
for templateName in allTemplates:
template = allTemplates[templateName]
fnSig = allTemplates[templateName].signature
lTTngHdr.append("\n#define " + templateName + "_TRACEPOINT_ARGS \\\n")
#TP_ARGS
tp_args = generateArgList(template)
lTTngHdr.append(tp_args)
#TP_EVENT_CLASS
lTTngHdr.append("TRACEPOINT_EVENT_CLASS(\n")
lTTngHdr.append(" " + providerName + ",\n")
lTTngHdr.append(" " + templateName + ",\n")
lTTngHdr.append(" " + templateName + "_TRACEPOINT_ARGS,\n")
#TP_FIELDS
tp_fields = generateFieldList(template)
lTTngHdr.append(tp_fields)
# Macro for defining event instance
lTTngHdr.append("\n#define " + templateName)
lTTngHdr.append("""T_TRACEPOINT_INSTANCE(name) \\
TRACEPOINT_EVENT_INSTANCE(\\
""")
lTTngHdr.append(" "+providerName + ",\\\n")
lTTngHdr.append(" " + templateName + ",\\\n")
lTTngHdr.append(" name ,\\\n")
lTTngHdr.append(" " + templateName + "_TRACEPOINT_ARGS \\\n)")
#add an empty template node to just specify the event name in the event stream
lTTngHdr.append("\n\nTRACEPOINT_EVENT_CLASS(\n")
lTTngHdr.append(" " + providerName + ",\n")
lTTngHdr.append(" emptyTemplate ,\n")
lTTngHdr.append(""" TP_ARGS(),
TP_FIELDS()
)
#define T_TRACEPOINT_INSTANCE(name) \\
TRACEPOINT_EVENT_INSTANCE(\\
""")
lTTngHdr.append(" " + providerName + ",\\\n")
lTTngHdr.append(" emptyTemplate,\\\n")
lTTngHdr.append(""" name ,\\
TP_ARGS()\\
)""")
#end of empty template
# create the event instance in headers
lTTngHdr.append("\n")
for eventNode in eventNodes:
eventName = eventNode.getAttribute('symbol');
templateName = eventNode.getAttribute('template');
if not eventName :
raise Exception(eventNode + " event does not have a symbol")
if not templateName:
lTTngHdr.append("T_TRACEPOINT_INSTANCE(")
lTTngHdr.append(eventName +")\n")
continue
subevent = templateName.replace(templateName,'')
lTTngHdr.append(templateName)
lTTngHdr.append("T_TRACEPOINT_INSTANCE(")
lTTngHdr.append(eventName + subevent + ")\n")
lTTngHdr.append("\n#endif /* LTTNG_CORECLR_H")
lTTngHdr.append(providerName + " */\n")
lTTngHdr.append("#include <lttng/tracepoint-event.h>")
return ''.join(lTTngHdr)
def generateMethodBody(template, providerName, eventName):
#emit code to init variables convert unicode to ansi string
result = []
fnSig = template.signature
for paramName in fnSig.paramlist:
fnparam = fnSig.getParam(paramName)
paramname = fnparam.name
if fnparam.winType == "win:UnicodeString":
result.append(" INT " + paramname + "_path_size = -1;\n")
result.append(" PathCharString " + paramname + "_PS;\n")
result.append(" INT " + paramname + "_full_name_path_size")
result.append(" = (PAL_wcslen(" + paramname + ") + 1)*sizeof(WCHAR);\n")
result.append(" CHAR* " + paramname + "_full_name = ")
result.append(paramname + "_PS.OpenStringBuffer(" + paramname + "_full_name_path_size );\n")
result.append(" if (" + paramname + "_full_name == NULL )")
result.append(" { return ERROR_WRITE_FAULT; }\n")
result.append("\n")
#emit tracepoints
fnSig = template.signature
if not shouldPackTemplate(template):
linefnbody = [" do_tracepoint(%s,\n %s" % (providerName, eventName)]
for params in fnSig.paramlist:
fnparam = fnSig.getParam(params)
wintypeName = fnparam.winType
winCount = fnparam.count
paramname = fnparam.name
ctf_type = ctfDataTypeMapping.get(winCount)
line = " "
if not ctf_type:
ctf_type = ctfDataTypeMapping[wintypeName]
if ctf_type == "ctf_string" and wintypeName == "win:UnicodeString":
#emit code to convert unicode to ansi string
result.append(" " + paramname+ "_path_size = WideCharToMultiByte( CP_ACP, 0, ")
result.append(paramname + ", -1, ")
result.append(paramname + "_full_name, ")
result.append(paramname + "_full_name_path_size, NULL, NULL );\n")
result.append(" _ASSERTE(" +paramname+ "_path_size < " )
result.append(paramname + "_full_name_path_size );\n ")
result.append(paramname + "_PS.CloseBuffer(" + paramname + "_path_size );\n")
result.append(" if( " + paramname + "_path_size == 0 ){ return ERROR_INVALID_PARAMETER; }\n")
line += paramname + "_full_name"
linefnbody.append(line)
continue
elif ctf_type == "ctf_sequence" or wintypeName == "win:Pointer":
line += "(" + lttngDataTypeMapping[wintypeName]
if not lttngDataTypeMapping[winCount] == " ":
line += lttngDataTypeMapping[winCount]
line += ") "
linefnbody.append(line + paramname)
else:
linefnbody.append(line + paramname)
linefnbody = ",\n".join(linefnbody) + ");\n"
result.append(linefnbody)
return ''.join(result)
else:
header = """
char stackBuffer[%s];
char *buffer = stackBuffer;
int offset = 0;
int size = %s;
bool fixedBuffer = true;
bool success = true;
""" % (template.estimated_size, template.estimated_size)
footer = """
if (!fixedBuffer)
delete[] buffer;
"""
pack_list = []
for paramName in fnSig.paramlist:
parameter = fnSig.getParam(paramName)
if paramName in template.structs:
size = "(int)%s_ElementSize * (int)%s" % (paramName, parameter.prop)
if template.name in specialCaseSizes and paramName in specialCaseSizes[template.name]:
size = "(int)(%s)" % specialCaseSizes[template.name][paramName]
pack_list.append(" success &= WriteToBuffer((const BYTE *)%s, %s, buffer, offset, size, fixedBuffer);" % (paramName, size))
elif paramName in template.arrays:
size = "sizeof(%s) * (int)%s" % (lttngDataTypeMapping[parameter.winType], parameter.prop)
if template.name in specialCaseSizes and paramName in specialCaseSizes[template.name]:
size = "(int)(%s)" % specialCaseSizes[template.name][paramName]
pack_list.append(" success &= WriteToBuffer((const BYTE *)%s, %s, buffer, offset, size, fixedBuffer);" % (paramName, size))
elif parameter.winType == "win:GUID":
pack_list.append(" success &= WriteToBuffer(*%s, buffer, offset, size, fixedBuffer);" % (parameter.name,))
else:
pack_list.append(" success &= WriteToBuffer(%s, buffer, offset, size, fixedBuffer);" % (parameter.name,))
code = "\n".join(pack_list) + "\n\n"
tracepoint = """ if (!success)
{
if (!fixedBuffer)
delete[] buffer;
return ERROR_WRITE_FAULT;
}
do_tracepoint(%s, %s, offset, buffer);\n""" % (providerName, eventName)
return header + code + tracepoint + footer
def generateLttngTpProvider(providerName, eventNodes, allTemplates):
lTTngImpl = []
for eventNode in eventNodes:
eventName = eventNode.getAttribute('symbol')
templateName = eventNode.getAttribute('template')
#generate EventXplatEnabled
lTTngImpl.append("extern \"C\" BOOL EventXplatEnabled%s(){ return tracepoint_enabled(%s, %s); }\n\n" % (eventName, providerName, eventName))
#generate FireEtw functions
fnptype = []
linefnptype = []
fnptype.append("extern \"C\" ULONG FireEtXplat")
fnptype.append(eventName)
fnptype.append("(\n")
if templateName:
template = allTemplates[templateName]
else:
template = None
if template:
fnSig = template.signature
for paramName in fnSig.paramlist:
fnparam = fnSig.getParam(paramName)
wintypeName = fnparam.winType
typewName = palDataTypeMapping[wintypeName]
winCount = fnparam.count
countw = palDataTypeMapping[winCount]
if paramName in template.structs:
linefnptype.append("%sint %s_ElementSize,\n" % (lindent, paramName))
linefnptype.append(lindent)
linefnptype.append(typewName)
if countw != " ":
linefnptype.append(countw)
linefnptype.append(" ")
linefnptype.append(fnparam.name)
linefnptype.append(",\n")
if len(linefnptype) > 0 :
del linefnptype[-1]
fnptype.extend(linefnptype)
fnptype.append(")\n{\n")
lTTngImpl.extend(fnptype)
#start of fn body
lTTngImpl.append(" if (!EventXplatEnabled%s())\n" % (eventName,))
lTTngImpl.append(" return ERROR_SUCCESS;\n")
if template:
result = generateMethodBody(template, providerName, eventName)
lTTngImpl.append(result)
lTTngImpl.append("\n return ERROR_SUCCESS;\n}\n\n")
return ''.join(lTTngImpl)
def generateLttngFiles(etwmanifest,eventprovider_directory):
eventprovider_directory = eventprovider_directory + "/"
tree = DOM.parse(etwmanifest)
#keep these relative
tracepointprovider_directory = "tracepointprovider"
lttng_directory = "lttng"
lttngevntprovPre = lttng_directory + "/eventprov"
lttngevntprovTpPre = lttng_directory + "/traceptprov"
if not os.path.exists(eventprovider_directory):
os.makedirs(eventprovider_directory)
if not os.path.exists(eventprovider_directory + lttng_directory):
os.makedirs(eventprovider_directory + lttng_directory)
if not os.path.exists(eventprovider_directory + tracepointprovider_directory):
os.makedirs(eventprovider_directory + tracepointprovider_directory)
#Top level Cmake
with open(eventprovider_directory + "CMakeLists.txt", 'w') as topCmake:
topCmake.write(stdprolog_cmake + "\n")
topCmake.write("""cmake_minimum_required(VERSION 2.8.12.2)
project(eventprovider)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-DPAL_STDCPP_COMPAT=1)
include_directories(${COREPAL_SOURCE_DIR}/inc/rt)
include_directories(lttng)
add_library(eventprovider
STATIC
""")
for providerNode in tree.getElementsByTagName('provider'):
providerName = providerNode.getAttribute('name')
providerName = providerName.replace("Windows-",'')
providerName = providerName.replace("Microsoft-",'')
providerName_File = providerName.replace('-','')
providerName_File = providerName_File.lower()
topCmake.write(' "%s%s.cpp"\n' % (lttngevntprovPre, providerName_File))
topCmake.write(' "%shelpers.cpp"\n' % (lttngevntprovPre,))
topCmake.write(""")
add_subdirectory(tracepointprovider)
# Install the static eventprovider library
install(TARGETS eventprovider DESTINATION lib)
""")
#TracepointProvider Cmake
with open(eventprovider_directory + tracepointprovider_directory + "/CMakeLists.txt", 'w') as tracepointprovider_Cmake:
tracepointprovider_Cmake.write(stdprolog_cmake + "\n")
tracepointprovider_Cmake.write("""cmake_minimum_required(VERSION 2.8.12.2)
project(coreclrtraceptprovider)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-DPAL_STDCPP_COMPAT=1)
include_directories(${COREPAL_SOURCE_DIR}/inc/rt)
include_directories(../lttng/)
add_compile_options(-fPIC)
add_library(coreclrtraceptprovider
SHARED
""")
for providerNode in tree.getElementsByTagName('provider'):
providerName = providerNode.getAttribute('name')
providerName = providerName.replace("Windows-",'')
providerName = providerName.replace("Microsoft-",'')
providerName_File = providerName.replace('-','')
providerName_File = providerName_File.lower()
tracepointprovider_Cmake.write(' "../'+ lttngevntprovTpPre + providerName_File +".cpp" + '"\n')
tracepointprovider_Cmake.write(""" )
target_link_libraries(coreclrtraceptprovider
-llttng-ust
)
# Install the static coreclrtraceptprovider library
install_clr(coreclrtraceptprovider)
""")
with open(eventprovider_directory + lttng_directory + "/eventprovhelpers.cpp", 'w') as helper:
helper.write("""
#include "palrt.h"
#include "pal.h"
#include "stdlib.h"
#include "pal_mstypes.h"
#include "pal_error.h"
#include <new>
#include <memory.h>
bool ResizeBuffer(char *&buffer, int& size, int currLen, int newSize, bool &fixedBuffer)
{
newSize *= 1.5;
_ASSERTE(newSize > size); // check for overflow
if (newSize < 32)
newSize = 32;
char *newBuffer = new char[newSize];
memcpy(newBuffer, buffer, currLen);
if (!fixedBuffer)
delete[] buffer;
buffer = newBuffer;
size = newSize;
fixedBuffer = false;
return true;
}
bool WriteToBuffer(const BYTE *src, int len, char *&buffer, int& offset, int& size, bool &fixedBuffer)
{
if (offset + len)
{
if (!ResizeBuffer(buffer, size, offset, size + len, fixedBuffer))
return false;
}
memcpy(buffer + offset, src, len);
offset += len;
return true;
}
bool WriteToBuffer(PCWSTR str, char *&buffer, int& offset, int& size, bool &fixedBuffer)
{
int byteCount = (PAL_wcslen(str) + 1) * sizeof(*str);
if (offset + byteCount)
{
if (!ResizeBuffer(buffer, size, offset, size + byteCount, fixedBuffer))
return false;
}
memcpy(buffer + offset, str, byteCount);
offset += byteCount;
return true;
}
bool WriteToBuffer(const char *str, char *&buffer, int& offset, int& size, bool &fixedBuffer)
{
int len = strlen(str) + 1;
if (offset + len)
{
if (!ResizeBuffer(buffer, size, offset, size + len, fixedBuffer))
return false;
}
memcpy(buffer + offset, str, len);
offset += len;
return true;
}""")
# Generate Lttng specific instrumentation
for providerNode in tree.getElementsByTagName('provider'):
providerName = providerNode.getAttribute('name')
providerName = providerName.replace("Windows-",'')
providerName = providerName.replace("Microsoft-",'')
providerName_File = providerName.replace('-','')
providerName_File = providerName_File.lower()
providerName = providerName.replace('-','_')
lttngevntheadershortname = "tp" + providerName_File +".h";
lttngevntheader = eventprovider_directory + "lttng/" + lttngevntheadershortname
lttngevntprov = eventprovider_directory + lttngevntprovPre + providerName_File + ".cpp"
lttngevntprovTp = eventprovider_directory + lttngevntprovTpPre + providerName_File +".cpp"
lTTngHdr = open(lttngevntheader, 'w')
lTTngImpl = open(lttngevntprov, 'w')
lTTngTpImpl = open(lttngevntprovTp, 'w')
lTTngHdr.write(stdprolog + "\n")
lTTngImpl.write(stdprolog + "\n")
lTTngTpImpl.write(stdprolog + "\n")
lTTngTpImpl.write("\n#define TRACEPOINT_CREATE_PROBES\n")
lTTngTpImpl.write("#include \"./"+lttngevntheadershortname + "\"\n")
lTTngHdr.write("""
#include "palrt.h"
#include "pal.h"
#undef TRACEPOINT_PROVIDER
""")
lTTngHdr.write("#define TRACEPOINT_PROVIDER " + providerName + "\n")
lTTngHdr.write("""
#undef TRACEPOINT_INCLUDE
""")
lTTngHdr.write("#define TRACEPOINT_INCLUDE \"./" + lttngevntheadershortname + "\"\n\n")
lTTngHdr.write("#if !defined(LTTNG_CORECLR_H" + providerName + ") || defined(TRACEPOINT_HEADER_MULTI_READ)\n\n")
lTTngHdr.write("#define LTTNG_CORECLR_H" + providerName + "\n")
lTTngHdr.write("\n#include <lttng/tracepoint.h>\n\n")
lTTngImpl.write("""
#define TRACEPOINT_DEFINE
#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE
#include "stdlib.h"
#include "pal_mstypes.h"
#include "pal_error.h"
#include "pal.h"
#define PAL_free free
#define PAL_realloc realloc
#include "pal/stackstring.hpp"
""")
lTTngImpl.write("#include \"" + lttngevntheadershortname + "\"\n\n")
lTTngImpl.write("""#ifndef tracepoint_enabled
#define tracepoint_enabled(provider, name) TRUE
#define do_tracepoint tracepoint
#endif
bool ResizeBuffer(char *&buffer, int& size, int currLen, int newSize, bool &fixedBuffer);
bool WriteToBuffer(PCWSTR str, char *&buffer, int& offset, int& size, bool &fixedBuffer);
bool WriteToBuffer(const char *str, char *&buffer, int& offset, int& size, bool &fixedBuffer);
bool WriteToBuffer(const BYTE *src, int len, char *&buffer, int& offset, int& size, bool &fixedBuffer);
template <typename T>
bool WriteToBuffer(const T &value, char *&buffer, int& offset, int& size, bool &fixedBuffer)
{
if (sizeof(T) + offset > size)
{
if (!ResizeBuffer(buffer, size, offset, size + sizeof(T), fixedBuffer))
return false;
}
*(T *)(buffer + offset) = value;
offset += sizeof(T);
return true;
}
""")
templateNodes = providerNode.getElementsByTagName('template')
eventNodes = providerNode.getElementsByTagName('event')
allTemplates = parseTemplateNodes(templateNodes)
#generate the header
lTTngHdr.write(generateLttngHeader(providerName,allTemplates,eventNodes) + "\n")
#create the implementation of eventing functions : lttngeventprov*.cp
lTTngImpl.write(generateLttngTpProvider(providerName,eventNodes,allTemplates) + "\n")
lTTngHdr.close()
lTTngImpl.close()
lTTngTpImpl.close()
import argparse
import sys
def main(argv):
#parse the command line
parser = argparse.ArgumentParser(description="Generates the Code required to instrument LTTtng logging mechanism")
required = parser.add_argument_group('required arguments')
required.add_argument('--man', type=str, required=True,
help='full path to manifest containig the description of events')
required.add_argument('--intermediate', type=str, required=True,
help='full path to eventprovider intermediate directory')
args, unknown = parser.parse_known_args(argv)
if unknown:
print('Unknown argument(s): ', ', '.join(unknown))
return const.UnknownArguments
sClrEtwAllMan = args.man
intermediate = args.intermediate
generateLttngFiles(sClrEtwAllMan,intermediate)
if __name__ == '__main__':
return_code = main(sys.argv[1:])
sys.exit(return_code)