Skip to content

Commit 138c8ac

Browse files
committed
Update docs and tests
Removed documentation about `counters.txt`, since the file is no longer generated. Added info on how to get `methods.xml` generated. TODO: `jit-times`
1 parent c74ba8e commit 138c8ac

File tree

6 files changed

+41
-58
lines changed

6 files changed

+41
-58
lines changed

Documentation/guides/profiling.md

+28-47
Original file line numberDiff line numberDiff line change
@@ -174,72 +174,53 @@ If profiling a Release build, you'll need to edit your
174174

175175
Debug builds already set this value by default.
176176

177+
In order to save method JIT statistics, the application has to be built
178+
with the `$(_AndroidMethodsStats)` MSBuild property set to `true`.
179+
177180
Next, run the `adb` command:
178181

179182
> adb shell setprop debug.mono.log timing,default
180183

181-
After launching the app, you can find a file that was recorded during
182-
startup:
184+
After launching the app, wait for the desired period of time and then send
185+
an Android intent to the application in order to actually save data into
186+
the `methods.xml` file:
187+
188+
> adb shell am broadcast -a mono.android.app.DUMP_TIMING_DATA com.xamarin.android.helloworld
189+
190+
After this is done, you can find a file that was recorded during startup:
183191

184192
> adb shell run-as com.xamarin.android.helloworld ls files/.__override__
185-
counters.txt
186-
methods.txt
193+
methods.xml
187194

188-
Make sure to use your app's package name instead of
189-
`com.xamarin.android.helloworld`.
195+
Make sure to use your app's package name instead of `com.xamarin.android.helloworld`.
190196

191197
You can pull these files to your machine by doing:
192198

193-
> adb shell run-as com.xamarin.android.helloworld cat files/.__override__/counters.txt > counters.txt
194-
> adb shell run-as com.xamarin.android.helloworld cat files/.__override__/methods.txt > methods.txt
199+
> adb shell run-as com.xamarin.android.helloworld cat files/.__override__/methods.xml > methods.xml
195200

196201
If you ever need to reset/clear these directories, you can
197202
uninstall/reinstall the app or merely:
198203

199-
> adb shell run-as com.xamarin.android.helloworld rm -r files/.__override__/
200-
201-
`counters.txt` has some interesting summary information provided by
202-
Mono:
203-
204-
## Runtime.register: type=HelloWorld.MainActivity, HelloWorld
205-
JIT statistics
206-
Discarded method code : 1
207-
Time spent JITting discarded code : 0.82 ms
208-
Try holes memory size : 896
209-
Dynamic code allocs : 3
210-
Dynamic code bytes : 584
211-
Dynamic code frees : 0
212-
Unwind info size : 5985
213-
Calls to trampolines : 1994
214-
JIT trampolines : 952
215-
Unbox trampolines : 2
216-
Static rgctx trampolines : 7
217-
Async JIT info size : 0
218-
Max native code in a domain : 0
219-
Max code space allocated in a domain: 0
220-
Total code space allocated : 0
221-
Hazardous pointers : 0
222-
Compiled methods : 921
223-
Methods from AOT : 0
224-
Methods JITted using mono JIT : 921
225-
Methods JITted using LLVM : 0
226-
Methods using the interpreter : 0
227-
228-
_NOTE: that `counters.txt` is not available in .NET 6 projects._
229-
230-
`methods.txt` has the individual JIT times of each method:
231-
232-
JIT method begin: System.OutOfMemoryException:.ctor (string) elapsed: 0s:20::136721
233-
JIT method done: System.OutOfMemoryException:.ctor (string) elapsed: 0s:20::605627
204+
> adb shell run-as com.xamarin.android.helloworld rm files/.__override__/methods.xml
205+
206+
`methods.xml` has the individual JIT times of each method:
207+
208+
<method name="Java.Lang.Object:GetObject (intptr,Android.Runtime.JniHandleOwnership,System.Type)" invocation_count="1" jit_time="0:0::20915" jit_status="success" />
209+
210+
If methods statistics were gathered in `Release` mode, the `invocation_count` attribute of most entries
211+
will be `0`. This is due to the fact that the Mono runtime allows us to gather call statistics only
212+
when running with the interpreter instead of JIT. In order to properly count calls to each method, the
213+
application needs to be built with the `$(UseInterpreter)` MSBuild property set to `true` (it works both in
214+
`Debug` and `Release` modes).
234215

235216
This is not particularly readable, so you can use our
236217
[jit-times][jit_times] command-line tool to get better/sorted output:
237218

238219
# Windows / .NET
239-
jit-times.exe methods.txt > methods-sorted.txt
220+
jit-times.exe methods.xml > methods-sorted.txt
240221

241222
# Mac / Mono
242-
mono jit-times.exe methods.txt > methods-sorted.txt
223+
mono jit-times.exe methods.xml > methods-sorted.txt
243224

244225
Which outputs:
245226

@@ -441,7 +422,7 @@ target:
441422
Project Evaluation Performance Summary:
442423
12 ms samples\HelloWorld\HelloLibrary\HelloLibrary.csproj 1 calls
443424
98 ms samples\HelloWorld\HelloWorld.csproj 1 calls
444-
425+
445426
Target Performance Summary:
446427
275 ms _UpdateAndroidResgen 2 calls
447428
354 ms _GenerateJavaStubs 1 calls
@@ -450,7 +431,7 @@ target:
450431
865 ms _ResolveSdks 2 calls
451432
953 ms ResolveProjectReferences 2 calls
452433
1219 ms _CompileToDalvikWithD8 1 calls
453-
434+
454435
Task Performance Summary:
455436
681 ms Csc 2 calls
456437
809 ms ValidateJavaVersion 2 calls

Documentation/workflow/SystemProperties.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ categories:
169169
* `timing`
170170
Enable logging of native code performance information, including
171171
method execution timing which is written to a file named
172-
`methods.txt`. `timing=bare` should be used in preference to this
173-
category.
172+
`methods.xml` (see [profiling][profiling] for more information).
173+
`timing=bare` should be used in preference to this category.
174+
175+
[profiling]: ../guides/profiling.md
174176

175177
#### Timing events format
176178

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
***********************************************************************************************
33
Xamarin.Android.Common.targets
44
@@ -1540,7 +1540,7 @@ because xbuild doesn't support framework reference assemblies.
15401540
<ItemGroup>
15411541
<AndroidManifestOverlay
15421542
Include="$(MSBuildThisFileDirectory)\ManifestOverlays\Timing.xml"
1543-
Condition=" '$(_AndroidFastTiming)' == 'True' "
1543+
Condition=" '$(_AndroidFastTiming)' == 'True' Or '$(_AndroidMethodsStats)' == 'True' "
15441544
/>
15451545
</ItemGroup>
15461546
<ManifestMerger

src/native/monodroid/monodroid-glue-internal.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace xamarin::android::internal
231231
static void prof_method_begin_invoke (MonoProfiler *prof, MonoMethod *method) noexcept;
232232
static void prof_method_end_invoke (MonoProfiler *prof, MonoMethod *method) noexcept;
233233
static void prof_method_enter (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *context) noexcept;
234-
static void prof_method_leave (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *context) noexcept;
234+
static void prof_method_leave (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *context) noexcept;
235235
static MonoProfilerCallInstrumentationFlags prof_method_filter (MonoProfiler *prof, MonoMethod *method) noexcept;
236236

237237
#if !defined (RELEASE)

src/native/monodroid/performance-methods.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ namespace {
3535
void
3636
MonodroidRuntime::dump_method_events ()
3737
{
38-
if (!method_event_map) {
38+
if (!method_event_map || !method_event_map_write_lock) {
3939
return;
4040
}
4141

42-
log_debug (LOG_ASSEMBLY, "Dumping method events");
4342
lock_guard<mutex> write_mutex { *method_event_map_write_lock.get () };
4443

4544
mono_profiler_set_jit_begin_callback (profiler_handle, nullptr);
@@ -71,6 +70,7 @@ MonodroidRuntime::dump_method_events ()
7170
return;
7271
}
7372
Util::set_world_accessable (jit_log_path.get ());
73+
log_info (LOG_DEFAULT, "Saving managed method statistics to: %s", jit_log_path.get ());
7474

7575
dprintf (
7676
jit_log,

tests/MSBuildDeviceIntegration/Tests/InstallTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void LoggingPropsShouldCreateOverrideDirForRelease ()
333333
Assert.True (didLaunch, "Activity should have started.");
334334
var directorylist = GetContentFromAllOverrideDirectories (proj.PackageName, DeviceAbi);
335335
builder.Uninstall (proj);
336-
StringAssert.Contains ("methods.txt", directorylist, $"methods.txt did not exist in the .__override__ directory.\nFound:{directorylist}");
336+
StringAssert.Contains ("methods.xml", directorylist, $"methods.xml did not exist in the .__override__ directory.\nFound:{directorylist}");
337337
}
338338
}
339339

@@ -546,7 +546,7 @@ public void IncrementalFastDeployment (string packageFormat)
546546
}
547547

548548
long lib1FirstBuildSize = new FileInfo (Path.Combine (rootPath, lib1.ProjectName, lib1.OutputPath, "Library1.dll")).Length;
549-
549+
550550
using (var builder = CreateApkBuilder (Path.Combine (rootPath, app.ProjectName))) {
551551
builder.Verbosity = LoggerVerbosity.Detailed;
552552
builder.ThrowOnBuildFailure = false;
@@ -653,7 +653,7 @@ public void AppWithAndroidJavaSource ()
653653
public class TestJavaClass2 {
654654
655655
public String test(){
656-
656+
657657
return ""Java is called"";
658658
}
659659
}",
@@ -671,7 +671,7 @@ public String test(){
671671
public class TestJavaClass {
672672
673673
public String test(){
674-
674+
675675
return ""Java is called"";
676676
}
677677
}",

0 commit comments

Comments
 (0)