Exemplo n.º 1
0
 private static bool SchemaMergesItemsWithDifferentOtherFields(PgoInstrumentationKind kind)
 {
     switch (kind)
     {
     //
     default:
         // All non-specified kinds are not distinguishable by Other field
         return(false);
     }
 }
Exemplo n.º 2
0
            public int Compare(PgoSchemaElem x, PgoSchemaElem y)
            {
                if (x.ILOffset != y.ILOffset)
                {
                    return(x.ILOffset.CompareTo(y.ILOffset));
                }
                PgoInstrumentationKind xdescr = x.InstrumentationKind & PgoInstrumentationKind.DescriptorMask;
                PgoInstrumentationKind ydescr = y.InstrumentationKind & PgoInstrumentationKind.DescriptorMask;

                if (xdescr != ydescr)
                {
                    return(xdescr.CompareTo(ydescr));
                }
                // We usually merge the Other field, except for edges, where we take care only to merge
                // edges with equal ILOffset _and_ equal Other fields.
                if ((x.InstrumentationKind == PgoInstrumentationKind.EdgeIntCount || x.InstrumentationKind == PgoInstrumentationKind.EdgeLongCount) &&
                    x.Other != y.Other)
                {
                    return(x.Other.CompareTo(y.Other));
                }

                return(0);
            }
Exemplo n.º 3
0
        public static void EncodePgoData <TType, TMethod>(IEnumerable <PgoSchemaElem> schemas, IPgoEncodedValueEmitter <TType, TMethod> valueEmitter, bool emitAllElementsUnconditionally)
        {
            PgoSchemaElem prevSchema         = default(PgoSchemaElem);
            TType         prevEmittedType    = default(TType);
            TMethod       prevEmittedMethod  = default(TMethod);
            long          prevEmittedIntData = 0;

            foreach (PgoSchemaElem schema in schemas)
            {
                int ilOffsetDiff = schema.ILOffset - prevSchema.ILOffset;
                int OtherDiff    = schema.Other - prevSchema.Other;
                int CountDiff    = schema.Count - prevSchema.Count;
                int TypeDiff     = (int)schema.InstrumentationKind - (int)prevSchema.InstrumentationKind;

                InstrumentationDataProcessingState modifyMask = (InstrumentationDataProcessingState)0;

                if (!emitAllElementsUnconditionally)
                {
                    if (ilOffsetDiff != 0)
                    {
                        modifyMask = modifyMask | InstrumentationDataProcessingState.ILOffset;
                    }
                    if (TypeDiff != 0)
                    {
                        modifyMask = modifyMask | InstrumentationDataProcessingState.Type;
                    }
                    if (CountDiff != 0)
                    {
                        modifyMask = modifyMask | InstrumentationDataProcessingState.Count;
                    }
                    if (OtherDiff != 0)
                    {
                        modifyMask = modifyMask | InstrumentationDataProcessingState.Other;
                    }
                }
                else
                {
                    modifyMask = InstrumentationDataProcessingState.ILOffset |
                                 InstrumentationDataProcessingState.Type |
                                 InstrumentationDataProcessingState.Count |
                                 InstrumentationDataProcessingState.Other;
                }

                Debug.Assert(modifyMask != InstrumentationDataProcessingState.Done);

                valueEmitter.EmitLong((long)modifyMask, 0);

                if ((modifyMask & InstrumentationDataProcessingState.ILOffset) == InstrumentationDataProcessingState.ILOffset)
                {
                    valueEmitter.EmitLong(schema.ILOffset, prevSchema.ILOffset);
                }
                if ((modifyMask & InstrumentationDataProcessingState.Type) == InstrumentationDataProcessingState.Type)
                {
                    valueEmitter.EmitLong((long)schema.InstrumentationKind, (long)prevSchema.InstrumentationKind);
                }
                if ((modifyMask & InstrumentationDataProcessingState.Count) == InstrumentationDataProcessingState.Count)
                {
                    valueEmitter.EmitLong(schema.Count, prevSchema.Count);
                }
                if ((modifyMask & InstrumentationDataProcessingState.Other) == InstrumentationDataProcessingState.Other)
                {
                    valueEmitter.EmitLong(schema.Other, prevSchema.Other);
                }

                for (int i = 0; i < schema.Count; i++)
                {
                    PgoInstrumentationKind marshal = schema.InstrumentationKind & PgoInstrumentationKind.MarshalMask;
                    switch (marshal)
                    {
                    case PgoInstrumentationKind.None:
                        break;

                    case PgoInstrumentationKind.FourByte:
                    {
                        long valueToEmit;
                        if (schema.Count == 1)
                        {
                            valueToEmit = schema.DataLong;
                        }
                        else
                        {
                            valueToEmit = ((int[])schema.DataObject)[i];
                        }
                        valueEmitter.EmitLong(valueToEmit, prevEmittedIntData);
                        prevEmittedIntData = valueToEmit;
                        break;
                    }

                    case PgoInstrumentationKind.EightByte:
                    {
                        long valueToEmit;
                        if (schema.Count == 1)
                        {
                            valueToEmit = schema.DataLong;
                        }
                        else
                        {
                            valueToEmit = ((long[])schema.DataObject)[i];
                        }
                        valueEmitter.EmitLong(valueToEmit, prevEmittedIntData);
                        prevEmittedIntData = valueToEmit;
                        break;
                    }

                    case PgoInstrumentationKind.TypeHandle:
                    {
                        TType typeToEmit = ((TType[])schema.DataObject)[i];
                        valueEmitter.EmitType(typeToEmit, prevEmittedType);
                        prevEmittedType = typeToEmit;
                        break;
                    }

                    case PgoInstrumentationKind.MethodHandle:
                    {
                        TMethod methodToEmit = ((TMethod[])schema.DataObject)[i];
                        valueEmitter.EmitMethod(methodToEmit, prevEmittedMethod);
                        prevEmittedMethod = methodToEmit;
                        break;
                    }

                    default:
                        throw new ArgumentException("Unknown schema marshal " + marshal);
                    }
                }

                prevSchema = schema;
            }

            // Emit a "done" schema
            if (!valueEmitter.EmitDone())
            {
                // If EmitDone returns true, no further data needs to be encoded.
                // Otherwise, emit a "Done" schema
                valueEmitter.EmitLong((long)InstrumentationDataProcessingState.Type, 0);
                valueEmitter.EmitLong((long)PgoInstrumentationKind.Done, (long)prevSchema.InstrumentationKind);
            }
        }