Skip to content

Commit acc623a

Browse files
authored
Merge pull request #782 from Unity-Technologies/unity-master-mixed-callstack-cleanup
Mixed Callstacks: Reduce allocations and perform name calculation outside of lock.
2 parents 3d1a1f7 + 7924b37 commit acc623a

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed

mono/mini/mixed_callstack_plugin.c

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,6 @@
22
#include "mono/metadata/mono-debug.h"
33
#include "mono/metadata/profiler.h"
44

5-
static char *
6-
pmip_pretty(MonoCompile* monoCompile)
7-
{
8-
char* methodName;
9-
char* assemblyName;
10-
char* formattedPMIP;
11-
MonoDebugSourceLocation* debugSourceLocation;
12-
MonoDebugMethodInfo* debugMethodInfo;
13-
MonoDomain* domain;
14-
MonoMethod* method = monoCompile->method;
15-
16-
domain = mono_domain_get();
17-
if (!domain)
18-
domain = mono_get_root_domain();
19-
20-
methodName = mono_method_full_name(method, TRUE);
21-
22-
debugSourceLocation = mono_debug_lookup_source_location(method, 0, domain);
23-
debugMethodInfo = mono_debug_lookup_method(method);
24-
25-
assemblyName = method->klass->image->module_name;
26-
27-
formattedPMIP = g_strdup_printf("[%s] %s", assemblyName, methodName);
28-
29-
mono_debug_free_source_location(debugSourceLocation);
30-
g_free(methodName);
31-
32-
return formattedPMIP;
33-
}
34-
355
#if !defined(DISABLE_JIT) && defined(HOST_WIN32)
366

377
static gboolean enabled;
@@ -99,24 +69,27 @@ mixed_callstack_plugin_on_domain_unload_end()
9969
void
10070
mixed_callstack_plugin_save_method_info (MonoCompile *cfg)
10171
{
102-
char* pretty_name;
103-
char* frame;
72+
char* method_name;
10473
long bytesWritten = 0;
74+
char frame[1024];
75+
int bytes;
10576

10677
if (!enabled)
10778
return;
10879

109-
pretty_name = pmip_pretty(cfg);
80+
method_name = mono_method_full_name (cfg->method, TRUE);
81+
82+
bytes = snprintf (frame, sizeof (frame), "%p;%p;[%s] %s\n", cfg->native_code, ((char*)cfg->native_code) + cfg->code_size, cfg->method->klass->image->module_name, method_name);
83+
/* negative value is encoding error */
84+
if (bytes < 0 || bytes > sizeof (frame))
85+
return;
11086

11187
mixed_callstack_plugin_lock ();
112-
frame = g_strdup_printf("%p;%p;%s\n", cfg->native_code, ((char*)cfg->native_code) + cfg->code_size, pretty_name);
113-
WriteFile(fileHandle, frame, strlen(frame), &bytesWritten, NULL);
88+
WriteFile(fileHandle, frame, bytes, &bytesWritten, NULL);
11489
FlushFileBuffers(fileHandle);
115-
11690
mixed_callstack_plugin_unlock ();
11791

118-
g_free(pretty_name);
119-
g_free(frame);
92+
g_free(method_name);
12093
}
12194

12295
void

0 commit comments

Comments
 (0)