Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing max_rollover_files option in definition of event session target file leads to lost of coverage info #81

Open
DmytroHavrylov opened this issue Sep 21, 2022 · 1 comment

Comments

@DmytroHavrylov
Copy link

DmytroHavrylov commented Sep 21, 2022

When using SQLCover.dll to gather coverage information on large project with great amount of TSQLT tests we found that MSSQLServer creates only 5 trace files (SQLCover-Trace-*.xel), and then overwrites older files. Each file size is close to 1GB.

@@Version = Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows Server 2016 Datacenter 6.3 (Build 14393: ) (Hypervisor)

The reason of the problem: when creating event session with asynchronous_file_target, parameter max_rollover_files is not defined. Default value for max_rollover_files in MSSQL is 5, therefore after writing 5 files it overwrites first one, so coverage information for first tests gets lost before reading.

Fix: to solve that problem we had to modify \src\SQLCover\SQLCoverLib\Trace\SqlTraceController.cs by adding max_rollover_files=(999) into definition of target in constant CreateTrace. Fixed line with max_rollover_files added looks like this:

 protected const string CreateTrace = @"CREATE EVENT SESSION [{0}] ON SERVER 
ADD EVENT sqlserver.sp_statement_starting(action (sqlserver.plan_handle, sqlserver.tsql_stack) where ([sqlserver].[database_id]=({1})))
ADD TARGET package0.asynchronous_file_target(
     SET filename='{2}', max_rollover_files=(999))
WITH (MAX_MEMORY=100 MB,EVENT_RETENTION_MODE=NO_EVENT_LOSS,MAX_DISPATCH_LATENCY=1 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF) 
";

@shortall
Copy link

shortall commented Jan 4, 2023

Thanks @DmytroHavrylov , this resolved the same issue for us. I also found adding source_database_id=({1}) to the where clause of the ADD EVENT definition filtered out a lot of events that weren't needed and keeps the xel files smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants