Esempio n. 1
0
        internal static async Task Output(string[] filePaths, string outputFilePath, string[] storedProcedureNames)
        {
            var          matchCriteria = StoredProcedureSearch.CreateMatchCriteria(storedProcedureNames);
            List <Event> events        = new List <Event>();

            foreach (var filePath in filePaths)
            {
                if (!Regex.IsMatch(Path.GetFileName(filePath), @"^replay\d+\.txt$", RegexOptions.IgnoreCase))
                {
                    //ignore any files that don't fit the pattern of replay files outputted from prep or prepnosc
                    continue;
                }
                Run run = await DeserializeRun(filePath);

                events.AddRange(run.Sessions.SelectMany(s => s.Events)
                                .Where(e => matchCriteria.Any(
                                           mc => ((e as Rpc)?.Procedure?.Equals(mc, StringComparison.CurrentCultureIgnoreCase)).GetValueOrDefault())).ToArray());
                foreach (var evt in events)
                {
                    ((Rpc)evt).TimeElapsedInMilliseconds =
                        (int)evt.Timestamp.Subtract(run.EventCaptureOrigin).TotalMilliseconds;
                }
            }
            await File.WriteAllTextAsync(outputFilePath, JsonConvert.SerializeObject(events.OrderBy(e => e.EventSequence)));
        }
Esempio n. 2
0
        public Task WarmupAsync(Run run, int durationInMinutes, string[] storedProcedureNamesToInclude)
        {
            var matchCriteria = StoredProcedureSearch.CreateMatchCriteria(storedProcedureNamesToInclude);

            if (matchCriteria.Any())
            {
                if (durationInMinutes > 0)
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !(matchCriteria.Any(mc =>
                                                                          ((e as Rpc)?.Procedure?.Equals(mc,
                                                                                                         StringComparison.CurrentCultureIgnoreCase)).GetValueOrDefault()) &&
                                                        e.Timestamp < run.EventCaptureOrigin.AddMinutes(durationInMinutes)));
                    }
                }
                else
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !matchCriteria.Any(mc =>
                                                                         ((e as Rpc)?.Procedure?.Equals(mc,
                                                                                                        StringComparison.CurrentCultureIgnoreCase)).GetValueOrDefault()));
                    }
                }
            }
            else
            {
                return(Task.CompletedTask);
            }
            return(RunEventsAsync(run));
        }
Esempio n. 3
0
        private void DuplicateEvents(Run run, byte factor)
        {
            var storedProcedureNames = new string[]
            {
                "procedure I want to duplicate, including schema"
            };
            var matchCriteria = StoredProcedureSearch.CreateMatchCriteria(storedProcedureNames);

            foreach (var session in run.Sessions)
            {
                var duplicates = new List <Rpc>();
                foreach (var evt in session.Events)
                {
                    if (!(evt is Rpc rpc))
                    {
                        continue;
                    }
                    if (!matchCriteria.Any(mc => (rpc.Procedure?.Equals(mc, StringComparison.CurrentCultureIgnoreCase)).GetValueOrDefault()))
                    {
                        continue;
                    }
                    for (byte i = 0; i < factor - 1; i++)
                    {
                        var duplicate = new Rpc
                        {
                            EventSequence = rpc.EventSequence,
                            Statement     = rpc.Statement,
                            ObjectName    = rpc.ObjectName,
                            Procedure     = rpc.Procedure,
                            Parameters    = rpc.Parameters, //safe to share reference as this list will only be read from
                            Timestamp     = rpc.Timestamp.AddMilliseconds(500 * (i + 1)),
                            TransactionId = "0"             //don't share transaction ID to avoid duplicates and original from conflicting in one transaction
                        };
                        duplicates.Add(duplicate);
                    }
                }
                session.Events.AddRange(duplicates);
            }
        }
Esempio n. 4
0
        public Task RunAsync(Run run, DateTimeOffset restorePoint, int durationInMinutes, string[] storedProcedureNamesToExclude)
        {
            var matchCriteria = StoredProcedureSearch.CreateMatchCriteria(storedProcedureNamesToExclude);

            if (matchCriteria.Any())
            {
                if (durationInMinutes > 0)
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !(!matchCriteria.Any(mc =>
                                                                           ((e as Rpc)?.Procedure?.Equals(mc, StringComparison.CurrentCultureIgnoreCase))
                                                                           .GetValueOrDefault()) &&
                                                        e.Timestamp > restorePoint &&
                                                        e.Timestamp < run.EventCaptureOrigin.AddMinutes(durationInMinutes)));
                    }
                }
                else
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !(!matchCriteria.Any(mc =>
                                                                           ((e as Rpc)?.Procedure?.Equals(mc, StringComparison.CurrentCultureIgnoreCase))
                                                                           .GetValueOrDefault()) &&
                                                        e.Timestamp > restorePoint));
                    }
                }
            }
            else
            {
                if (durationInMinutes > 0)
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !(e.Timestamp > restorePoint &&
                                                        e.Timestamp < run.EventCaptureOrigin.AddMinutes(durationInMinutes)));
                    }
                }
                else
                {
                    foreach (var session in run.Sessions)
                    {
                        session.Events.RemoveAll(e => !(e.Timestamp > restorePoint));
                    }
                }
            }
            foreach (var session in run.Sessions)
            {
                session.Events.RemoveAll(e =>
                {
                    if (e is Rpc rpc && rpc.Statement != null)
                    {
                        return(rpc.Statement.Contains("OPENROWSET", StringComparison.CurrentCultureIgnoreCase) ||
                               rpc.Statement.Contains("OPENDATASOURCE", StringComparison.CurrentCultureIgnoreCase));
                    }

                    return(false);
                });
            }
            run.EventCaptureOrigin = restorePoint;
            return(RunEventsAsync(run));
        }