示例#1
0
            static unsafe void Deserialize(ref DeserializationContext context, out AllocationRanges output)
            {
                if (context.SourceLength < 4)
                {
                    throw new InvalidDataException();
                }

                int count = *(int *)(context.Source + 0);
                var array = ImmutableArrayPool <Range> .Allocate(count);

                uint offset   = 4;
                uint itemSize = BlittableSerializer <Range> .Size;

                if (context.SourceLength < (4 + (itemSize * count)))
                {
                    throw new InvalidDataException();
                }

                for (int i = 0; i < count; i++)
                {
                    context.DeserializeValue(
                        BlittableSerializer <Range> .Deserialize,
                        offset, itemSize, out array.Array[array.Offset + i]
                        );

                    offset += itemSize;
                }

                output = new AllocationRanges(array);
            }
示例#2
0
            static unsafe void Serialize(ref SerializationContext context, ref AllocationRanges input)
            {
                var buffer = new byte[4];
                var count  = input.Ranges.Count;

                fixed(byte *pBuffer = buffer)
                {
                    *(int *)(pBuffer) = count;
                    context.Stream.Write(buffer, 0, 4);
                }

                var array = input.Ranges.Array;

                for (int i = 0, o = input.Ranges.Offset; i < count; i++)
                {
                    context.SerializeValue(
                        BlittableSerializer <Range> .Serialize, ref array[i + o]
                        );
                }
            }
示例#3
0
        public IEnumerator <object> SaveToDatabase(DatabaseFile db)
        {
            SavedToDatabase = true;

            yield return(db.Snapshots.Set(Index, this.Info));

            {
                var batch = db.Modules.CreateBatch(Modules.Count);

                foreach (var module in Modules)
                {
                    batch.Add(module.Filename, module);
                }

                yield return(batch.Execute());
            }

            yield return(db.SnapshotModules.Set(Index, Modules.Keys.ToArray()));

            {
                var tracebackBatch = db.Tracebacks.CreateBatch(Tracebacks.Count);

                foreach (var traceback in Tracebacks)
                {
                    tracebackBatch.Add(traceback.ID, traceback);
                }

                yield return(tracebackBatch.Execute());
            }

            UInt16 uIndex = (UInt16)Index;

            HashSet <UInt32> addressSet;

            DecisionUpdateCallback <AllocationRanges> rangeUpdater =
                (ref AllocationRanges oldValue, ref AllocationRanges newValue) => {
                var r = newValue.Ranges.Array[newValue.Ranges.Offset];
                newValue = oldValue.Update(r.First, r.TracebackID, r.Size, r.Overhead);
                return(true);
            };

            foreach (var heap in Heaps)
            {
                var fAddressSet = db.HeapAllocations.Get(heap.ID);
                yield return(fAddressSet);

                if (fAddressSet.Failed)
                {
                    addressSet = new HashSet <UInt32>();
                }
                else
                {
                    addressSet = new HashSet <UInt32>(fAddressSet.Result);
                }

                var batch = db.Allocations.CreateBatch(heap.Allocations.Count);

                foreach (var allocation in heap.Allocations)
                {
                    batch.AddOrUpdate(
                        allocation.Address, AllocationRanges.New(
                            uIndex, allocation.TracebackID, allocation.Size, allocation.Overhead
                            ), rangeUpdater
                        );

                    addressSet.Add(allocation.Address);
                }

                yield return(batch.Execute());

                yield return(db.HeapAllocations.Set(heap.ID, addressSet.ToArray()));
            }

            yield return(db.SnapshotHeaps.Set(Index, (from heap in Heaps select heap.Info).ToArray()));
        }