public void PopulateTraceAttributesFromPackageContents(Trace trace, string pathToUnzippedPackage)
 {
     var supplementalFile =
         Directory.EnumerateFileSystemEntries(pathToUnzippedPackage, BxrRSupplementalDataFileNamePattern)
             .FirstOrDefault();
     if (supplementalFile == null) return;
     foreach (var line in File.ReadLines(supplementalFile))
     {
         var matchInfo = Regex.Match(line, BxrRKeyValuePattern, RegexOptions.IgnoreCase);
         if (!matchInfo.Success) continue;
         var itemName = matchInfo.Groups[1].Value;
         var itemValue = matchInfo.Groups[2].Value;
         if (string.IsNullOrWhiteSpace(itemName) || string.IsNullOrWhiteSpace(itemValue)) continue;
         if (string.Equals(itemName, "ProductSKU", StringComparison.OrdinalIgnoreCase)) continue;
         if (string.Equals(itemName, "ProcessorIDsMerged", StringComparison.OrdinalIgnoreCase)) continue;
         var attr = new TraceAttribute
         {
             Name = itemName,
             StringValue = itemValue
         };
         if (string.Equals(attr.Name, "OSInstallDateWMI", StringComparison.OrdinalIgnoreCase))
             attr.DateTimeValue = ManagementDateTimeConverter.ToDateTime(attr.StringValue);
         if (string.Equals(attr.Name, "manufacturer", StringComparison.Ordinal))
             attr.Name = "Manufacturer";
         trace.AddMeasurement(attr);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Checks liveness at a trace cycle.
        /// </summary>
        /// <param name="root">Cycle start</param>
        internal void CheckLivenessAtTraceCycle(Fingerprint root, Trace trace)
        {
            var cycle = new List<TraceStep>();

            do
            {
                Output.Debug(DebugType.Liveness, "<LivenessDebug> Cycle contains {0}.",
                    trace.Peek().Fingerprint.ToString());
                cycle.Add(trace.Pop());
            }
            while (trace.Peek() != null && !trace.Peek().Fingerprint.Equals(root));

            if (!this.IsSchedulingFair(cycle))
            {
                Output.Debug(DebugType.Liveness, "<LivenessDebug> Scheduling in cycle is unfair.");
                return;
            }
            else if (!this.IsNondeterminismFair(cycle))
            {
                Output.Debug(DebugType.Liveness, "<LivenessDebug> Nondeterminism in cycle is unfair.");
                return;
            }

            Output.Debug(DebugType.Liveness, "<LivenessDebug> Cycle execution is fair.");

            var hotMonitors = this.GetHotMonitors(cycle);
            foreach (var monitor in hotMonitors)
            {
                string message = Output.Format("Monitor '{0}' detected infinite execution that " +
                    "violates a liveness property.", monitor.GetType().Name);
                PSharpRuntime.BugFinder.NotifyAssertionFailure(message, false);
            }

            PSharpRuntime.BugFinder.Stop();
        }
        public virtual void Write(Trace t) {

            writer.Write("\n--------------\n Trace from {0:yyyy-MM-dd HH:mm:ss.fff} to {1:yyyy-MM-dd HH:mm:ss.fff} \n entries:", t.Start, t.End);
            foreach (Entry e in t.Entries)
            {
                Write(e, 0);
            }
            writer.Write("\n--------------\n");
            
        }
 public void PopulateTraceAttributesFromFileName(Trace trace, string filePath)
 {
     if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath));
     var fileInfo = new FileInfo(filePath);
     if (!fileInfo.Exists) throw new FileNotFoundException(filePath, filePath);
     trace.PackageFileNameFull = filePath;
     trace.PackageFileName = fileInfo.Name;
     trace.TracePackageTime =
         new[] {fileInfo.LastWriteTimeUtc, fileInfo.CreationTimeUtc}.OrderBy(t => t.ToFileTimeUtc())
             .Last();
 }
Beispiel #5
0
 public FrontierNode(TraversalInfo ti)
 {
     this.Bounds = new ZingerBounds(ti.zBounds.ExecutionCost, ti.zBounds.ChoiceCost);
     if (ZingerConfiguration.DoDelayBounding)
     {
         schedulerState = ti.ZingDBSchedState.Clone(true);
     }
     else if (ZingerConfiguration.DoPreemptionBounding)
     {
         preemptionBounding = ti.preemptionBounding.Clone();
     }
     ti.IsFingerPrinted = true;
     TheTrace = ti.GenerateTrace();
 }
Beispiel #6
0
        private void handleData()
        {
            while (pendingRoutes.Count != 0)
            {
                Node node = pendingRoutes[0];
                pendingRoutes.Remove(node);

                foreach (Node solvedRoute in solvedRoutes)
                {
                    if (!solvedRoute.Routes.ContainsKey(node.Name) || solvedRoute.Routes[node.Name] == -1)
                    {
                        break;
                    }

                    var cost = solvedRoute.Routes[node.Name];

                    foreach (KeyValuePair<int, int> pair in node.Routes)
                    {
                        if (pair.Value == -1)
                        {
                            continue;
                        }

                        int originalCost = solvedRoute.Routes.ContainsKey(pair.Key)
                            ? solvedRoute.Routes[pair.Key]
                            : Int32.MaxValue;
                        if (originalCost == -1 || originalCost > cost + pair.Value)
                        {
                            solvedRoute.Routes[pair.Key] = cost + pair.Value;
                            Trace trace = null;
                            if (!solvedRoute.Traces.ContainsKey(pair.Key))
                            {
                                trace = new Trace();
                                solvedRoute.Traces.Add(pair.Key, trace);
                            }
                            else
                            {
                                trace = solvedRoute.Traces[pair.Key];
                            }
                            trace.Nodes.Clear();
                            trace.Nodes.Add(solvedRoute.Name);
                            trace.AppendTrace(node.Traces[pair.Key]);
                        }
                    }
                }

                solvedRoutes.Add(node);
            }
        }
 public void PopulateTraceAttributesFromFileName(Trace trace, string filePath)
 {
     var fileNameRelative = Path.GetFileName(filePath);
     if (string.IsNullOrEmpty(fileNameRelative)) throw new ArgumentNullException(nameof(fileNameRelative));
     var match = Regex.Match(fileNameRelative, IcuFileNamePattern, RegexOptions.IgnoreCase);
     if (match.Success)
     {
         trace.ComputerName = match.Groups["ComputerName"].Value;
         var tracestartDateTimeString = match.Groups["DateTime"].Value;
         trace.TracePackageTime = DateTime.ParseExact(tracestartDateTimeString, IcuDateTimeStringFormat,
             new DateTimeFormatInfo());
         trace.AddMeasurement(new TraceAttribute
         {
             Name = "Trigger",
             StringValue = match.Groups["TriggerName"].Value
         });
     }
 }
 public void PopulateTraceAttributesFromPackageContents(Trace trace, string pathToUnzippedPackage)
 {
     foreach (var emailAddress in GetIcuEmailReportToAddresses(pathToUnzippedPackage))
     {
         trace.AddMeasurement(new TraceAttribute
         {
             Name = NameOfIcuMetaEmailReportToAttribute,
             StringValue = emailAddress
         });
     }
     foreach (var userNote in GetIseUserInitiatedNote(pathToUnzippedPackage))
     {
         trace.AddMeasurement(new TraceAttribute
         {
             Name = NameOfIcuUserNoteAttribute,
             StringValue = userNote
         });
     }
 }
Beispiel #9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 internal StateExplorer()
 {
     this.Trace = new Trace();
     this.Fingerprints = new HashSet<Fingerprint>();
 }
 private void DeleteUnusedIndexes_FormClosed(object sender, FormClosedEventArgs e)
 {
     try
     {
         if (trc != null)
         {
             try
             {
                 trc.Drop();
             }
             catch { }
             trc = null;
         }
     }
     catch { }
 }
        /// <summary>
        /// Deserializes a trace from an XML Error file.
        /// </summary>
        /// <param name="reader">XML Error file.</param>
        /// <param name="trace">Trace to obtain.</param>
        /// <returns>Trace.</returns>
        public static Trace Deserialize(XmlReader reader, Trace trace)
        {
            if (reader.IsStartElement(DTD.Error.ErrorTrace.TagErrorTraceItem))
            {
                if (trace == null)
                {
                    trace = new Trace();
                }

                // Read Attributes.
                trace.Number = reader.GetAttribute(DTD.Error.ErrorTrace.TagNumber);
                switch (reader.GetAttribute(DTD.Error.ErrorTrace.TagType))
                {
                case ResponseException.ErrorExternal:
                    trace.Type = ErrorTraceType.External;
                    break;
                case ResponseException.ErrorModel:
                    trace.Type = ErrorTraceType.Model;
                    break;
                }

                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement();

                    do
                    {
                        if (reader.IsStartElement(DTD.Error.TagErrorMessage))
                        {
                            if (!reader.IsEmptyElement)
                            {
                                trace.Message = reader.ReadString();
                            }
                            else
                            {
                                reader.Skip();
                                if (reader.NodeType == XmlNodeType.None)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            if (reader.IsStartElement(DTD.Error.TagErrorParams))
                            {
                                trace.Parameters = XMLErrorParamsSerialize.Deserialize(reader.ReadSubtree(), null);
                            }
                            else
                            {
                                reader.Skip();
                                if (reader.NodeType == XmlNodeType.None)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    } while (reader.Read());
                }
                else
                {
                    reader.Skip();
                }
            }
            return trace;
        }
        /// <summary>
        /// Translate strings from the business logic layer depending on the current culture.
        /// </summary>
        /// <param name="trace">Bussiness Logic exception trace element.</param>
        /// <returns>Translated string.</returns>
        public static string TranslateBusinessLogicException(Trace trace)
        {
            string lTranslatedString = string.Empty;

            if (trace == null)
            {
                return lTranslatedString;
            }

            // If there is not multilanguage, return the business logic exception message directly.
            if (SupportedLanguages.Count <= 1)
            {
                return trace.Message;
            }
            // If there is multilanguage, translate the business logic exception message depending on the culture.
            else
            {
                lTranslatedString = TranslateString("e" + trace.Number, trace.Message);
                if (trace.Parameters != null)
                {
                    string lSearchedKey = string.Empty;
                    for (int lKeyIndex = 0; lKeyIndex < trace.Parameters.Count; lKeyIndex++)
                    {
                        lSearchedKey = "{" + trace.Parameters[lKeyIndex].Key + "}";

                        // Keyed value.
                        if (trace.Parameters[lKeyIndex].Type == ErrorParamType.Key)
                        {
                            // The text to replace must be taken from language resources.
                            string lTranslatedKey = TranslateString(trace.Parameters[lKeyIndex].Text, string.Empty);
                            lTranslatedString = lTranslatedString.Replace(lSearchedKey, lTranslatedKey);
                        }
                        // Literal value.
                        else if (trace.Parameters[lKeyIndex].Type == ErrorParamType.Literal)
                        {
                            // The text to replace must be taken directly from the exception.
                            lTranslatedString = lTranslatedString.Replace(lSearchedKey, trace.Parameters[lKeyIndex].Text);
                        }
                    }
                }
            }

            return lTranslatedString;
        }
        private void FinishExecute(bool bShowResults)
        {
            if (this.InvokeRequired)
            {
                //important to show the notification on the main thread of BIDS
                this.BeginInvoke(new MethodInvoker(delegate() { FinishExecute(bShowResults); }));
            }
            else
            {
                try
                {
                    if (trc != null)
                    {
                        try
                        {
                            trc.Drop();
                        }
                        catch { }
                        trc = null;
                    }

                    bExecuting = false;
                    this.radioTraceTypeLive.Enabled = true;
                    this.radioTraceTypeSQL.Enabled = true;
                    this.btnSQLConnection.Enabled = true;
                    this.btnExecute.Text = "Execute";
                    this.btnExecute.Enabled = true;
                    timer1.Enabled = false;
                    if (bShowResults)
                    {
                        this.treeViewAggregation.Visible = true;
                        this.lblUnusedAggregationsToDelete.Visible = true;
                        this.Height = this.iWindowFullHeight;
                        this.buttonCancel.Visible = true;
                        this.buttonOK.Visible = true;

                        treeViewAggregation.Nodes.Clear();
                        this.treeViewAggregation.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewAggregation_AfterCheck);
                        FillTree();
                        treeViewAggregation.ExpandAll();
                        if (treeViewAggregation.Nodes.Count > 0) treeViewAggregation.Nodes[0].EnsureVisible();
                        this.treeViewAggregation.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewAggregation_AfterCheck);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #14
0
        private void SetupTrace(Trace trace)
        {
            // Add CommandBegin so we can catch the heartbeat events
            if (trace.Events.Find(TraceEventClass.CommandBegin) == null)
                trace.Events.Add(TraceEventFactory.Create(TraceEventClass.CommandBegin));
            // Add QueryEnd so we know when to stop the trace
            if (trace.Events.Find(TraceEventClass.QueryEnd)==null)
                trace.Events.Add(TraceEventFactory.Create(TraceEventClass.QueryEnd));

            //foreach (var watcher in CheckedTraceWatchers)
            foreach (var watcher in AvailableTraceWatchers)
            {
                //reset the watcher so it can clear any cached events
                watcher.Reset();
                // catch the events in the ITraceWatcher
                foreach (TraceEventClass eventClass in watcher.MonitoredEvents)
                {
                    if (trace.Events.Find(eventClass) != null)
                        continue;

                    var trcEvent = TraceEventFactory.Create(eventClass);
                    trace.Events.Add(trcEvent);
                }
            }

            trace.Update();
        }
        public override void Mangle(CilBody body, ScopeBlock root, CFContext ctx)
        {
            Trace trace = new Trace(body, ctx.Method.ReturnType.RemoveModifiers().ElementType != ElementType.Void);
            var local = new Local(ctx.Method.Module.CorLibTypes.UInt32);
            body.Variables.Add(local);
            body.InitLocals = true;

            body.MaxStack += 2;
            IPredicate predicate = null;
            if (ctx.Predicate == PredicateType.Normal) {
                predicate = new NormalPredicate(ctx);
            }
            else if (ctx.Predicate == PredicateType.Expression) {
                predicate = new ExpressionPredicate(ctx);
            }
            else if (ctx.Predicate == PredicateType.x86) {
                predicate = new x86Predicate(ctx);
            }

            foreach (InstrBlock block in GetAllBlocks(root)) {
                LinkedList<Instruction[]> statements = SpiltStatements(block, trace, ctx);

                // Make sure .ctor is executed before switch
                if (ctx.Method.IsInstanceConstructor) {
                    var newStatement = new List<Instruction>();
                    while (statements.First != null) {
                        newStatement.AddRange(statements.First.Value);
                        Instruction lastInstr = statements.First.Value.Last();
                        statements.RemoveFirst();
                        if (lastInstr.OpCode == OpCodes.Call && ((IMethod)lastInstr.Operand).Name == ".ctor")
                            break;
                    }
                    statements.AddFirst(newStatement.ToArray());
                }

                if (statements.Count < 3) continue;

                int i;

                var keyId = Enumerable.Range(0, statements.Count).ToArray();
                ctx.Random.Shuffle(keyId);
                var key = new int[keyId.Length];
                for (i = 0; i < key.Length; i++) {
                    var q = ctx.Random.NextInt32() & 0x7fffffff;
                    key[i] = q - q % statements.Count + keyId[i];
                }

                var statementKeys = new Dictionary<Instruction, int>();
                LinkedListNode<Instruction[]> current = statements.First;
                i = 0;
                while (current != null) {
                    if (i != 0)
                        statementKeys[current.Value[0]] = key[i];
                    i++;
                    current = current.Next;
                }

                var statementLast = new HashSet<Instruction>(statements.Select(st => st.Last()));

                Func<IList<Instruction>, bool> hasUnknownSource;
                hasUnknownSource = instrs => instrs.Any(instr => {
                    if (trace.HasMultipleSources(instr.Offset))
                        return true;
                    List<Instruction> srcs;
                    if (trace.BrRefs.TryGetValue(instr.Offset, out srcs)) {
                        // Target of switch => assume unknown
                        if (srcs.Any(src => src.Operand is Instruction[]))
                            return true;

                        // Not within current instruction block / targeted in first statement
                        if (srcs.Any(src => src.Offset <= statements.First.Value.Last().Offset ||
                                            src.Offset >= block.Instructions.Last().Offset))
                            return true;

                        // Not targeted by the last of statements
                        if (srcs.Any(src => statementLast.Contains(src)))
                            return true;
                    }
                    return false;
                });

                var switchInstr = new Instruction(OpCodes.Switch);
                var switchHdr = new List<Instruction>();

                if (predicate != null) {
                    predicate.Init(body);
                    switchHdr.Add(Instruction.CreateLdcI4(predicate.GetSwitchKey(key[1])));
                    predicate.EmitSwitchLoad(switchHdr);
                }
                else {
                    switchHdr.Add(Instruction.CreateLdcI4(key[1]));
                }

                switchHdr.Add(Instruction.Create(OpCodes.Dup));
                switchHdr.Add(Instruction.Create(OpCodes.Stloc, local));
                switchHdr.Add(Instruction.Create(OpCodes.Ldc_I4, statements.Count));
                switchHdr.Add(Instruction.Create(OpCodes.Rem_Un));
                switchHdr.Add(switchInstr);

                if (trace.BeforeStack[statements.Last.Value[0].Offset] == 0)
                {
                    ctx.AddJump(switchHdr, statements.Last.Value[0]);
                }
                else
                {
                    ctx.AddJump(switchHdr, switchHdr[0]);
                }
                ctx.AddJunk(switchHdr);

                var operands = new Instruction[statements.Count];
                current = statements.First;
                i = 0;
                while (current.Next != null) {
                    var newStatement = new List<Instruction>(current.Value);

                    if (i != 0) {
                        // Convert to switch
                        bool converted = false;

                        if (newStatement.Last().IsBr()) {
                            // Unconditional

                            var target = (Instruction)newStatement.Last().Operand;
                            int brKey;
                            if (!trace.IsBranchTarget(newStatement.Last().Offset) &&
                                statementKeys.TryGetValue(target, out brKey)) {

                                if (trace.BeforeStack[target.Offset] == 0)
                                {
                                    var targetKey = predicate != null ? predicate.GetSwitchKey(brKey) : brKey;
                                    var unkSrc = hasUnknownSource(newStatement);

                                    var initialBeforeStack = trace.BeforeStack[newStatement[0].Offset];
                                    newStatement.RemoveAt(newStatement.Count - 1);

                                    if (unkSrc || initialBeforeStack != 0) {
                                        newStatement.Add(Instruction.Create(OpCodes.Ldc_I4, targetKey));
                                    }
                                    else {
                                        var thisKey = key[i];
                                        var r = ctx.Random.NextInt32();
                                        newStatement.Add(Instruction.Create(OpCodes.Ldloc, local));
                                        newStatement.Add(Instruction.CreateLdcI4(r));
                                        newStatement.Add(Instruction.Create(OpCodes.Mul));
                                        newStatement.Add(Instruction.Create(OpCodes.Ldc_I4, (thisKey * r) ^ targetKey));
                                        newStatement.Add(Instruction.Create(OpCodes.Xor));
                                    }

                                    ctx.AddJump(newStatement, switchHdr[1]);
                                    ctx.AddJunk(newStatement);
                                }

                                if (trace.BeforeStack[newStatement[0].Offset] == 0)
                                {
                                    operands[keyId[i]] = newStatement[0];
                                }

                                converted = true;
                            }
                        }
                        else if (newStatement.Last().IsConditionalBranch()) {
                            // Conditional

                            var target = (Instruction)newStatement.Last().Operand;
                            int brKey;
                            if (!trace.IsBranchTarget(newStatement.Last().Offset) &&
                                statementKeys.TryGetValue(target, out brKey)) {

                                if (trace.BeforeStack[target.Offset] == 0)
                                {
                                    bool unkSrc = hasUnknownSource(newStatement);
                                    int nextKey = key[i + 1];
                                    OpCode condBr = newStatement.Last().OpCode;
                                    newStatement.RemoveAt(newStatement.Count - 1);

                                    if (ctx.Random.NextBoolean()) {
                                        condBr = InverseBranch(condBr);
                                        int tmp = brKey;
                                        brKey = nextKey;
                                        nextKey = tmp;
                                    }

                                    var thisKey = key[i];
                                    int r = 0, xorKey = 0;
                                    if (!unkSrc) {
                                        r = ctx.Random.NextInt32();
                                        xorKey = thisKey * r;
                                    }

                                    Instruction brKeyInstr = Instruction.CreateLdcI4(xorKey ^ (predicate != null ? predicate.GetSwitchKey(brKey) : brKey));
                                    Instruction nextKeyInstr = Instruction.CreateLdcI4(xorKey ^ (predicate != null ? predicate.GetSwitchKey(nextKey) : nextKey));
                                    Instruction pop = Instruction.Create(OpCodes.Pop);

                                    newStatement.Add(Instruction.Create(condBr, brKeyInstr));
                                    newStatement.Add(nextKeyInstr);
                                    newStatement.Add(Instruction.Create(OpCodes.Dup));
                                    newStatement.Add(Instruction.Create(OpCodes.Br, pop));
                                    newStatement.Add(brKeyInstr);
                                    newStatement.Add(Instruction.Create(OpCodes.Dup));
                                    newStatement.Add(pop);

                                    if (!unkSrc) {
                                        newStatement.Add(Instruction.Create(OpCodes.Ldloc, local));
                                        newStatement.Add(Instruction.CreateLdcI4(r));
                                        newStatement.Add(Instruction.Create(OpCodes.Mul));
                                        newStatement.Add(Instruction.Create(OpCodes.Xor));
                                    }

                                    ctx.AddJump(newStatement, switchHdr[1]);
                                    ctx.AddJunk(newStatement);

                                    converted = true;
                                }

                                if (trace.BeforeStack[newStatement[0].Offset] == 0)
                                {
                                    operands[keyId[i]] = newStatement[0];
                                }
                            }
                        }

                        if (!converted) {
                            // Normal

                            if (newStatement[newStatement.Count - 1].OpCode != OpCodes.Ret)
                            {
                                var nextStatement = current.Next;
                                if (trace.BeforeStack[nextStatement.Value[0].Offset] == 0)
                                {
                                    var targetKey = predicate != null ? predicate.GetSwitchKey(key[i + 1]) : key[i + 1];
                                    if (!hasUnknownSource(newStatement) && trace.BeforeStack[newStatement[0].Offset] == 0)
                                    {
                                        var thisKey = key[i];
                                        var r = ctx.Random.NextInt32();
                                        newStatement.Add(Instruction.Create(OpCodes.Ldloc, local));
                                        newStatement.Add(Instruction.CreateLdcI4(r));
                                        newStatement.Add(Instruction.Create(OpCodes.Mul));
                                        newStatement.Add(Instruction.Create(OpCodes.Ldc_I4, (thisKey*r) ^ targetKey));
                                        newStatement.Add(Instruction.Create(OpCodes.Xor));
                                    }
                                    else
                                    {
                                        newStatement.Add(Instruction.Create(OpCodes.Ldc_I4, targetKey));
                                    }

                                    ctx.AddJump(newStatement, switchHdr[1]);
                                    ctx.AddJunk(newStatement);
                                }
                                else
                                {
                                    newStatement.Add(Instruction.Create(OpCodes.Br, nextStatement.Value[0]));
                                }
                            }

                            if (trace.BeforeStack[newStatement[0].Offset] == 0)
                            {
                                operands[keyId[i]] = newStatement[0];
                            }
                        }
                    }
                    else
                        operands[keyId[i]] = switchHdr[0];

                    current.Value = newStatement.ToArray();
                    current = current.Next;
                    i++;
                }

                if (trace.BeforeStack[current.Value[0].Offset] == 0)
                {
                    operands[keyId[i]] = current.Value[0];
                }

                for (i = 0; i < operands.Length; i++)
                {
                    if (operands[i] == null)
                    {
                        operands[i] = switchHdr[0];
                    }
                }

                switchInstr.Operand = operands;

                Instruction[] first = statements.First.Value;
                statements.RemoveFirst();
                Instruction[] last = statements.Last.Value;
                statements.RemoveLast();

                List<Instruction[]> newStatements = statements.Where(s => trace.BeforeStack[s[0].Offset] == 0).ToList();
                ctx.Random.Shuffle(newStatements);

                List<Instruction[]> newOrderedStatements = statements.Where(s => trace.BeforeStack[s[0].Offset] != 0).ToList();

                block.Instructions.Clear();
                block.Instructions.AddRange(first);
                block.Instructions.AddRange(switchHdr);
                foreach (var statement in newStatements)
                    block.Instructions.AddRange(statement);
                foreach (var statement in newOrderedStatements)
                    block.Instructions.AddRange(statement);
                block.Instructions.AddRange(last);
            }
        }
Beispiel #16
0
        public void Stop()
        {
            Status = QueryTraceStatus.Stopping;

            if (_trace != null)
            {
                _trace.OnEvent -= OnTraceEventInternal;
                try
                {
                    //    _trace.Stop();
                    _trace.Drop();
                    _trace = null;
                    Status = QueryTraceStatus.Stopped;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e);
                }
            }

            _traceStarted = false;
        }
        public void StartTest()
        {
            try
            {
                Dictionary<Aggregation, long> dictAggRowCount = new Dictionary<Aggregation, long>();
                Dictionary<AggregationDesign, long> dictAggDesignRowCount = new Dictionary<AggregationDesign, long>();

                AdomdConnection conn = new AdomdConnection("Data Source=" + _currentAggD.ParentServer.Name + ";Initial Catalog=" + _currentAggD.ParentDatabase.Name);
                conn.Open();
                _sessionID = conn.SessionID;

                if (_cancelled) return;

                foreach (Partition p in _currentAggD.Parent.Partitions)
                {
                    if (p.AggregationDesignID != _currentAggD.ID) continue;

                    RaiseProgressEvent(0, "Retrieving list of processed aggs in partition " + p.Name + "...");

                    AdomdRestrictionCollection coll = new AdomdRestrictionCollection();
                    coll.Add("DATABASE_NAME", _currentAggD.ParentDatabase.Name);
                    coll.Add("CUBE_NAME", _currentAggD.ParentCube.Name);
                    coll.Add("MEASURE_GROUP_NAME", p.Parent.Name);
                    coll.Add("PARTITION_NAME", p.Name);
                    DataSet aggDS = conn.GetSchemaDataSet("DISCOVER_PARTITION_STAT", coll);
                    foreach (DataRow row in aggDS.Tables[0].Rows)
                    {
                        if (!string.IsNullOrEmpty(Convert.ToString(row["AGGREGATION_NAME"])))
                        {
                            Aggregation a = p.AggregationDesign.Aggregations.FindByName(Convert.ToString(row["AGGREGATION_NAME"]));
                            if (a == null) throw new Exception("Couldn't find aggregation [" + row["AGGREGATION_NAME"] + "]");
                            long lngAggRowCount = Convert.ToInt64(row["AGGREGATION_SIZE"]);
                            if (lngAggRowCount > 0)
                            {
                                if (!dictAggRowCount.ContainsKey(a))
                                    dictAggRowCount.Add(a, lngAggRowCount);
                                else
                                    dictAggRowCount[a] += lngAggRowCount;
                            }
                        }
                        else
                        {
                            long lngPartitionRowCount = Convert.ToInt64(row["AGGREGATION_SIZE"]);
                            if (!dictAggDesignRowCount.ContainsKey(p.AggregationDesign ?? _emptyAggregationDesign))
                                dictAggDesignRowCount.Add(p.AggregationDesign ?? _emptyAggregationDesign, lngPartitionRowCount);
                            else
                                dictAggDesignRowCount[p.AggregationDesign ?? _emptyAggregationDesign] += lngPartitionRowCount;
                        }
                        if (_cancelled) return;
                    }
                }

                if (dictAggRowCount.Count == 0) return;

                //figure out any DefaultMember that aren't the all member
                string sDefaultMembersCalcs = "";
                string sDefaultMembersCols = "";
                foreach (MeasureGroupDimension mgd in _currentAggD.Parent.Dimensions)
                {
                    RegularMeasureGroupDimension rmgd = mgd as RegularMeasureGroupDimension;
                    if (rmgd == null) continue;
                    foreach (MeasureGroupAttribute mga in rmgd.Attributes)
                    {
                        if (mga.CubeAttribute.AttributeHierarchyEnabled && mga.Attribute.AttributeHierarchyEnabled)
                        {
                            sDefaultMembersCalcs += "MEMBER [Measures].[|" + mga.CubeAttribute.Parent.Name + " | " + mga.CubeAttribute.Attribute.Name + "|] as iif([" + mga.CubeAttribute.Parent.Name + "].[" + mga.CubeAttribute.Attribute.Name + "].DefaultMember.Level.Name = \"(All)\", null, [" + mga.CubeAttribute.Parent.Name + "].[" + mga.CubeAttribute.Attribute.Name + "].DefaultMember.UniqueName)\r\n";
                            if (sDefaultMembersCols.Length > 0) sDefaultMembersCols += ",";
                            sDefaultMembersCols += "[Measures].[|" + mga.CubeAttribute.Parent.Name + " | " + mga.CubeAttribute.Attribute.Name + "|]\r\n";
                        }
                    }
                }

                RaiseProgressEvent(1, "Detecting DefaultMember on each dimension attribute...");

                AdomdCommand cmd = new AdomdCommand();
                cmd.Connection = conn;
                cmd.CommandText = "with\r\n"
                    + sDefaultMembersCalcs
                    + "select {\r\n"
                    + sDefaultMembersCols
                    + "} on 0\r\n"
                    + "from [" + _currentAggD.ParentCube.Name.Replace("]", "]]") + "]";
                CellSet cs = cmd.ExecuteCellSet();

                int iCol = 0;
                _dictDefaultMembers.Clear();
                foreach (MeasureGroupDimension mgd in _currentAggD.Parent.Dimensions)
                {
                    RegularMeasureGroupDimension rmgd = mgd as RegularMeasureGroupDimension;
                    if (rmgd == null) continue;
                    foreach (MeasureGroupAttribute mga in rmgd.Attributes)
                    {
                        if (mga.CubeAttribute.AttributeHierarchyEnabled && mga.Attribute.AttributeHierarchyEnabled)
                        {
                            string sValue = Convert.ToString(cs.Cells[iCol++].Value);
                            if (!string.IsNullOrEmpty(sValue))
                            {
                                _dictDefaultMembers.Add(mga, sValue);
                            }
                        }
                    }
                }

                conn.Close(false);

                if (_cancelled) return;

                RaiseProgressEvent(2, "Starting trace...");

                Server s = new Server();
                s.Connect("Data Source=" + _currentAggD.ParentServer.Name, _sessionID);

                Server sAlt = new Server();
                sAlt.Connect("Data Source=" + _currentAggD.ParentServer.Name);
                MeasureGroup mgAlt = sAlt.Databases.GetByName(_currentAggD.ParentDatabase.Name).Cubes.GetByName(_currentAggD.ParentCube.Name).MeasureGroups.GetByName(_currentAggD.Parent.Name);

                try
                {
                    Database db = s.Databases.GetByName(_currentAggD.ParentDatabase.Name);

                    string sTraceID = "BIDS Helper Aggs Performance Trace " + System.Guid.NewGuid().ToString();
                    _trc = s.Traces.Add(sTraceID, sTraceID);
                    _trc.OnEvent += new TraceEventHandler(trace_OnEvent);
                    _trc.Stopped += new TraceStoppedEventHandler(trace_Stopped);
                    _trc.AutoRestart = false;

                    TraceEvent te;
                    te = _trc.Events.Add(TraceEventClass.QueryEnd);
                    te.Columns.Add(TraceColumn.Duration);
                    te.Columns.Add(TraceColumn.SessionID);

                    te = _trc.Events.Add(TraceEventClass.GetDataFromAggregation);
                    te.Columns.Add(TraceColumn.ObjectPath);
                    te.Columns.Add(TraceColumn.TextData);
                    te.Columns.Add(TraceColumn.SessionID);
                    te.Columns.Add(TraceColumn.ConnectionID);

                    _trc.Update();
                    _trc.Start();

                    if (_cancelled) return;

                    s.BeginTransaction();
                    UnprocessOtherPartitions(s);

                    int i = 0;
                    if (_testAgg)
                    {
                        foreach (Aggregation a in dictAggRowCount.Keys)
                        {
                            RaiseProgressEvent(3 + (int)(87.0 * i++ / dictAggRowCount.Count / _totalIterations), "Testing performance with agg " + i + " of " + dictAggRowCount.Count + " (" + a.Name + ")...");

                            AggregationPerformance aggP = new AggregationPerformance(a);
                            aggP.AggregationRowCount = dictAggRowCount[a];
                            aggP.PartitionRowCount = dictAggDesignRowCount[a.Parent];
                            aggP.MeasureGroupRowCount = aggP.PartitionRowCount; //if there are multiple aggregation designs, outside code will fix that

                            ServerExecute(s, "<ClearCache xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" + "\r\n"
                            + "    <Object>" + "\r\n"
                            + "      <DatabaseID>" + _currentAggD.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                            + "      <CubeID>" + _currentAggD.ParentCube.ID + "</CubeID>" + "\r\n"
                            + "    </Object>" + "\r\n"
                            + "  </ClearCache>");

                            _queryEnded = false;

                            //initialize the MDX script with a no-op query
                            ServerExecuteMDX(db, "with member [Measures].[_Exec MDX Script_] as null select [Measures].[_Exec MDX Script_] on 0 from [" + _currentAggD.ParentCube.Name.Replace("]", "]]") + "]", _sessionID);

                            while (!this._queryEnded) //wait for session trace query end event
                            {
                                if (_cancelled) return;
                                System.Threading.Thread.Sleep(100);
                            }

                            aggP.ScriptPerformanceWithAgg = _queryDuration;

                            _queryEnded = false;
                            //don't clear dictHitAggs because if an agg got hit during the ExecuteMDXScript event, then it will be cached for the query

                            ServerExecuteMDX(db, aggP.PerformanceTestMDX, _sessionID);

                            while (!this._queryEnded) //wait for session trace query end event
                            {
                                if (_cancelled) return;
                                System.Threading.Thread.Sleep(100);
                            }

                            aggP.QueryPerformanceWithAgg = _queryDuration;

                            if (_dictHitAggs.ContainsKey(a))
                                aggP.HitAggregation = true;

                            aggP.AggHits = _dictHitAggs;
                            _dictHitAggs = new Dictionary<Aggregation, int>();

                            _listAggPerf.Add(aggP);

                            if (_cancelled) return;
                        }
                    }

                    if (_testWithoutSomeAggs && _listAggPerf.Count > 0)
                    {
                        RaiseProgressEvent(4 + (int)(87.0 * i / dictAggRowCount.Count / _totalIterations), "Dropping some aggs inside a transaction...");

                        //build list of all aggs which were hit, and which are contained within another agg
                        List<AggregationPerformance> allAggs = new List<AggregationPerformance>();
                        foreach (AggregationPerformance ap in _listAggPerf)
                        {
                            if (!ap.HitAggregation) continue;
                            foreach (AggregationPerformance ap2 in _listAggPerf)
                            {
                                if (ap.Aggregation != ap2.Aggregation && ap.Aggregation.Parent == ap2.Aggregation.Parent && SearchSimilarAggs.IsAggregationIncluded(ap.Aggregation, ap2.Aggregation, false))
                                {
                                    allAggs.Add(ap);
                                    break;
                                }
                            }
                        }
                        allAggs.Sort(delegate(AggregationPerformance a, AggregationPerformance b)
                            {
                                int iCompare = 0;
                                try
                                {
                                    if (a == b || a.Aggregation == b.Aggregation) return 0;
                                    iCompare = a.AggregationRowCount.CompareTo(b.AggregationRowCount);
                                    if (iCompare == 0)
                                    {
                                        //if the aggs are the same rowcount, then sort by whether one is contained in the other
                                        if (SearchSimilarAggs.IsAggregationIncluded(a.Aggregation, b.Aggregation, false))
                                            return -1;
                                        else if (SearchSimilarAggs.IsAggregationIncluded(b.Aggregation, a.Aggregation, false))
                                            return 1;
                                        else
                                            return 0;
                                    }
                                }
                                catch { }
                                return iCompare;
                            });

                        List<AggregationPerformance> deletedAggregationPerfs = new List<AggregationPerformance>();
                        List<AggregationPerformance> nextAggs = new List<AggregationPerformance>();
                        List<AggregationPerformance> aggsToSkipTesting = new List<AggregationPerformance>();

                        System.Diagnostics.Stopwatch timerProcessIndexes = new System.Diagnostics.Stopwatch();
                        long lngLastProcessIndexesTime = 0;
                        AggregationPerformance lastDeletedAggregationPerf = null;

                        while (allAggs.Count > 0)
                        {
                            AggregationPerformance aggP = null;
                            if (nextAggs.Count == 0)
                            {
                                aggP = allAggs[0];
                                allAggs.RemoveAt(0);
                            }
                            else
                            {
                                aggP = nextAggs[0];
                                nextAggs.RemoveAt(0);
                                allAggs.Remove(aggP);
                            }
                            deletedAggregationPerfs.Add(aggP);

                            //capture XMLA for deleting aggs
                            AggregationDesign aggD = mgAlt.AggregationDesigns.GetByName(aggP.Aggregation.Parent.Name);
                            aggD.ParentServer.CaptureXml = true;
                            foreach (AggregationPerformance ap in deletedAggregationPerfs)
                            {
                                if (aggD.Aggregations.ContainsName(ap.Aggregation.Name))
                                {
                                    aggD.Aggregations.RemoveAt(aggD.Aggregations.IndexOfName(ap.Aggregation.Name));
                                }
                            }
                            aggD.Update(UpdateOptions.ExpandFull);
                            string sAlterXMLA = aggD.ParentServer.CaptureLog[0];
                            aggD.ParentServer.CaptureLog.Clear();
                            aggD.ParentServer.CaptureXml = false;
                            aggD.Refresh(true); //get the deleted aggs back

                            ServerExecute(s, sAlterXMLA);

                            if (_cancelled) return;

                            RaiseProgressEvent(5 + (int)(87.0 * i++ / dictAggRowCount.Count / _totalIterations), "Processing aggs without some aggs " + ((i - 1) % dictAggRowCount.Count + 1) + " of " + dictAggRowCount.Count + " (" + aggP.AggregationName + ")...");

                            timerProcessIndexes.Reset();
                            timerProcessIndexes.Start();

                            //process aggs to delete existing aggs
                            ServerExecute(s, "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" + "\r\n"
                                + "  <Parallel>" + "\r\n"
                                + "    <Process xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\" xmlns:ddl100_100=\"http://schemas.microsoft.com/analysisservices/2008/engine/100/100\">" + "\r\n"
                                + "      <Object>" + "\r\n"
                                + "       <DatabaseID>" + _currentAggD.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                                + "       <CubeID>" + _currentAggD.ParentCube.ID + "</CubeID>" + "\r\n"
                                + "       <MeasureGroupID>" + _currentAggD.Parent.ID + "</MeasureGroupID>" + "\r\n"
                                + "      </Object>" + "\r\n"
                                + "      <Type>ProcessIndexes</Type>" + "\r\n"
                                + "      <WriteBackTableCreation>UseExisting</WriteBackTableCreation>" + "\r\n"
                                + "    </Process>" + "\r\n"
                                + "  </Parallel>" + "\r\n"
                                + "</Batch>" + "\r\n");
                            if (!string.IsNullOrEmpty(_errors)) throw new Exception(_errors);

                            timerProcessIndexes.Stop();

                            //record time it took to process aggs... compare how long the prior one took, then you can determine how much incremental time was spent on the newly deleted agg
                            if (lastDeletedAggregationPerf != null)
                                lastDeletedAggregationPerf.ProcessIndexesDuration = lngLastProcessIndexesTime - timerProcessIndexes.ElapsedMilliseconds;

                            lngLastProcessIndexesTime = timerProcessIndexes.ElapsedMilliseconds;
                            lastDeletedAggregationPerf = aggP;

                            if (_cancelled) return;

                            int j = 0;
                            foreach (AggregationPerformance deleteAP in deletedAggregationPerfs)
                            {
                                RaiseProgressEvent(6 + (int)(87.0 * i / dictAggRowCount.Count / _totalIterations), "Testing performance without some aggs " + ((i - 1) % dictAggRowCount.Count + 1) + " of " + dictAggRowCount.Count + "\r\nTesting agg " + (++j) + " of " + deletedAggregationPerfs.Count + " (" + deleteAP.AggregationName + ")...");

                                if (aggsToSkipTesting.Contains(deleteAP)) continue; //skip this agg if we've already determined it won't hit another agg

                                ServerExecute(s, "<ClearCache xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" + "\r\n"
                                + "    <Object>" + "\r\n"
                                + "      <DatabaseID>" + _currentAggD.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                                + "      <CubeID>" + _currentAggD.ParentCube.ID + "</CubeID>" + "\r\n"
                                + "    </Object>" + "\r\n"
                                + "  </ClearCache>");

                                _queryEnded = false;

                                //initialize the MDX script with a no-op query
                                ServerExecuteMDX(db, "with member [Measures].[_Exec MDX Script_] as null select [Measures].[_Exec MDX Script_] on 0 from [" + _currentAggD.ParentCube.Name.Replace("]", "]]") + "]", _sessionID);

                                while (!this._queryEnded) //wait for session trace query end event
                                {
                                    if (_cancelled) return;
                                    System.Threading.Thread.Sleep(100);
                                }

                                long lngScriptDuration = _queryDuration;

                                _queryEnded = false;
                                //don't clear dictHitAggs because if an agg got hit during the ExecuteMDXScript event, then it will be cached for the query

                                ServerExecuteMDX(db, deleteAP.PerformanceTestMDX, _sessionID);

                                while (!this._queryEnded) //wait for session trace query end event
                                {
                                    if (_cancelled) return;
                                    System.Threading.Thread.Sleep(100);
                                }

                                long lngQueryDuration = _queryDuration;

                                List<Aggregation> deletedAggregations = new List<Aggregation>();
                                foreach (AggregationPerformance a in deletedAggregationPerfs)
                                {
                                    deletedAggregations.Add(a.Aggregation);
                                }

                                MissingAggregationPerformance missingAggPerf = new MissingAggregationPerformance(deleteAP, deletedAggregations.ToArray(), _dictHitAggs);
                                _listMissingAggPerf.Add(missingAggPerf);
                                missingAggPerf.QueryPerformance = lngQueryDuration;
                                missingAggPerf.ScriptPerformance = lngScriptDuration;

                                foreach (Aggregation a in missingAggPerf.AggHitsDiff)
                                {
                                    foreach (AggregationPerformance ap in allAggs)
                                    {
                                        if (ap.Aggregation == a && !nextAggs.Contains(ap))
                                            nextAggs.Add(ap);
                                    }
                                }

                                if (missingAggPerf.AggHitsDiff.Length == 0)
                                {
                                    aggsToSkipTesting.Add(deleteAP);
                                }
                                else
                                {
                                    bool bThisAggContainedInRemainingAgg = false;
                                    foreach (AggregationPerformance ap2 in allAggs)
                                    {
                                        if (deleteAP.Aggregation != ap2.Aggregation && deleteAP.Aggregation.Parent == ap2.Aggregation.Parent && SearchSimilarAggs.IsAggregationIncluded(deleteAP.Aggregation, ap2.Aggregation, false))
                                        {
                                            bThisAggContainedInRemainingAgg = true;
                                            break;
                                        }
                                    }
                                    if (!bThisAggContainedInRemainingAgg)
                                        aggsToSkipTesting.Add(deleteAP); //stop testing this agg when it's not contained in any remaining aggs that need to be tested
                                }

                                _dictHitAggs = new Dictionary<Aggregation, int>();
                            }

                            if (_cancelled) return;

                            s.RollbackTransaction();
                            s.BeginTransaction();

                            UnprocessOtherPartitions(s);
                        }
                    }

                    if (_testNoAggs)
                    {
                        //ensure the counter is where it's supposed to be since the "test with some aggs" test may not have done iterations for every agg
                        i = Math.Max(i, dictAggRowCount.Count * (_totalIterations - 1));

                        RaiseProgressEvent(4 + (int)(87.0 * i / dictAggRowCount.Count / _totalIterations), "Dropping all aggs inside a transaction...");

                        //delete all aggs in all aggregation designs
                        string sXMLA = "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\" xmlns:as=\"http://schemas.microsoft.com/analysisservices/2003/engine\" xmlns:dwd=\"http://schemas.microsoft.com/DataWarehouse/Designer/1.0\">" + "\r\n"
                            + "  <Alter AllowCreate=\"true\" ObjectExpansion=\"ExpandFull\">" + "\r\n"
                            + "    <Object>" + "\r\n"
                            + "      <DatabaseID>" + _currentAggD.Parent.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                            + "      <CubeID>" + _currentAggD.Parent.Parent.ID + "</CubeID>" + "\r\n"
                            + "      <MeasureGroupID>" + _currentAggD.Parent.ID + "</MeasureGroupID>" + "\r\n"
                            + "      <AggregationDesignID>" + _currentAggD.ID + "</AggregationDesignID>" + "\r\n"
                            + "    </Object>" + "\r\n"
                            + "    <ObjectDefinition>" + "\r\n"
                            + "      <AggregationDesign>" + "\r\n"
                            + "        <ID>" + _currentAggD.ID + "</ID>" + "\r\n"
                            + "        <Name>" + _currentAggD.Name + "</Name>" + "\r\n"
                            + "        <Aggregations>" + "\r\n"
                            + "        </Aggregations>" + "\r\n"
                            + "      </AggregationDesign>" + "\r\n"
                            + "    </ObjectDefinition>" + "\r\n"
                            + "  </Alter>" + "\r\n"
                            + "</Batch>" + "\r\n";
                        ServerExecute(s, sXMLA);

                        RaiseProgressEvent(5 + (int)(87.0 * i / dictAggRowCount.Count / _totalIterations), "Processing empty aggregation design...");

                        if (_cancelled) return;

                        //process aggs to delete existing aggs
                        ServerExecute(s, "<Batch xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" + "\r\n"
                            + "  <Parallel>" + "\r\n"
                            + "    <Process xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ddl2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2\" xmlns:ddl2_2=\"http://schemas.microsoft.com/analysisservices/2003/engine/2/2\" xmlns:ddl100_100=\"http://schemas.microsoft.com/analysisservices/2008/engine/100/100\">" + "\r\n"
                            + "      <Object>" + "\r\n"
                            + "       <DatabaseID>" + _currentAggD.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                            + "       <CubeID>" + _currentAggD.ParentCube.ID + "</CubeID>" + "\r\n"
                            + "       <MeasureGroupID>" + _currentAggD.Parent.ID + "</MeasureGroupID>" + "\r\n"
                            + "      </Object>" + "\r\n"
                            + "      <Type>ProcessIndexes</Type>" + "\r\n"
                            + "      <WriteBackTableCreation>UseExisting</WriteBackTableCreation>" + "\r\n"
                            + "    </Process>" + "\r\n"
                            + "  </Parallel>" + "\r\n"
                            + "</Batch>" + "\r\n");
                        if (!string.IsNullOrEmpty(_errors)) throw new Exception(_errors);

                        if (_cancelled) return;

                        foreach (AggregationPerformance aggP in _listAggPerf)
                        {
                            RaiseProgressEvent(10 + (int)(87.0 * i++ / dictAggRowCount.Count / _totalIterations), "Testing performance with no aggs " + ((i - 1) % dictAggRowCount.Count + 1) + " of " + dictAggRowCount.Count + " (" + aggP.AggregationName + ")...");

                            ServerExecute(s, "<ClearCache xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">" + "\r\n"
                            + "    <Object>" + "\r\n"
                            + "      <DatabaseID>" + _currentAggD.ParentDatabase.ID + "</DatabaseID>" + "\r\n"
                            + "      <CubeID>" + _currentAggD.ParentCube.ID + "</CubeID>" + "\r\n"
                            + "    </Object>" + "\r\n"
                            + "  </ClearCache>");

                            if (_cancelled) return;

                            _queryEnded = false;

                            //initialize the MDX script with a no-op query
                            ServerExecuteMDX(db, "with member [Measures].[_Exec MDX Script_] as null select [Measures].[_Exec MDX Script_] on 0 from [" + _currentAggD.ParentCube.Name.Replace("]", "]]") + "]", _sessionID);

                            while (!this._queryEnded) //wait for session trace query end event
                            {
                                if (_cancelled) return;
                                System.Threading.Thread.Sleep(100);
                            }

                            aggP.ScriptPerformanceWithoutAggs = _queryDuration;

                            _queryEnded = false;

                            ServerExecuteMDX(db, aggP.PerformanceTestMDX, _sessionID);

                            while (!this._queryEnded) //wait for session trace query end event
                            {
                                if (_cancelled) return;
                                System.Threading.Thread.Sleep(100);
                            }

                            aggP.QueryPerformanceWithoutAggs = _queryDuration;
                        }
                    } //end of testing with no aggs

                    RaiseProgressEvent(100, "Finished measure group " + _currentAggD.Parent.Name);

                    if (!string.IsNullOrEmpty(_errors)) throw new Exception(_errors);
                }
                finally
                {
                    try
                    {
                        if (!s.Connected)
                        {
                            s.Connect("Data Source=" + _currentAggD.ParentServer.Name, _sessionID);
                        }
                    }
                    catch
                    {
                        try
                        {
                            if (!s.Connected)
                            {
                                s.Connect("Data Source=" + _currentAggD.ParentServer.Name); //can't connect to that session, so just reconnect
                            }
                        }
                        catch { }
                    }

                    try
                    {
                        s.RollbackTransaction();
                    }
                    catch { }

                    try
                    {
                        _trc.Drop();
                    }
                    catch { }

                    try
                    {
                        s.Disconnect();
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                if (!_cancelled)
                {
                    _errors += ex.Message + "\r\n" + ex.StackTrace + "\r\n";
                    System.Windows.Forms.MessageBox.Show(_errors);
                }
            }
        }
Beispiel #18
0
        private void Execute()
        {
            dictHitAggs = new Dictionary<Aggregation, int>();
            bExecuting = true;
            this.radioTraceTypeLive.Enabled = false;
            this.radioTraceTypeSQL.Enabled = false;
            this.btnSQLConnection.Enabled = false;
            this.dtTraceStarted = DateTime.Now;
            this.Width = this.iWindowFullWidth;
            this.Height = this.iWindowShortHeight;
            this.buttonCancel.Visible = false;
            this.buttonOK.Visible = false;
            this.grpProgress.Visible = true;
            this.treeViewAggregation.Visible = false;
            this.lblUnusedAggregationsToDelete.Visible = false;
            this.iAggHits = 0;
            this.iQueries = 0;
            this.dtTraceStarted = DateTime.Now;

            timer1_Tick(null, null);
            this.btnExecute.Enabled = false;
            Application.DoEvents();

            try
            {
                if (this.radioTraceTypeLive.Checked)
                {
                    timer1.Enabled = true;

                    string sTraceID = "BIDS Helper Delete Unused Aggs Trace " + System.Guid.NewGuid().ToString();
                    trc = liveServer.Traces.Add(sTraceID, sTraceID);
                    trc.OnEvent += new TraceEventHandler(trc_OnEvent);
                    trc.Stopped += new TraceStoppedEventHandler(trc_Stopped);
                    trc.AutoRestart = true;

                    TraceEvent te;
                    te = trc.Events.Add(TraceEventClass.QueryEnd);
                    te.Columns.Add(TraceColumn.DatabaseName);
                    te.Columns.Add(TraceColumn.EventSubclass);

                    te = trc.Events.Add(TraceEventClass.GetDataFromAggregation);
                    te.Columns.Add(TraceColumn.DatabaseName);
                    te.Columns.Add(TraceColumn.TextData);
                    te.Columns.Add(TraceColumn.ObjectPath);

                    trc.Update();
                    trc.Start();

                    this.btnExecute.Text = "Stop Trace";
                    this.btnExecute.Enabled = true;
                }
                else
                {
                    SqlConnection conn = new SqlConnection(ConnectionString);
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = "select * from " + Table; //just select everything and filter in .NET (which allows us to throw better error messages if a column is missing
                    SqlDataReader reader = null;
                    try
                    {
                        reader = cmd.ExecuteReader();
                        if (!ReaderContainsColumn(reader, "EventClass"))
                            MessageBox.Show("Table " + Table + " must contain EventClass column");
                        else if (!ReaderContainsColumn(reader, "EventSubclass"))
                            MessageBox.Show("Table " + Table + " must contain EventSubclass column");
                        else if (!ReaderContainsColumn(reader, "TextData"))
                            MessageBox.Show("Table " + Table + " must contain TextData column");
                        else if (!ReaderContainsColumn(reader, "ObjectPath"))
                            MessageBox.Show("Table " + Table + " must contain ObjectPath column");
                        else
                        {
                            this.dtTraceStarted = DateTime.Now;
                            string sDateColumnName = "";
                            if (ReaderContainsColumn(reader, "StartTime"))
                                sDateColumnName = "StartTime";
                            else if (ReaderContainsColumn(reader, "CurrentTime"))
                                sDateColumnName = "CurrentTime";
                            DateTime dtMin = DateTime.MaxValue;
                            DateTime dtMax = DateTime.MinValue;
                            while (reader.Read())
                            {
                                MyTraceEventArgs arg = new MyTraceEventArgs(reader);
                                HandleTraceEvent(arg);
                                if (!string.IsNullOrEmpty(sDateColumnName) && !Convert.IsDBNull(reader[sDateColumnName]))
                                {
                                    DateTime dt = Convert.ToDateTime(reader[sDateColumnName]);
                                    if (dtMin > dt) dtMin = dt;
                                    if (dtMax < dt) dtMax = dt;
                                    long iSecondsDiff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, dtMin, dtMax, Microsoft.VisualBasic.FirstDayOfWeek.System, Microsoft.VisualBasic.FirstWeekOfYear.Jan1);
                                    this.dtTraceStarted = Microsoft.VisualBasic.DateAndTime.DateAdd(Microsoft.VisualBasic.DateInterval.Second, -iSecondsDiff, DateTime.Now);
                                }
                                timer1_Tick(null, null);
                                Application.DoEvents();
                            }
                            FinishExecute(true);
                            return;
                        }
                        FinishExecute(false);
                    }
                    finally
                    {
                        try
                        {
                            reader.Close();
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                FinishExecute(false);
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #19
0
        private void FinishExecute(bool bShowResults)
        {
            try
            {
                if (trc != null)
                {
                    try
                    {
                        trc.Drop();
                    }
                    catch { }
                    trc = null;
                }
                bExecuting = false;
                this.radioTraceTypeLive.Enabled = true;
                this.radioTraceTypeSQL.Enabled = true;
                this.btnSQLConnection.Enabled = true;
                this.btnExecute.Text = "Execute";
                this.btnExecute.Enabled = true;
                timer1.Enabled = false;
                if (bShowResults)
                {
                    this.treeViewAggregation.Visible = true;
                    this.lblUnusedAggregationsToDelete.Visible = true;
                    this.Height = this.iWindowFullHeight;
                    this.buttonCancel.Visible = true;
                    this.buttonOK.Visible = true;

                    treeViewAggregation.Nodes.Clear();
                    this.treeViewAggregation.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewAggregation_AfterCheck);
                    if (cloneMG == null)
                    {
                        foreach (MeasureGroup mg in cloneCube.MeasureGroups)
                        {
                            FillTree(mg);
                        }
                    }
                    else
                    {
                        FillTree(cloneMG);
                    }
                    treeViewAggregation.ExpandAll();
                    if (treeViewAggregation.Nodes.Count > 0) treeViewAggregation.Nodes[0].EnsureVisible();
                    this.treeViewAggregation.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewAggregation_AfterCheck);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public void PopulateTraceAttributesFromPackageContents(Trace trace, string pathToUnzippedPackage)
 {
 }
 public override void OnTrace(Trace t)
 {
     Write(t);
 }
 public override void OnTrace(Trace t) {
     if(Properties.Timeout == -1 || (t.End-t.Start).TotalMilliseconds > Properties.Timeout)
         base.OnTrace(t);
 }
Beispiel #23
0
        //private IResultsTarget _resultsTarget;
        public void Start()
        {
            if (_trace != null)
                if (_trace.IsStarted)
                    throw new InvalidOperationException("Cannot start a new trace as one is already running");

            if (Status != QueryTraceStatus.Started)
                Status = QueryTraceStatus.Starting;

            _trace = GetTrace();
            SetupTrace(_trace);
            _trace.Start();

            // create timer to "ping" the server with DISCOVER_SESSION requests
            // until the trace events start to fire.
            if (_startingTimer == null)
                _startingTimer = new Timer();
            _startingTimer.Interval = 300;  //TODO - make time interval shorter
            _startingTimer.Elapsed += OnTimerElapsed;
            _startingTimer.Enabled = true;
            _startingTimer.Start();
            utcPingStart = DateTime.UtcNow;
            // Wait for Trace to become active
        }
Beispiel #24
0
        LinkedList<Instruction[]> SpiltStatements(InstrBlock block, Trace trace, CFContext ctx)
        {
            var statements = new LinkedList<Instruction[]>();
            var currentStatement = new List<Instruction>();

            // Instructions that must be included in the ccurrent statement to ensure all outgoing
            // branches have stack = 0
            var requiredInstr = new HashSet<Instruction>();

            for (int i = 0; i < block.Instructions.Count; i++) {
                Instruction instr = block.Instructions[i];
                currentStatement.Add(instr);

                bool shouldSpilt = i + 1 < block.Instructions.Count && trace.HasMultipleSources(block.Instructions[i + 1].Offset);
                switch (instr.OpCode.FlowControl) {
                    case FlowControl.Branch:
                    case FlowControl.Cond_Branch:
                    case FlowControl.Return:
                    case FlowControl.Throw:
                        if (trace.AfterStack[instr.Offset] != 0) {
                            if (instr.Operand is Instruction)
                                requiredInstr.Add((Instruction)instr.Operand);
                            else if (instr.Operand is Instruction[]) {
                                foreach (var target in (Instruction[])instr.Operand)
                                    requiredInstr.Add(target);
                                shouldSpilt = false;
                            }
                        }
                        shouldSpilt = true;
                        break;
                }
                requiredInstr.Remove(instr);
                if ((instr.OpCode.OpCodeType != OpCodeType.Prefix && trace.AfterStack[instr.Offset] == 0 &&
                     requiredInstr.Count == 0) &&
                    (shouldSpilt || ctx.Intensity > ctx.Random.NextDouble())) {
                    statements.AddLast(currentStatement.ToArray());
                    currentStatement.Clear();
                }
            }

            if (currentStatement.Count > 0)
                statements.AddLast(currentStatement.ToArray());

            return statements;
        }
Beispiel #25
0
 private Trace GetTrace()
 {
     if (_trace == null)
       {
           _trace = _server.Traces.Add( string.Format("DaxStudio_Trace_SPID_{0}", _connection.SPID));
           //TODO - filter on session id
           // _trace.Filter = GetSpidFilter();
           _trace.Filter = GetSessionIdFilter();
           _trace.OnEvent += OnTraceEventInternal;
       }
       return _trace;
 }
        public void prepareScope()
        {
            //prepare the scope with the traces
            Trace inputTrace = new Trace();
            Trace outputTrace = new Trace();

            inputTrace.TraceColor = System.Drawing.ColorTranslator.FromHtml("#4aa3df");
            inputTrace.UnitName = "Input Volts";
            outputTrace.TraceColor = System.Drawing.ColorTranslator.FromHtml("#e74c3c");
            outputTrace.UnitName = "Output Volts";
            scope.Traces.Add(inputTrace);
            scope.Traces.Add(outputTrace);
        }
Beispiel #27
0
        protected TraversalInfo GetTraversalInfoForTrace(Trace trace)
        {
            TraversalInfo ti = new ExecutionState((StateImpl)StartStateStateImpl.Clone(), null, null);
            TraversalInfo newTi = null;

            if (trace != null)
            {
                if (trace.Count > 0)
                {
                    for (int i = 0; i < trace.Count; ++i)
                    {
                        newTi = ti.GetSuccessorN((int)trace[i].Selection);
                        System.Diagnostics.Debug.Assert(newTi != null);
                        ti = newTi;
                    }
                }
            }

            return ti;
        }
Beispiel #28
0
 public abstract void OnTrace(Trace t);
        LinkedList<Instruction[]> SpiltStatements(InstrBlock block, Trace trace, CFContext ctx)
        {
            var statements = new LinkedList<Instruction[]>();
            var currentStatement = new List<Instruction>();

            for (int i = 0; i < block.Instructions.Count; i++) {
                Instruction instr = block.Instructions[i];
                currentStatement.Add(instr);

                bool shouldSpilt = i + 1 < block.Instructions.Count && trace.HasMultipleSources(block.Instructions[i + 1].Offset);
                switch (instr.OpCode.FlowControl) {
                    case FlowControl.Branch:
                    case FlowControl.Cond_Branch:
                    case FlowControl.Return:
                    case FlowControl.Throw:
                        shouldSpilt = true;
                        break;
                }
                if ((instr.OpCode.OpCodeType != OpCodeType.Prefix && (trace.AfterStack[instr.Offset] == 0 || instr.IsBr())) &&
                    (shouldSpilt || ctx.Intensity > ctx.Random.NextDouble())) {
                    statements.AddLast(currentStatement.ToArray());
                    currentStatement.Clear();
                }
            }

            if (currentStatement.Count > 0)
                statements.AddLast(currentStatement.ToArray());

            return statements;
        }
        private void Execute()
        {
            dictHitIndexes = new Dictionary<CubeAttribute, int>();
            listDrillthroughQueries = new List<string>();
            bExecuting = true;
            this.radioTraceTypeLive.Enabled = false;
            this.radioTraceTypeSQL.Enabled = false;
            this.btnSQLConnection.Enabled = false;
            this.dtTraceStarted = DateTime.Now;
            this.Width = this.iWindowFullWidth;
            this.Height = this.iWindowShortHeight;
            this.buttonCancel.Visible = false;
            this.buttonOK.Visible = false;
            this.grpProgress.Visible = true;
            this.treeViewAggregation.Visible = false;
            this.lblUnusedAggregationsToDelete.Visible = false;
            this.iQueries = 0;
            this.dtTraceStarted = DateTime.Now;

            timer1_Tick(null, null);
            this.btnExecute.Enabled = false;
            Application.DoEvents();

            try
            {
                if (this.radioTraceTypeLive.Checked)
                {
                    timer1.Enabled = true;

                    string sTraceID = "BIDS Helper Delete Unused Indexes Trace " + System.Guid.NewGuid().ToString();
                    trc = liveServer.Traces.Add(sTraceID, sTraceID);
                    trc.OnEvent += new TraceEventHandler(trc_OnEvent);
                    trc.Stopped += new TraceStoppedEventHandler(trc_Stopped);
                    trc.AutoRestart = true;

                    TraceEvent te;
                    te = trc.Events.Add(TraceEventClass.QueryBegin);
                    te.Columns.Add(TraceColumn.DatabaseName);
                    te.Columns.Add(TraceColumn.TextData);
                    te.Columns.Add(TraceColumn.SessionID);

                    te = trc.Events.Add(TraceEventClass.QueryEnd);
                    te.Columns.Add(TraceColumn.DatabaseName);
                    te.Columns.Add(TraceColumn.SessionID);

                    te = trc.Events.Add(TraceEventClass.QuerySubcubeVerbose);
                    te.Columns.Add(TraceColumn.DatabaseName);
                    te.Columns.Add(TraceColumn.TextData);
                    te.Columns.Add(TraceColumn.ObjectPath);
                    te.Columns.Add(TraceColumn.SessionID);

                    trc.Update();
                    trc.Start();

                    this.btnExecute.Text = "Stop Trace";
                    this.btnExecute.Enabled = true;
                }
                else
                {
                    SqlConnection conn = new SqlConnection(ConnectionString);
                    conn.Open();

                    bool bHasRowNumberColumn = false;
                    try
                    {
                        //test that this table has the RowNumber column
                        SqlCommand cmdCheckRowNumber = new SqlCommand();
                        cmdCheckRowNumber.Connection = conn;
                        cmdCheckRowNumber.CommandText = "select top 1 RowNumber from " + Table + " (nolock)";
                        cmdCheckRowNumber.CommandTimeout = 0;
                        cmdCheckRowNumber.ExecuteNonQuery();
                        bHasRowNumberColumn = true;
                    }
                    catch { }

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = "select * from " + Table + " (nolock) order by CurrentTime" + (bHasRowNumberColumn ? ", RowNumber" : ""); //just select everything and filter in .NET (which allows us to throw better error messages if a column is missing... must be ordered so that we can recognize drillthrough queries and skip the query subcube verbose events until query end... ordering by CurrentTime then RowNumber allows this to work in ASTrace archive tables which have overlapping RowNumber ranges
                    cmd.CommandTimeout = 0;
                    SqlDataReader reader = null;
                    try
                    {
                        reader = cmd.ExecuteReader();
                        if (!ReaderContainsColumn(reader, "EventClass"))
                            MessageBox.Show("Table " + Table + " must contain EventClass column");
                        else if (!ReaderContainsColumn(reader, "TextData"))
                            MessageBox.Show("Table " + Table + " must contain TextData column");
                        else if (!ReaderContainsColumn(reader, "ObjectPath"))
                            MessageBox.Show("Table " + Table + " must contain ObjectPath column");
                        else if (!ReaderContainsColumn(reader, "SessionID") && !ReaderContainsColumn(reader, "SPID"))
                            MessageBox.Show("Table " + Table + " must contain SessionID or SPID column");
                        else
                        {
                            if (ReaderContainsColumn(reader, "SessionID"))
                                sSessionIDColumnName = "SessionID";
                            else
                                sSessionIDColumnName = "SPID";


                            this.dtTraceStarted = DateTime.Now;
                            string sDateColumnName = "CurrentTime";
                            DateTime dtMin = DateTime.MaxValue;
                            DateTime dtMax = DateTime.MinValue;
                            Int64 iRowCount = 0;
                            while (reader.Read())
                            {
                                MyTraceEventArgs arg = new MyTraceEventArgs(reader);
                                HandleTraceEvent(arg);
                                if (!string.IsNullOrEmpty(sDateColumnName) && !Convert.IsDBNull(reader[sDateColumnName]))
                                {
                                    DateTime dt = Convert.ToDateTime(reader[sDateColumnName]);
                                    if (dtMin > dt) dtMin = dt;
                                    if (dtMax < dt) dtMax = dt;
                                    long iSecondsDiff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, dtMin, dtMax, Microsoft.VisualBasic.FirstDayOfWeek.System, Microsoft.VisualBasic.FirstWeekOfYear.Jan1);
                                    this.dtTraceStarted = Microsoft.VisualBasic.DateAndTime.DateAdd(Microsoft.VisualBasic.DateInterval.Second, -iSecondsDiff, DateTime.Now);
                                }
                                if (iRowCount++ % 500 == 0)
                                {
                                    timer1_Tick(null, null);
                                    Application.DoEvents();
                                }
                            }
                            timer1_Tick(null, null);
                            Application.DoEvents();

                            FinishExecute(true);
                            return;
                        }
                        FinishExecute(false);
                    }
                    finally
                    {
                        try
                        {
                            reader.Close();
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                FinishExecute(false);
                MessageBox.Show(ex.Message);
            }
        }