创建profiler的存储过程:

USE [xxxDB]
GO /****** Object: StoredProcedure [dbo].[CreateProfile] Script Date: 2015/12/16 17:23:32 ******/
SET ANSI_NULLS ON
GO SET QUOTED_IDENTIFIER ON
GO CREATE proc [dbo].[CreateProfile]
as -- Create a Queue
declare @rc int
declare @TraceID int
declare @maxfilesize bigint
declare @tracefile nvarchar(256)
set @maxfilesize = 500
--设置最大跟踪文件的大小500M
set @tracefile = 'd:\tracefile\'+convert(char(8),getdate(),112)
-- Please replace the text InsertFileNameHere, with an appropriate
-- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension
-- will be appended to the filename automatically. If you are writing from
-- remote server to local drive, please use UNC path and make sure server has
-- write access to your network share exec @rc = sp_trace_create @TraceID output, 0, @tracefile, @maxfilesize, NULL
-- 创建跟踪
if (@rc != 0) goto error -- Client side File and Table cannot be scripted -- Set the events
--设置跟踪事件
-- sp_trace_setevent [ @traceid = ] trace_id , [ @eventid = ] event_id , [ @columnid = ] column_id , [ @on = ] on 其中on=1 开启 on=0 停止 on=2 关闭
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 10, 1, @on
exec sp_trace_setevent @TraceID, 10, 9, @on
exec sp_trace_setevent @TraceID, 10, 2, @on
exec sp_trace_setevent @TraceID, 10, 4, @on
exec sp_trace_setevent @TraceID, 10, 8, @on
exec sp_trace_setevent @TraceID, 10, 11, @on
exec sp_trace_setevent @TraceID, 10, 12, @on
exec sp_trace_setevent @TraceID, 10, 13, @on
exec sp_trace_setevent @TraceID, 10, 14, @on
exec sp_trace_setevent @TraceID, 10, 16, @on
exec sp_trace_setevent @TraceID, 10, 17, @on
exec sp_trace_setevent @TraceID, 10, 18, @on
exec sp_trace_setevent @TraceID, 10, 35, @on
exec sp_trace_setevent @TraceID, 10, 49, @on
exec sp_trace_setevent @TraceID, 12, 1, @on
exec sp_trace_setevent @TraceID, 12, 9, @on
exec sp_trace_setevent @TraceID, 12, 11, @on
exec sp_trace_setevent @TraceID, 12, 4, @on
exec sp_trace_setevent @TraceID, 12, 8, @on
exec sp_trace_setevent @TraceID, 12, 12, @on
exec sp_trace_setevent @TraceID, 12, 13, @on
exec sp_trace_setevent @TraceID, 12, 14, @on
exec sp_trace_setevent @TraceID, 12, 16, @on
exec sp_trace_setevent @TraceID, 12, 17, @on
exec sp_trace_setevent @TraceID, 12, 18, @on
exec sp_trace_setevent @TraceID, 12, 35, @on
exec sp_trace_setevent @TraceID, 12, 49, @on -- Set the Filters
declare @intfilter int
declare @bigintfilter bigint set @bigintfilter = 4000000
-- duration的最大时间
exec sp_trace_setfilter @TraceID, 13, 0, 4, @bigintfilter -- Set the trace status to start
exec sp_trace_setstatus @TraceID, 1 -- display trace id for future references
select TraceID=@TraceID
goto finish error:
select ErrorCode=@rc finish: GO

结束profiler的存储过程(profiler查询消耗的是系统内存):

Create proc [dbo].[StopProfile]
as declare @traceid int select @traceid = id
from sys.traces
where path like 'd:\tracefile%'
-- path 为跟踪文件的存储路径 exec sp_trace_setstatus @traceid,0 exec sp_trace_setstatus @traceid,2

具体profiler的开启关闭的时间,可以在sqlserver代理的作业中根据需要更改。

profiler加入计划任务的更多相关文章

  1. SQL Server 利用Profiler观察执行计划是否重用时SP:Cachemiss,SP:CacheInsert以及SP:CacheHit的含义

    本文出处:http://www.cnblogs.com/wy123/p/6913055.html 执行计划的缓存与重用 在通过SQL Profile观察一个SQL语句或者存储过程是否有可用的缓存执行计 ...

  2. [网站性能3]SqlServer中Profiler的使用

    原文链接:http://www.cnblogs.com/caishuhua226/p/3838060.html   http://www.cnblogs.com/lyhabc/articles/294 ...

  3. SQL执行效率2-执行计划

    以下语句可以进行SQL 语句执行时间分析,两个Go之间就是SQL查询语句 use Work--数据库名 go set statistics profile on set statistics io o ...

  4. SQL Server 执行计划缓存

    标签:SQL SERVER/MSSQL SERVER/数据库/DBA/内存池/缓冲区 概述 了解执行计划对数据库性能分析很重要,其中涉及到了语句性能分析与存储,这也是写这篇文章的目的,在了解执行计划之 ...

  5. 程序员眼中的 SQL Server-执行计划教会我如何创建索引?

    先说点废话 以前有 DBA 在身边的时候,从来不曾考虑过数据库性能的问题,但是,当一个应用程序从头到脚都由自己完成,而且数据库面对的是接近百万的数据,看着一个页面加载速度像乌龟一样,自己心里真是有种挫 ...

  6. 谈一谈SQL Server中的执行计划缓存(上)

    简介 我们平时所写的SQL语句本质只是获取数据的逻辑,而不是获取数据的物理路径.当我们写的SQL语句传到SQL Server的时候,查询分析器会将语句依次进行解析(Parse).绑定(Bind).查询 ...

  7. MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划

    这篇文章主要介绍了MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划的相关资料,需要的朋友可以参考下 一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存 ...

  8. SQL Server Profiler

    一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收集查询信息: 分析性能: 诊断像死锁之类的问 ...

  9. SQL Server Profiler教程

    SQL Server Profiler是SQL Server企业版自带的一个sql 语句跟踪和分析工具,功能十分强大.熟练地使用它,对我们分析数据库性能问题很有帮助,比如当数据访问使用EF等ORM框架 ...

随机推荐

  1. git commit --amend

    任何时候,你都有可能需要撤消刚才所做的某些操作.接下来,我们会介绍一些基本的撤消操作相关的命令.请注意,有些撤销操作是不可逆的,所以请务必谨慎小心,一旦失误,就有可能丢失部分工作成果. 有时候我们提交 ...

  2. laravel打印sql语句

    打印sql语句,直接在你执行SQL语句后输出 方法一: $queries = DB::getQueryLog(); $a = end($queries); $tmp = str_replace('?' ...

  3. Mean Shift Tracking: 2000-2012回顾 (新论文更新)

    参考: Mean Shift Tracking: 2000-2012回顾 (新论文更新) ECCV2016要来了,估计深度学习要一统天下了吧

  4. linux定时执行脚本

    阅读目录 1. cron服务[Ubuntu环境] 2. crontab用法 3. 编辑crontab文件 4. 流程举例 5. 几个例子 Linux中,周期执行的任务一般由cron这个守护进程来处理. ...

  5. 3. Android程序生成步骤

      主要流程如下图所示:       所需要的工具列表 名称 功能介绍 在操作系统中的路径 aapt Android资源打包工具 ${ANDROID_SDK_HOME}/platform-tools/ ...

  6. VQuery选择器

    VQUery elements属性,储存选中的元素 参数 typeof的作用 字符串 class  ID tagName 函数 事件绑定 对象 直接插入 $函数 绑定事件 click方法 显示隐藏,- ...

  7. 【leetcode】Edit Distance

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert  ...

  8. android气泡消息提醒布局

    无论是anroid还是ios,气泡消息提醒再正常不过了.然而要定义一个气泡消息提醒确要费一番周折.下面记录下气泡提醒布局. 定义气泡背景shape_unread_message_bg.xml < ...

  9. ios delegate 使用注意 assign,weak

    今天一个同事写代码,把一个delegate对象设定成了assign类型属性,没有用weak,就是delegate对象释放后,不会把delegate指针自动设定为nil,把对象的delegate设定成了 ...

  10. linux学习之-vsftp

    一.简介 vsftp是一个基于GPL发布的类unix系统上使用的ftp服务器软件,它的全称是very secure FTP ,软件的编写初衷是为了代码的安全,另外高速与高稳定性也是vsftp的两个重要 ...