Visual Studio中探查显示DLL名称,而不是函数名 [英] Visual Studio Profiler shows DLL name instead of Function name

查看:809
本文介绍了Visual Studio中探查显示DLL名称,而不是函数名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里跟随性能分析教程:
http://msdn.microsoft。 COM / EN-US /杂志/ cc337887.aspx



我试着来分析通过使用CPU采样项目。



MSDN结果:





我的结果:





我期待看到 System.Drawing.Bitmap.SetPixel 而不是 [System.Drawing.ni.dll]



根据建议由这个帖子,我有:




  • 单击显示全部代码链接

  • 禁用仅我的代码

  • 选中Microsoft符号服务工具>选项>调试>符号,重新启动Visual Studio和再次运行报告。



输出(以下上面的步骤)后:

 无法加载符号C:\Windows\assembly\NativeImages_v2.0.50727_64\\ \\System.Drawing\8b88ae6d063a9d8ffc2f312af5d40ce5\System.Drawing.ni.dll 
加载从报告符号C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
从报告中加载符号C:从C类报告\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9200.16518_none_726fbfe0cc22f012\GdiPlus.dll
加载符号:\Windows\System32\ ntdll.dll中
加载从报告符号C:从报告\Windows\System32\KernelBase.dll
加载符号C:\Windows\System32\msvcrt.dll
无法加载符号C:\Windows\assembly\NativeImages_v2.0.50727_64\mscorlib\061d0414114241f4f2fe0908bf53b076\mscorlib.ni.dll
无法加载符号C:\Windows\assembly \NativeImages_v2.0.50727_64\System.Windows.Forms\01a89d2c3499af1e3378797d51eec364\System.Windows.Forms.ni.dll
加载从报告符号C:\Windows\System32\user32.dll
加载从报告符号C:从报告\Windows\System32\gdi32.dll
加载符号C:\Windows\System32\kernel32.dll
从加载符号对于C报告:从报告\Windows\System32\uxtheme.dll
加载符号C:\Users\user\Desktop\VSTSProfiler\bin\Debug\Mandel.exe
符号信息保存到报告。



(源代码可以从这里donwloaded:
http://download.microsoft.com/download/f/2/7/f279e71e -efb0-4155-873d-5554a0608523 / MSDNMag2008_03.exe



萃取后,这将是一个所谓的文件夹中:VSTSProfiler不管怎样,这里是粘贴如果源代码它的股价下跌:)

 使用系统; 
使用的System.Xml;
使用的System.Xml.Serialization;使用System.Diagnostics程序
; System.Collections中使用
;
使用System.Drawing中;
使用System.Drawing.Drawing2D;使用System.Windows.Forms的
;
使用的System.Threading;
使用System.Drawing.Imaging;使用System.Runtime.InteropServices
;
:使用System.IO;
使用System.Collections.Generic;

命名空间曼德尔
{
///<总结>为Form1
///摘要说明。
///< /总结>
公共Form1类:System.Windows.Forms.Form中
{
#区域自动
///<总结>
///必需的设计变量。
///< /总结>
私人System.ComponentModel.Container成分= NULL;

公共Form1中()
{
//
//所必需的Windows窗体设计器支持
//
的InitializeComponent();

//
// TODO:添加任何构造函数代码后InitializeComponent调用
//
}

///<总结> ;使用
///清理的任何资源。
///< /总结>
保护覆盖无效的Dispose(BOOL处置)
{
如果(处置)
{
如果(组件!= NULL)
{
components.Dispose();
}
}
base.Dispose(处置);
}

#region Windows窗体设计器生成的代码
///<总结>
///设计器支持所需的方法 - 不要修改
///此方法的代码编辑器的内容。
///< /总结>
私人无效的InitializeComponent()
{
this.SuspendLayout();
//
// Form1中
//
this.AutoScaleBaseSize =新System.Drawing.Size(5,13);
this.ClientSize =新System.Drawing.Size(392,266);
this.Name =Form1的;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text =曼德尔 - 绘图......;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load + =新System.EventHandler(this.Form1_Load);
this.ResumeLayout(假);

}
#endregion

///<总结>
///的主入口点应用程序。
///< /总结>
[STAThread]
静态无效的主要()
{
Application.Run(新Form1的());
}
#endregion

螺纹drawingThread = NULL;
双xLowBound = -2.1;
双yLowBound = -1.3;
双xUpperBound = 1;
双yUpperBound = 1.3;
串colorsMap =Green.Map;
常量布尔COLOR = FALSE;
//这个计时器将检查绘图线程是否仍在工作
//并更新标题为完成后:
System.Windows.Forms.Timer定时器=新System.Windows.Forms的.Timer();

私人无效Form1_Load的(对象发件人,发送System.EventArgs)
{
//设置定时器,并钩住它
timer.Interval = 200;
timer.Tick + =的OnTimer;
//初始化并启动绘图螺纹:
this.drawingThread =新主题(新的ThreadStart(this.DrawMandel));
this.drawingThread.Start();
timer.Start();
}

私人无效的OnTimer(对象发件人,EventArgs参数)
{
如果(this.drawingThread.IsAlive)
{
本。文本=曼德尔 - 分形生成...;
}
,否则
{
timer.Stop();
this.Text =曼德尔 - 准备好;
}
}

私人无效DrawMandel()
{
的for(int i = 0; I< 5;我++)
{//这个循环被故意加到拖慢了程序来衡量绩效。

颜色[] =颜色ReadColorsMap(colorsMap);
位图位图=新位图(宽度,高度);

//取消注释下面的块,以避免Bitmap.SetPixel:
//的BitmapData bmpData = bitmap.LockBits(新的Rectangle(0,0,宽度,高度),ImageLockMode.ReadWrite,位图.PixelFormat);
// IntPtr的PTR = bmpData.Scan0;
// INT像素= bitmap.Width * bitmap.Height;
//的Int32 [] = rgbValues新的Int32 [像素]

双XSTART = xLowBound;
双yStart = yLowBound;
双XEND = xUpperBound;
双YEND = yUpperBound;
双DELTAX =(XEND - XSTART)/宽度;
双DELTAY =(YEND - yStart)/身高;
双X = XSTART;
双Y = yStart;

为(INT列= 1;列<宽度;柱++)
{
Y = yStart;
为(INT行= 1;行<身高;排++)
{
双X1 = 0;
双Y1 = 0;
INT颜色= 0;
INT部门= 0;

{
部门++;
双TEMP =(X1 * X1) - (Y1 * Y1)+ X;
Y1 = 2 * X1 * Y1 + Y;
X1 =温度;
双percentFactor =部门/(100.0);
表色=((int)的(percentFactor * 255));
}
而(部门&所述; 100&放大器;&放大器;的Math.sqrt((X1 * X1)+(Y1 * Y1))2);
//评论此行来避免调用Bitmap.SetPixel:
bitmap.SetPixel(列,行,颜色[颜色]);低于
//取消注释块,以避免Bitmap.SetPixel:
// rgbValues [行*宽+列] =颜色[颜色] .ToArgb();

Y + = DELTAY;
}
X + = DELTAX;
}


//取消注释下面的块,以避免Bitmap.SetPixel:
//Marshal.Copy(rgbValues,0,PTR,像素);
//bitmap.UnlockBits(bmpData);

的BackgroundImage =(图像)的位图;
}
}


私人颜色[] ReadColorsMap(字符串路径)
{

{
颜色[] =颜色新的色彩[256];
名单,LT;字符串> colorLines =新的List<串GT;();使用
(StreamReader的SR =新的StreamReader(路径))
{
,而


//读取颜色定义(sr.EndOfStream!) {
字符串s = sr.ReadLine(); (!String.IsNullOrEmpty(S))
如果
{
colorLines.Add(s.Trim());
}
}
}

//解析定义,并将其存储在颜色数组
如果(colorLines.Count> colors.Length )
{
抛出新的异常(的String.Format(太多的颜色));
}

INT colorIndex = 0;
的foreach(在colorLines串色)
{
的String []值= color.Split('');
如果(values.Length = 3!)
{
抛出新的异常(的String.Format(地图行:'{0}',颜色));
}

INT红色= int.Parse(值[0]);
INT绿色= int.Parse(值[1]);
INT蓝色= int.Parse(值[2]);
色[colorIndex ++] = Color.FromArgb(红,绿,蓝);
}

//设置,其余的为黑色:
为(; colorIndex< colors.Length; colorIndex ++)
{
颜色[colorIndex] = Color.Black;
}

返回颜色;
}
赶上(异常前)
{
抛出新的异常(无效的颜色表文件,前);
}
}
}
}


解决方案

发现了如何:




  • 从相同版本的.NET运行NGEN.exe的版本,是
    编译的。例如:
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319

  • 给它参数 createpdb

  • 指定需要PDB为
    DLL的完整路径指定您的程序集缓存路径。例如: ngen.exe createpdb C:\windows\pathtoassembly.dll C:\SymbolCache



最后的命令奏效。我重装Visual Studio和为以后成功的。
我用同样的链接汉斯帕桑特顺便发布

  C:\Program文件(x86)\Microsoft Visual Studio的11.0\VC> NGEN createpdbC:\Window 
s\assembly\NativeImages_v4.0.30319_32\System.Drawing\ee1e19e1282f67f0466e281b535
69cd7\System.Drawing.ni.dll C:\SymbolCache
微软(R)CLR本机图像生成 - 版本4.0.30319.17929
版权所有(c)Microsoft公司。版权所有。
成功生成PDB本机程序集C:\Windows\assembly\NativeImages
_v4.0.30319_32\System.Drawing\ee1e19e1282f67f0466e281b53569cd7\System.Drawing.ni
。 DLL。在目录时生成
PDB:\SymbolCache\System.Drawing.ni.pdb\ee1e19e1282f67f0
466e281b53569cd71\


I'm following the Profiling Tutorial here: http://msdn.microsoft.com/en-us/magazine/cc337887.aspx

I've tried to profile the project by using CPU sampling.

MSDN Results:

My Results:

I'm expecting to see System.Drawing.Bitmap.SetPixel instead of the [System.Drawing.ni.dll].

As recommended by this post, I have:

  • Clicked the "Show All Code" link
  • Disabled "Just My Code"
  • Checked "Microsoft Symbol Serves" in Tools > Options > Debugging > Symbols, restarted visual studio and ran the report again.

Output (after following above steps):

Failed to load symbols for C:\Windows\assembly\NativeImages_v2.0.50727_64\System.Drawing\8b88ae6d063a9d8ffc2f312af5d40ce5\System.Drawing.ni.dll
Loaded symbols from report for C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Loaded symbols from report for C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9200.16518_none_726fbfe0cc22f012\GdiPlus.dll
Loaded symbols from report for C:\Windows\System32\ntdll.dll
Loaded symbols from report for C:\Windows\System32\KernelBase.dll
Loaded symbols from report for C:\Windows\System32\msvcrt.dll
Failed to load symbols for C:\Windows\assembly\NativeImages_v2.0.50727_64\mscorlib\061d0414114241f4f2fe0908bf53b076\mscorlib.ni.dll
Failed to load symbols for C:\Windows\assembly\NativeImages_v2.0.50727_64\System.Windows.Forms\01a89d2c3499af1e3378797d51eec364\System.Windows.Forms.ni.dll
Loaded symbols from report for C:\Windows\System32\user32.dll
Loaded symbols from report for C:\Windows\System32\gdi32.dll
Loaded symbols from report for C:\Windows\System32\kernel32.dll
Loaded symbols from report for C:\Windows\System32\uxtheme.dll
Loaded symbols from report for C:\Users\user\Desktop\VSTSProfiler\bin\Debug\Mandel.exe
Symbol information saved to report.

(The source code can be donwloaded from here: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/MSDNMag2008_03.exe

After extracting, it will be in a folder called: VSTSProfiler. Regardless, here is the pasted source code in case it goes down:)

using System;
using System.Xml;
using System.Xml.Serialization;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;

namespace Mandel
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        #region Auto
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(392, 266);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Mandel - Drawing...";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }
        #endregion

        Thread drawingThread = null;
        double xLowBound = -2.1;
        double yLowBound = -1.3;
        double xUpperBound = 1;
        double yUpperBound = 1.3;
        string colorsMap = "Green.Map";
        const bool COLOR = false;
        //This timer will check whether the drawing thread is still working
        //and update the title after it finishes:
        System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

        private void Form1_Load(object sender, System.EventArgs e)
        {
            //Setup the timer and hook to it
            timer.Interval = 200;
            timer.Tick += OnTimer;
            //Initialize and start the drawing thread:
            this.drawingThread = new Thread(new ThreadStart(this.DrawMandel));
            this.drawingThread.Start();
            timer.Start();
        }

        private void OnTimer(object sender, EventArgs args)
        {
            if (this.drawingThread.IsAlive)
            {
                this.Text = "Mandel - Generating Fractal...";
            }
            else
            {
                timer.Stop();
                this.Text = "Mandel - Ready";
            }
        }

        private void DrawMandel()
        {
            for (int i = 0; i < 5; i++)
            { //This loop was added purposely to slow the program down to measure performance.

                Color[] colors = ReadColorsMap(colorsMap);
                Bitmap bitmap = new Bitmap(Width, Height);

                //Uncomment the block below to avoid Bitmap.SetPixel:
                //BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                //IntPtr ptr = bmpData.Scan0;
                //int pixels = bitmap.Width * bitmap.Height;
                //Int32[] rgbValues = new Int32[pixels];

                double xStart = xLowBound;
                double yStart = yLowBound;
                double xEnd = xUpperBound;
                double yEnd = yUpperBound;
                double deltaX = (xEnd - xStart) / Width;
                double deltaY = (yEnd - yStart) / Height;
                double x = xStart;
                double y = yStart;

                for (int column = 1; column < Width; column++)
                {
                    y = yStart;
                    for (int row = 1; row < Height; row++)
                    {
                        double x1 = 0;
                        double y1 = 0;
                        int color = 0;
                        int dept = 0;
                        do
                        {
                            dept++;
                            double temp = (x1 * x1) - (y1 * y1) + x;
                            y1 = 2 * x1 * y1 + y;
                            x1 = temp;
                            double percentFactor = dept / (100.0);
                            color = ((int)(percentFactor * 255));
                        }
                        while (dept < 100 && Math.Sqrt((x1 * x1) + (y1 * y1)) < 2);
                        //Comment this line to avoid calling Bitmap.SetPixel:
                        bitmap.SetPixel(column, row, colors[color]);
                        //Uncomment the block below to avoid Bitmap.SetPixel:
                        //rgbValues[row * Width + column] = colors[color].ToArgb();

                        y += deltaY;
                    }
                    x += deltaX;
                }


                //Uncomment the block below to avoid Bitmap.SetPixel:
                //Marshal.Copy(rgbValues, 0, ptr, pixels);
                //bitmap.UnlockBits(bmpData);

                BackgroundImage = (Image)bitmap;
            }
        }


        private Color[] ReadColorsMap(string Path)
        {
            try
            {
                Color[] colors = new Color[256];
                List<string> colorLines = new List<string>();

                //Read the color definitions:
                using (StreamReader sr = new StreamReader(Path))
                {
                    while (!sr.EndOfStream)
                    {
                        string s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s))
                        {
                            colorLines.Add(s.Trim());
                        }
                    }
                }

                //Parse the definitions and store them in "colors" array
                if (colorLines.Count > colors.Length)
                {
                    throw new Exception(string.Format("Too many colors"));
                }

                int colorIndex = 0;
                foreach(string color in colorLines)
                {
                    string[] values = color.Split(' ');
                    if (values.Length != 3)
                    {
                        throw new Exception(string.Format("Map line: '{0}'", color));
                    }

                    int red = int.Parse(values[0]);
                    int green = int.Parse(values[1]);
                    int blue = int.Parse(values[2]);
                    colors[colorIndex++] = Color.FromArgb(red, green, blue);
                }

                //Set the rest to black:
                for (; colorIndex < colors.Length; colorIndex++)
                {
                    colors[colorIndex] = Color.Black;
                }

                return colors;
            }
            catch(Exception ex)
            {
                throw new Exception("Invalid ColorMap file.", ex);
            }
        }
    }
}

解决方案

Found out how:

  • Run the version of NGEN.exe from the same version of .NET you are compiling for. Example: C:\Windows\Microsoft.NET\Framework64\v4.0.30319
  • Give it the parameter createpdb
  • Specify the full path of the DLL you need to PDB for Specify the path of your assembly cache. Example: ngen.exe createpdb C:\windows\pathtoassembly.dll C:\SymbolCache

Final command that worked. I reloaded Visual Studio and was succesful after that. I used the same link Hans Passant posted incidentally.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>ngen createpdb "C:\Window
s\assembly\NativeImages_v4.0.30319_32\System.Drawing\ee1e19e1282f67f0466e281b535
69cd7\System.Drawing.ni.dll" C:\SymbolCache
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.17929
Copyright (c) Microsoft Corporation.  All rights reserved.
Successfully generated PDB for native assembly 'C:\Windows\assembly\NativeImages
_v4.0.30319_32\System.Drawing\ee1e19e1282f67f0466e281b53569cd7\System.Drawing.ni
.dll'.
PDB generated in directory C:\SymbolCache\System.Drawing.ni.pdb\ee1e19e1282f67f0
466e281b53569cd71\

这篇关于Visual Studio中探查显示DLL名称,而不是函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆