Example #1
0
        private void TruncateStringVariant(ref Variant v, int index, int averageStringVariantLength)
        {
            var str = v.ConvertToString();

            if (!string.IsNullOrEmpty(str) && str.Length > averageStringVariantLength)
            {
                var newVariant = str.Substring(0, averageStringVariantLength);
                RemoveStringEventData(index);
                AddStringEventData(newVariant, index);
                v = newVariant;
            }
        }
Example #2
0
        private void AddStringEventData(Variant variant, int index)
        {
            EventData dataDescriptor = default(EventData);

            dataDescriptor.Reserved = 0;
            if (variant.IsString())
            {
                var str = variant.ConvertToString();
                dataDescriptor.Size  = str == null ? 0 : (uint)(str.Length + 1) * 2;
                eventData[index]     = dataDescriptor;
                this.totalEventSize += eventData[index].Size;
                this.currentBuffer  += EventDataArrayBuilder.BasicTypeAllocationBufferSize;
            }
        }
Example #3
0
        private static void EncodeVariant(Variant data, EventData *dataDescriptor, byte *dataBuffer)
        {
            dataDescriptor->Reserved = 0;
            if (data.IsString())
            {
                var str = data.ConvertToString();
                dataDescriptor->Size = str == null ? 0 : (uint)(str.Length + 1) * 2;
                return;
            }

            // Copy the entire 16B field even if only 1B is being used.
            Guid *guidptr = (Guid *)dataBuffer;

            *guidptr = data.ConvertToGuid();
            dataDescriptor->DataPointer = (ulong)guidptr;
            dataDescriptor->Size        = data.Size;
        }
        private string GetTypeFromIndex(int index, Variant v0, Variant v1, Variant v2, Variant v3, Variant v4,
                                        Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13)
        {
            switch (index)
            {
            case 0:  return(v0.ConvertToString());

            case 1:  return(v1.ConvertToString());

            case 2:  return(v2.ConvertToString());

            case 3:  return(v3.ConvertToString());

            case 4:  return(v4.ConvertToString());

            case 5:  return(v5.ConvertToString());

            case 6:  return(v6.ConvertToString());

            case 7:  return(v7.ConvertToString());

            case 8:  return(v8.ConvertToString());

            case 9:  return(v9.ConvertToString());

            case 10: return(v10.ConvertToString());

            case 11: return(v11.ConvertToString());

            case 12: return(v12.ConvertToString());

            case 13: return(v13.ConvertToString());
            }

            return(null);
        }
        public void VariantWriteLinuxUnstructured(
            ref GenericEventDescriptor genericEventDescriptor,
            int argCount,
            Variant v0  = default(Variant),
            Variant v1  = default(Variant),
            Variant v2  = default(Variant),
            Variant v3  = default(Variant),
            Variant v4  = default(Variant),
            Variant v5  = default(Variant),
            Variant v6  = default(Variant),
            Variant v7  = default(Variant),
            Variant v8  = default(Variant),
            Variant v9  = default(Variant),
            Variant v10 = default(Variant),
            Variant v11 = default(Variant),
            Variant v12 = default(Variant),
            Variant v13 = default(Variant))
        {
            int    eventId = genericEventDescriptor.EventId;
            string text    = string.Format(
                this.eventDescriptors[eventId].Message, new object[]
                { v0.ToObject(), v1.ToObject(), v2.ToObject(), v3.ToObject(), v4.ToObject(), v5.ToObject(), v6.ToObject(), v7.ToObject(), v8.ToObject(), v9.ToObject(), v10.ToObject(), v11.ToObject(), v12.ToObject(), v13.ToObject() }
                );

            string id             = this.eventDescriptors[eventId].hasId && !string.IsNullOrWhiteSpace(v0.ConvertToString()) ? v0.ConvertToString() : eventId.ToString();
            int    typeFieldIndex = this.eventDescriptors[eventId].typeFieldIndex;
            string type           = this.eventDescriptors[eventId].EventName;

            if (this.eventDescriptors[eventId].typeFieldIndex != -1)
            {
                string typeField = GetTypeFromIndex(typeFieldIndex, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
                if (!string.IsNullOrWhiteSpace(typeField))
                {
                    type = typeField;
                }
            }

            TraceViaNative.WriteUnstructured(FabricEvents.Events.GetEventTaskName((EventTask)genericEventDescriptor.Task), type, id, genericEventDescriptor.Level, text);
        }
        public unsafe void VariantWrite(ref GenericEventDescriptor genericEventDescriptor, int argCount,
                                        Variant v1  = default(Variant), Variant v2  = default(Variant), Variant v3  = default(Variant),
                                        Variant v4  = default(Variant), Variant v5  = default(Variant), Variant v6  = default(Variant),
                                        Variant v7  = default(Variant), Variant v8  = default(Variant), Variant v9  = default(Variant),
                                        Variant v10 = default(Variant), Variant v11 = default(Variant), Variant v12 = default(Variant),
                                        Variant v13 = default(Variant), Variant v14 = default(Variant))
        {
            if (argCount == 0)
            {
#if !DotNetCoreClrLinux
                this.WriteEvent(genericEventDescriptor.EventId);
#else
                TraceViaNative.WriteStructured(ref genericEventDescriptor, 0, null);
#endif
                return;
            }

            Tracing.EventData *eventSourceData = stackalloc Tracing.EventData[argCount];
            byte *dataBuffer = stackalloc byte[EventDataArrayBuilder.BasicTypeAllocationBufferSize * argCount];
            var   edb        = new EventDataArrayBuilder(eventSourceData, dataBuffer);

            if (!edb.AddEventDataWithTruncation(argCount, ref v1, ref v2, ref v3, ref v4, ref v5, ref v6, ref v7, ref v8, ref v9, ref v10, ref v11, ref v12, ref v13, ref v14))
            {
                Debug.Fail(string.Format("EventData for eventid {0} is invalid. Check the total size of the event.",
                                         genericEventDescriptor.EventId));
                return;
            }

            fixed(char *s1 = v1.ConvertToString(),
                  s2       = v2.ConvertToString(),
                  s3       = v3.ConvertToString(),
                  s4       = v4.ConvertToString(),
                  s5       = v5.ConvertToString(),
                  s6       = v6.ConvertToString(),
                  s7       = v7.ConvertToString(),
                  s8       = v8.ConvertToString(),
                  s9       = v9.ConvertToString(),
                  s10      = v10.ConvertToString(),
                  s11      = v11.ConvertToString(),
                  s12      = v12.ConvertToString(),
                  s13      = v13.ConvertToString(),
                  s14      = v14.ConvertToString())
            {
                var tracingEventDataPtr = edb.ToEventDataArray(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14);

                // Convert to EventSource.EventData from Tracing.EventData.
#if !DotNetCoreClrLinux
                EventData *eventDataPtr = stackalloc EventData[argCount];
                for (uint i = 0; i < argCount; ++i)
                {
                    eventDataPtr[i].DataPointer = (IntPtr)tracingEventDataPtr[i].DataPointer;
                    eventDataPtr[i].Size        = (int)tracingEventDataPtr[i].Size;
                }

                this.WriteEventCore(genericEventDescriptor.EventId, argCount, eventDataPtr);
#else
                EventDataDescriptor *eventDataPtr = stackalloc EventDataDescriptor[argCount];
                for (uint i = 0; i < argCount; ++i)
                {
                    eventDataPtr[i].DataPointer = (UInt64)tracingEventDataPtr[i].DataPointer;
                    eventDataPtr[i].Size        = tracingEventDataPtr[i].Size;
                }

                TraceViaNative.WriteStructured(ref genericEventDescriptor, (uint)argCount, eventDataPtr);
#endif
            }
        }
        public unsafe void VariantWrite(
            ref GenericEventDescriptor genericEventDescriptor,
            int argCount,
            Variant v0  = default(Variant),
            Variant v1  = default(Variant),
            Variant v2  = default(Variant),
            Variant v3  = default(Variant),
            Variant v4  = default(Variant),
            Variant v5  = default(Variant),
            Variant v6  = default(Variant),
            Variant v7  = default(Variant),
            Variant v8  = default(Variant),
            Variant v9  = default(Variant),
            Variant v10 = default(Variant),
            Variant v11 = default(Variant),
            Variant v12 = default(Variant),
            Variant v13 = default(Variant))
        {
            EventDescriptor eventDesc = new EventDescriptor(genericEventDescriptor.EventId, genericEventDescriptor.Version, genericEventDescriptor.Channel, genericEventDescriptor.Level, genericEventDescriptor.Opcode, genericEventDescriptor.Task, genericEventDescriptor.Keywords);

            if (argCount == 0)
            {
                this.WriteEvent(ref eventDesc, argCount, null);
                return;
            }

            EventData *eventSourceData = stackalloc EventData[argCount]; // allocation for the data descriptors
            byte *     dataBuffer      = stackalloc byte[EventDataArrayBuilder.BasicTypeAllocationBufferSize * argCount];

            // 16 byte for non-string argument
            var edb = new EventDataArrayBuilder(eventSourceData, dataBuffer);

            if (!edb.AddEventDataWithTruncation(argCount, ref v0, ref v1, ref v2, ref v3, ref v4, ref v5, ref v6, ref v7, ref v8, ref v9, ref v10, ref v11, ref v12, ref v13))
            {
                Debug.Fail(string.Format("EventData for eventid {0} is invalid. Check the total size of the event.",
                                         eventDesc.EventId));
                return;
            }

            fixed(
                char *s0 = v0.ConvertToString(),
                s1       = v1.ConvertToString(),
                s2       = v2.ConvertToString(),
                s3       = v3.ConvertToString(),
                s4       = v4.ConvertToString(),
                s5       = v5.ConvertToString(),
                s6       = v6.ConvertToString(),
                s7       = v7.ConvertToString(),
                s8       = v8.ConvertToString(),
                s9       = v9.ConvertToString(),
                s10      = v10.ConvertToString(),
                s11      = v11.ConvertToString(),
                s12      = v12.ConvertToString(),
                s13      = v13.ConvertToString())
            {
                var eventDataPtr = edb.ToEventDataArray(
                    s0,
                    s1,
                    s2,
                    s3,
                    s4,
                    s5,
                    s6,
                    s7,
                    s8,
                    s9,
                    s10,
                    s11,
                    s12,
                    s13);

                this.WriteEvent(ref eventDesc, argCount, (IntPtr)eventDataPtr);
            }
        }
Example #8
0
        private int GetAverageStringVariantLength(ref Variant v0, ref Variant v1, ref Variant v2, ref Variant v3, ref Variant v4, ref Variant v5, ref Variant v6, ref Variant v7, ref Variant v8, ref Variant v9, ref Variant v10, ref Variant v11, ref Variant v12, ref Variant v13)
        {
            int count       = 0;
            int totalLength = 0;

            if (v0.IsString() && !string.IsNullOrEmpty(v0.ConvertToString()))
            {
                count++;
                totalLength += v0.ConvertToString().Length;
            }

            if (v1.IsString() && !string.IsNullOrEmpty(v1.ConvertToString()))
            {
                count++;
                totalLength += v1.ConvertToString().Length;
            }

            if (v2.IsString() && !string.IsNullOrEmpty(v2.ConvertToString()))
            {
                count++;
                totalLength += v2.ConvertToString().Length;
            }

            if (v3.IsString() && !string.IsNullOrEmpty(v3.ConvertToString()))
            {
                count++;
                totalLength += v3.ConvertToString().Length;
            }

            if (v4.IsString() && !string.IsNullOrEmpty(v4.ConvertToString()))
            {
                count++;
                totalLength += v4.ConvertToString().Length;
            }

            if (v5.IsString() && !string.IsNullOrEmpty(v5.ConvertToString()))
            {
                count++;
                totalLength += v5.ConvertToString().Length;
            }

            if (v6.IsString() && !string.IsNullOrEmpty(v6.ConvertToString()))
            {
                count++;
                totalLength += v6.ConvertToString().Length;
            }

            if (v7.IsString() && !string.IsNullOrEmpty(v7.ConvertToString()))
            {
                count++;
                totalLength += v7.ConvertToString().Length;
            }

            if (v8.IsString() && !string.IsNullOrEmpty(v8.ConvertToString()))
            {
                count++;
                totalLength += v8.ConvertToString().Length;
            }

            if (v9.IsString() && !string.IsNullOrEmpty(v9.ConvertToString()))
            {
                count++;
                totalLength += v9.ConvertToString().Length;
            }

            if (v10.IsString() && !string.IsNullOrEmpty(v10.ConvertToString()))
            {
                count++;
                totalLength += v10.ConvertToString().Length;
            }

            if (v11.IsString() && !string.IsNullOrEmpty(v11.ConvertToString()))
            {
                count++;
                totalLength += v11.ConvertToString().Length;
            }

            if (v12.IsString() && !string.IsNullOrEmpty(v12.ConvertToString()))
            {
                count++;
                totalLength += v12.ConvertToString().Length;
            }

            if (v13.IsString() && !string.IsNullOrEmpty(v13.ConvertToString()))
            {
                count++;
                totalLength += v13.ConvertToString().Length;
            }

            var overflow          = GetOverflow();
            var adjustedOverFlow  = (overflow % 2 == 1) ? (overflow + 1) : (overflow);
            var characterOverflow = (adjustedOverFlow / 2);

            return((totalLength - characterOverflow) / count);
        }