sql - Getting parameters and their values of a stored procedure via DMVs -
i have stored procedure using dmvs returns performance statistics on stored procedures. in using tool @ sp performance, found of complex stored procedures have multiple cached plans. stored procedures in question have lot of parameters , performance varies dramatically across cached plans, therefore, want examine how these stored procedures being called. parameters have values (other default).
is there way stored procedure command being called in result set via dmv?
for example, hope able see like: "exec myprocname @param1=value1, @param2=value2, @paramn=valuen"
the second question have on subject multiple instances of cached plans per stored procedure. thought there multiple plans if procedure called varying parameter values (enough variation change or generate new plan). on track here or way off base?
here definition of current stored proc uses sys.dm_exec_procedure_stats dmv:
alter procedure [dbo].[bss_stored_procedure_performance] @dt_start datetime = null ,@dt_end datetime = null ,@db_name varchar(100) = null ,@sp_name varchar(100) = null ,@sort_col varchar(25) = 'avg physical reads' ,@sort_asc bit = 0 ,@record bit = 0 begin set nocount on; if @dt_start null begin set @dt_start = current_timestamp - 3 set @dt_end = current_timestamp end select x.* ( select case when database_id = 32767 'resource' else db_name(database_id)end dbname ,object_schema_name(object_id,database_id) [schema] ,object_name(object_id,database_id)as [obj name] ,type_desc [object type] ,cached_time [cached dt] ,last_execution_time [last execute dt] ,last_elapsed_time [last duration] ,cast(last_elapsed_time*.000001 decimal(9,2)) [last duration / seconds] ,execution_count [execution count] ,total_worker_time / execution_count [avg cpu] ,min_elapsed_time [min duration] ,total_elapsed_time / execution_count [avg duration] ,max_elapsed_time [max duration] ,total_logical_reads / execution_count [avg logical reads] ,total_logical_writes / execution_count [avg logical writes] ,total_physical_reads / execution_count [avg physical reads] sys.dm_exec_procedure_stats last_execution_time between @dt_start , @dt_end , ((@db_name null) or (db_name(database_id) = @db_name)) , ((@sp_name null) or (object_name(object_id,database_id) '%' + @sp_name + '%')) ) x order case when @sort_col = 'avg physical reads' , @sort_asc = 1 [avg physical reads] end asc, case when @sort_col = 'avg physical reads' , @sort_asc = 0 [avg physical reads] end desc, case when @sort_col = 'last execute dt' , @sort_asc = 1 [last execute dt] end asc, case when @sort_col = 'last execute dt' , @sort_asc = 0 [last execute dt] end desc print 'date range: ' + convert(varchar(50),@dt_start) + ' -- -- ' + convert(varchar(50),@dt_end)
Comments
Post a Comment