c# website - 分析代码和查询

Posted

技术标签:

【中文标题】c# website - 分析代码和查询【英文标题】:c# website - analysing code and queries 【发布时间】:2013-04-04 12:58:12 【问题描述】:

我正在开发一个预先存在的 c#/asp 网站,并且我正在尝试对其进行优化。

为此,我想了解在每个页面上进行了多少 SQL 查询。如果可能,找出它给服务器带来了多少负载,或者如果不可能,找出执行请求所花费的时间。

我可以使用哪些工具,我该怎么做?

我正在使用 Visual Studio 2012 Ultimate,并且正在连接到 SQL Server 2005。

【问题讨论】:

查询,你的意思是sql查询吗? @ManishMishra 是的。感谢您指出这一点,我已经更新了我的问题。 谢谢我得到了关于 Firebug 的答案。 :-S miniprofiler.com SQL Profiler 可能会帮助你,但你不会页面明智的查询列表。 【参考方案1】:

如果您想知道,在给定页面上,有多少 sql 查询进入您的数据库服务器,最好的分析方法是使用SQL Profiler。

SQL Profiler is a graphical tool that allows system administrators to monitor 
events in an instance of Microsoft® SQL Server™. You can capture and save data 
about each event to a file or SQL Server table to analyze later. For example,
you can monitor a production environment to see which stored procedures are 
hampering performance by executing too slowly.

阅读更多关于这个here和here

现在,如果您想根据其 Xhtml 标记分析页面的性能,有很多工具可以做到这一点。我使用并认为非常有用的是 Firefox 插件YSlow

YSlow analyzes web pages and suggests ways to improve their performance based 
on a set of rules for high performance web pages.

现在,如果您想在语义、性能、代码结构方面优化您的 C# 代码,请使用这个免费的 Microsoft.NET 工具FxCop。

FxCop is an application that analyzes managed code assemblies (code that 
targets the .NET Framework common language runtime) and reports information 
about the assemblies, such as possible design, localization, performance, 
and security improvements. Many of the issues concern violations of the 
programming and design rules set forth in the Design Guidelines, which are 
the Microsoft guidelines for writing robust and easily maintainable code by 
using the .NET Framework.

【讨论】:

【参考方案2】:

我还建议New Relic,它是一项商业服务,一开始是免费试用的,然后如果您不想付费,则将您转到免费的应用性能检查层。

我用它来检查我的应用程序中的瓶颈,它确实有助于发现问题。它会告诉您代码中花费最多时间的位置。

n.b 您需要完全访问服务器才能安装监控服务。

【讨论】:

以上是关于c# website - 分析代码和查询的主要内容,如果未能解决你的问题,请参考以下文章

Cakephp 2.2.3 habtm 保存到中间表

c#网站项目的发布:项目方式webSite网站模式(未能获得项目引用XXX的依赖项的解决)

使用 jQuery 更改浏览器中的后退按钮功能

utf8_bin 与 utf_unicode_ci

Java 8 – Convert List to Map

php 活动日历:在新窗口中打开活动链接。 - 与“制作事件标题链接到事件Websi”结合使用