-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdynamic-tracing.yaml
149 lines (138 loc) · 4.17 KB
/
dynamic-tracing.yaml
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
apiVersion: v1
kind: Pod
metadata:
name: sample-netcore-app
labels:
app: sample-netcore-app
spec:
shareProcessNamespace: true
containers:
- env:
- name: COMPlus_PerfMapEnabled
value: "1"
- name: ASPNETCORE_URLS
value: http://*:8080
image: joeelliott/sample-netcore-app:v1.0.0-2.2.5
imagePullPolicy: IfNotPresent
name: sample-netcore-app
command: ["/run-native/runNative.sh"]
args: ["/app/sample-netcore-app.dll"]
volumeMounts:
- mountPath: /run-native
name: run-native-volume
- mountPath: /app-profile
name: app
- mountPath: /tmp
name: tmp
- name: profile-sidecar
image: joeelliott/netcore-debugging-tools:v0.0.10-2.2.5
imagePullPolicy: IfNotPresent
securityContext:
privileged: true
args:
- sleep
- infinity
volumeMounts:
- mountPath: /app-profile
name: app
- mountPath: /tmp
name: tmp
- mountPath: /sys
name: sys
# - mountPath: /usr/src
# name: modules
# readOnly: true
# - mountPath: /lib/modules
# name: headers
# readOnly: true
volumes:
- name: tmp
emptyDir: {}
- configMap:
defaultMode: 0740
name: profile-run-native
name: run-native-volume
- emptyDir: {}
name: app
- hostPath:
path: /sys
type: Directory
name: sys
# - hostPath:
# path: /usr/src
# type: Directory
# name: modules
# - hostPath:
# path: /lib/modules
# type: Directory
# name: headers
---
apiVersion: v1
kind: ConfigMap
metadata:
name: profile-run-native
data:
runNative.sh: |
#! /bin/sh
#
# runNative.sh <app dll> <sdk version>
# ./runNative /app/app.dll
#
APP_DLL=$1
APP_DIR=$(dirname "$APP_DLL")
DOTNET_VERSION=$(dotnet --info | grep Version | cut -f2 -d":" | xargs)
DOTNET_FRAMEWORK_PATH=/usr/share/dotnet/shared/Microsoft.NETCore.App/$DOTNET_VERSION
#todo: dynamically generate this with dotnet --list-runtimes
ADDITIONAL_PATHS=/usr/share/dotnet/shared/Microsoft.AspNetCore.All/$DOTNET_VERSION:/usr/share/dotnet/shared/Microsoft.AspNetCore.App/$DOTNET_VERSION
# using the shell name to guess the runtime id. can't find a better way to do this
# bash => linux-x64
# ash => linux-musl-x64
if [ -f /bin/bash ]; then
RUNTIME_ID=linux-x64
else
RUNTIME_ID=linux-musl-x64
fi
# get dotnet sdk
echo -- Grabbing netcore sdk $DOTNET_VERSION for runtime $RUNTIME_ID
# alpine containers have wget. standard have curl
if which curl; then
curl -L -o runtime.zip https://www.nuget.org/api/v2/package/runtime.$RUNTIME_ID.Microsoft.NETCore.App/$DOTNET_VERSION
elif which wget; then
wget -O runtime.zip https://www.nuget.org/api/v2/package/runtime.$RUNTIME_ID.Microsoft.NETCore.App/$DOTNET_VERSION
else
echo "Unable to pull runtime"
exit 1
fi
# install unzip if necessary
# alpine containers have unzip. others don't. use apt-get to bring it in.
which unzip || { apt-get update && apt-get install unzip -y; }
mkdir -p ./runtime
unzip runtime.zip -d ./runtime
cp ./runtime/tools/crossgen .
chmod 744 ./crossgen
rm -rf ./runtime
# find libjitclr.so
if [ -f $APP_DIR/libcrljit.so ]; then
JIT_PATH=$APP_DIR/libcrljit.so
elif [ -f $DOTNET_FRAMEWORK_PATH/libclrjit.so ]; then
JIT_PATH=$DOTNET_FRAMEWORK_PATH/libclrjit.so
else
# look in other places? use find?
echo "Unable to find libclrjit.so"
exit 1
fi
# generate native image and perf map
APP_BASE_NAME=${APP_DLL%.*}
APP_NATIVE_IMAGE=$APP_BASE_NAME.ni.exe
./crossgen /JITPath $JIT_PATH \
/Platform_Assemblies_Paths $DOTNET_FRAMEWORK_PATH:$APP_DIR:$ADDITIONAL_PATHS \
$APP_DLL
./crossgen /Platform_Assemblies_Paths $DOTNET_FRAMEWORK_PATH:$APP_DIR:$ADDITIONAL_PATHS \
/CreatePerfMap /tmp \
$APP_NATIVE_IMAGE
cp $APP_BASE_NAME.deps.json $APP_BASE_NAME.ni.deps.json
cp $APP_BASE_NAME.runtimeconfig.json $APP_BASE_NAME.ni.runtimeconfig.json
#cp to /app-profile
cp -r $APP_DIR/* /app-profile
# run native image
dotnet /app-profile/$(basename $APP_NATIVE_IMAGE)