From 623846e347a76ec87819a565ce5fd88f751ce853 Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Fri, 25 Mar 2011 20:16:24 +0900 Subject: [PATCH] VTune Amplifier XE 2011 plugin for Mono --- mono/profiler/mono-profiler-vtune.c | 122 +++++++++++++++++++ msvc/mono-profiler-vtune.def | 4 + msvc/mono.sln | 15 ++- msvc/profiler-vtune.vcxproj | 178 ++++++++++++++++++++++++++++ 4 files changed, 317 insertions(+), 2 deletions(-) create mode 100644 mono/profiler/mono-profiler-vtune.c create mode 100644 msvc/mono-profiler-vtune.def create mode 100644 msvc/profiler-vtune.vcxproj diff --git a/mono/profiler/mono-profiler-vtune.c b/mono/profiler/mono-profiler-vtune.c new file mode 100644 index 00000000000..dafd100accc --- /dev/null +++ b/mono/profiler/mono-profiler-vtune.c @@ -0,0 +1,122 @@ +/* + * mono-codeanalyst.c: VTune profiler + * + * Author: + * Virgile Bello (virgile.bello@gmail.com) + * + * (C) 2011 Virgile Bello + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define bool char + +#include "jitprofiling.h" + +/* called at the end of the program */ +static void +codeanalyst_shutdown (MonoProfiler *prof) +{ + iJIT_NotifyEvent(iJVM_EVENT_TYPE_SHUTDOWN, NULL); +} + +static void +method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, int result) { + if (result == MONO_PROFILE_OK) { + int i; + MonoDebugSourceLocation *sourceLoc; + MonoDebugMethodInfo *methodDebugInfo; + MonoDebugMethodJitInfo *dmji; + MonoClass *klass = mono_method_get_class (method); + char *signature = mono_signature_get_desc (mono_method_signature (method), TRUE); + char *name = g_strdup_printf ("%s(%s)", mono_method_get_name (method), signature); + char *classname = g_strdup_printf ("%s%s%s", mono_class_get_namespace (klass), mono_class_get_namespace (klass)[0] != 0 ? "::" : "", mono_class_get_name (klass)); + gpointer code_start = mono_jit_info_get_code_start (jinfo); + int code_size = mono_jit_info_get_code_size (jinfo); + + iJIT_Method_Load vtuneMethod; + memset(&vtuneMethod, 0, sizeof(vtuneMethod)); + vtuneMethod.method_id = iJIT_GetNewMethodID(); + vtuneMethod.method_name = name; + vtuneMethod.method_load_address = code_start; + vtuneMethod.method_size = code_size; + vtuneMethod.class_file_name = classname; + + dmji = mono_debug_find_method (method, mono_domain_get()); + + if (dmji != NULL) + { + vtuneMethod.line_number_size = dmji->num_line_numbers; + vtuneMethod.line_number_table = (vtuneMethod.line_number_size != 0) ? + (LineNumberInfo*)malloc(sizeof(LineNumberInfo) * vtuneMethod.line_number_size) : NULL; + + for (i = 0; i < dmji->num_line_numbers; ++i) + { + sourceLoc = mono_debug_lookup_source_location (method, dmji->line_numbers[i].native_offset, mono_domain_get()); + if (sourceLoc == NULL) + { + free(vtuneMethod.line_number_table); + vtuneMethod.line_number_table = NULL; + vtuneMethod.line_number_size = 0; + break; + } + if (i == 0) + vtuneMethod.source_file_name = strdup(sourceLoc->source_file); + vtuneMethod.line_number_table[i].Offset = dmji->line_numbers[i].native_offset; + vtuneMethod.line_number_table[i].LineNumber = sourceLoc->row; + mono_debug_free_source_location (sourceLoc); + } + mono_debug_free_method_jit_info (dmji); + } + + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &vtuneMethod); + + if (vtuneMethod.source_file_name != NULL) + free(vtuneMethod.source_file_name); + if (vtuneMethod.line_number_table != NULL) + free(vtuneMethod.line_number_table); + + g_free (signature); + g_free (name); + g_free (classname); + } +} + +/* the entry point */ +void +mono_profiler_startup (const char *desc) +{ + iJIT_IsProfilingActiveFlags flags = iJIT_IsProfilingActive(); + if (flags == iJIT_SAMPLING_ON) + { + mono_profiler_install (NULL, codeanalyst_shutdown); + mono_profiler_install_jit_end (method_jit_result); + mono_profiler_set_events (MONO_PROFILE_JIT_COMPILATION); + } +} diff --git a/msvc/mono-profiler-vtune.def b/msvc/mono-profiler-vtune.def new file mode 100644 index 00000000000..1da827afb1d --- /dev/null +++ b/msvc/mono-profiler-vtune.def @@ -0,0 +1,4 @@ +; file generated by create-windef.pl +LIBRARY mono-profiler-vtune.dll +EXPORTS +mono_profiler_startup \ No newline at end of file diff --git a/msvc/mono.sln b/msvc/mono.sln index a2a6ef3a679..d989efd1c1a 100644 --- a/msvc/mono.sln +++ b/msvc/mono.sln @@ -61,6 +61,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "profiler-codeanalyst", "pro EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Profilers", "Profilers", "{4CFD7702-60B2-4E82-BFAD-FCBB53EB4DA2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "profiler-vtune", "profiler-vtune.vcxproj", "{F51017F9-B7FB-4F87-B7B5-12799D965783}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -195,6 +197,14 @@ Global {8FEF7F9E-F5F3-470E-91F4-404B7D6BC1BB}.Debug|x64.ActiveCfg = Debug|x64 {8FEF7F9E-F5F3-470E-91F4-404B7D6BC1BB}.Release|Win32.ActiveCfg = Release|Win32 {8FEF7F9E-F5F3-470E-91F4-404B7D6BC1BB}.Release|x64.ActiveCfg = Release|x64 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Debug|Win32.ActiveCfg = Debug|Win32 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Debug|Win32.Build.0 = Debug|Win32 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Debug|x64.ActiveCfg = Debug|x64 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Debug|x64.Build.0 = Debug|x64 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Release|Win32.ActiveCfg = Release|Win32 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Release|Win32.Build.0 = Release|Win32 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Release|x64.ActiveCfg = Release|x64 + {F51017F9-B7FB-4F87-B7B5-12799D965783}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -217,11 +227,12 @@ Global {83D4D926-2983-4770-BA92-EB9CB8828C95} = {4CFD7702-60B2-4E82-BFAD-FCBB53EB4DA2} {8FEF7F9E-F5F3-470E-91F4-404B7D6BC1BB} = {4CFD7702-60B2-4E82-BFAD-FCBB53EB4DA2} {86663B87-4CD2-42B6-8D8E-C79DA1CCDEE6} = {4CFD7702-60B2-4E82-BFAD-FCBB53EB4DA2} + {F51017F9-B7FB-4F87-B7B5-12799D965783} = {4CFD7702-60B2-4E82-BFAD-FCBB53EB4DA2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - AMDCaProjectFile = C:\Users\Owner\Development\monogit\mono\msvc\CodeAnalyst\mono.caw - AMDCaPersistentStartup = mono AMDCaPersistentConfig = Debug|Win32 + AMDCaPersistentStartup = mono + AMDCaProjectFile = C:\Users\Owner\Development\monogit\mono\msvc\CodeAnalyst\mono.caw EndGlobalSection GlobalSection(DPCodeReviewSolutionGUID) = preSolution DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} diff --git a/msvc/profiler-vtune.vcxproj b/msvc/profiler-vtune.vcxproj new file mode 100644 index 00000000000..66a73f9fda8 --- /dev/null +++ b/msvc/profiler-vtune.vcxproj @@ -0,0 +1,178 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {F51017F9-B7FB-4F87-B7B5-12799D965783} + profilervtune + Win32Proj + + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + true + + + DynamicLibrary + Unicode + true + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(Platform)\bin\ + $(Platform)\bin\ + $(Platform)\obj\$(ProjectName)\ + $(Platform)\obj\$(ProjectName)\ + true + true + $(Platform)\bin\ + $(Platform)\bin\ + $(Platform)\obj\$(ProjectName)\ + $(Platform)\obj\$(ProjectName)\ + false + false + mono-profiler-vtune + mono-profiler-vtune + mono-profiler-vtune + mono-profiler-vtune + + + + MaxSpeed + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + ..\libgc\include;..\;..\mono\;..\mono\jit;..\mono\eglib\src;..\..\mono\eglib\src;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\include;%(AdditionalIncludeDirectories) + + + true + Windows + true + true + MachineX86 + mono-profiler-vtune.def + mono-2.0.lib;version.lib;libgc.lib;eglib.lib;ws2_32.lib;Psapi.lib;winmm.lib;jitprofiling.lib;%(AdditionalDependencies) + $(Platform)\lib;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\lib32;%(AdditionalLibraryDirectories) + + + + + MaxSpeed + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + ..\libgc\include;..\;..\mono\;..\mono\jit;..\mono\eglib\src;..\..\mono\eglib\src;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\include;%(AdditionalIncludeDirectories) + + + true + Windows + true + true + mono-profiler-vtune.def + mono-2.0.lib;version.lib;libgc.lib;eglib.lib;ws2_32.lib;Psapi.lib;winmm.lib;%(AdditionalDependencies) + $(Platform)\lib;%(AdditionalLibraryDirectories) + + + + + Disabled + ..\libgc\include;..\;..\mono\;..\mono\jit;..\mono\eglib\src;..\..\mono\eglib\src;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + + + mono-2.0.lib;version.lib;libgc.lib;eglib.lib;ws2_32.lib;Psapi.lib;winmm.lib;jitprofiling.lib;%(AdditionalDependencies) + $(Platform)\lib;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\lib32;%(AdditionalLibraryDirectories) + true + Windows + MachineX86 + mono-profiler-vtune.def + + + + + Disabled + ..\libgc\include;..\;..\mono\;..\mono\jit;..\mono\eglib\src;..\..\mono\eglib\src;$(ProgramFiles)\Intel\VTune Amplifier XE 2011\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + ProgramDatabase + + + mono-2.0.lib;version.lib;libgc.lib;eglib.lib;ws2_32.lib;Psapi.lib;winmm.lib;%(AdditionalDependencies) + $(Platform)\lib;%(AdditionalLibraryDirectories) + true + Windows + mono-profiler-vtune.def + + + + + + + + + + + + \ No newline at end of file -- 2.25.1