Skip to content

Instantly share code, notes, and snippets.

@goldshtn
Created April 2, 2017 06:57
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save goldshtn/eae953dfccd2eb4b4d43d4c326b62fb5 to your computer and use it in GitHub Desktop.
.NET Core (CoreCLR) patch for emitting USDT probes
diff --git a/src/scripts/genXplatLttng.py b/src/scripts/genXplatLttng.py
index bacf034..3d40d77 100644
--- a/src/scripts/genXplatLttng.py
+++ b/src/scripts/genXplatLttng.py
@@ -407,8 +407,25 @@ def generateLttngTpProvider(providerName, eventNodes, allTemplates):
for eventNode in eventNodes:
eventName = eventNode.getAttribute('symbol')
templateName = eventNode.getAttribute('template')
+
+ template = allTemplates[templateName] if templateName else None
+ paramlist = template.signature.paramlist[:10] if template else []
+ strparamlist = str.join(", ", paramlist())
+ numparams = len(paramlist)
+
+ lTTngImpl.append("#define SDT_%s_%s_ENABLED() __builtin_expect (%s_%s_semaphore, 0)\n" %
+ (providerName.upper(), eventName.upper(), providerName, eventName))
+ lTTngImpl.append(("__extension__ unsigned short %s_%s_semaphore __attribute__ ((unused)) " +
+ "__attribute__ ((section (\".probes\")));\n") % (providerName, eventName))
+ lTTngImpl.append("#define SDT_%s_%s(%s) DTRACE_PROBE%s(%s, %s%s %s)\n\n" %
+ (providerName.upper(), eventName.upper(), strparamlist,
+ numParams if numParams != 0 else "", providerName, eventName,
+ "," if numParams != 0 else "", strparamlist))
+
#generate EventXplatEnabled
- lTTngImpl.append("extern \"C\" BOOL EventXplatEnabled%s(){ return tracepoint_enabled(%s, %s); }\n\n" % (eventName, providerName, eventName))
+ lTTngImpl.append("extern \"C\" BOOL EventXplatEnabled%s() { " +
+ "return tracepoint_enabled(%s, %s) || SDT_%s_%s_ENABLED(); }\n\n" %
+ (eventName, providerName, eventName, providerName.upper(), eventName.upper()))
#generate FireEtw functions
fnptype = []
linefnptype = []
@@ -416,12 +433,6 @@ def generateLttngTpProvider(providerName, eventNodes, allTemplates):
fnptype.append(eventName)
fnptype.append("(\n")
-
- if templateName:
- template = allTemplates[templateName]
- else:
- template = None
-
if template:
fnSig = template.signature
for paramName in fnSig.paramlist:
@@ -451,6 +462,8 @@ def generateLttngTpProvider(providerName, eventNodes, allTemplates):
lTTngImpl.extend(fnptype)
#start of fn body
+ lTTngImpl.append(" if (SDT_%s_%s_ENABLED())\n" % (providerName.upper(), eventName.upper()))
+ lTTngImpl.append(" SDT_%s_%s(%s);\n\n" % (providerName.upper(), eventName.upper(), strparamlist))
lTTngImpl.append(" if (!EventXplatEnabled%s())\n" % (eventName,))
lTTngImpl.append(" return ERROR_SUCCESS;\n")
@@ -654,7 +667,7 @@ bool WriteToBuffer(const char *str, char *&buffer, int& offset, int& size, bool
lTTngTpImpl = open(lttngevntprovTp, 'w')
lTTngHdr.write(stdprolog + "\n")
- lTTngImpl.write(stdprolog + "\n")
+ lTTngImpl.write(stdprolog + "\n#define _SDT_HAS_SEMAPHORES 1\n#include <sys/sdt.h>\n")
lTTngTpImpl.write(stdprolog + "\n")
lTTngTpImpl.write("\n#define TRACEPOINT_CREATE_PROBES\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment