/// <summary>
        /// Deserialize a pip graph fragment and call the given handleDeserializedPip function on each pip deserialized
        /// Returns true if successfully handled all pips.
        /// </summary>
        public bool Deserialize(string fragmentDescription, PipExecutionContext context, PipGraphFragmentContext pipFragmentContext, AbsolutePath filePath, Func <Pip, bool> handleDeserializedPip)
        {
            FragmentDescription = fragmentDescription;
            PipsDeserialized    = 0;
            string fileName = filePath.ToString(context.PathTable);

            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (RemapReader reader = new RemapReader(pipFragmentContext, stream, context))
                {
                    TotalPips = reader.ReadInt32();
                    for (int i = 0; i < TotalPips; i++)
                    {
                        var pip     = Pip.Deserialize(reader);
                        var success = handleDeserializedPip?.Invoke(pip);
                        if (success.HasValue & !success.Value)
                        {
                            return(false);
                        }

                        PipsDeserialized++;
                    }
                }

            return(true);
        }
Ejemplo n.º 2
0
        private static (Pip, PipId) DeserializePipAndPipId(PipReader reader)
        {
            Pip   pip = null;
            PipId pipId;

            try
            {
                pip = Pip.Deserialize(reader);

                // Pip id is not deserialized when pip is deserialized.
                // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                // remaps the pip id to a new pip id.
                pipId = PipId.Deserialize(reader);

                if (!pipId.IsValid)
                {
                    throw new BuildXLException("Deserialize pip id is invalid");
                }

                return(pip, pipId);
            }
            catch (Exception e)
            {
                string pipType = pip != null?pip.PipType.ToString() : "<NULL>";

                string semiStableHash = pip != null ? pip.FormattedSemiStableHash : "<NULL>";

                throw new BuildXLException($"Failed to deserialize pip (hash: {semiStableHash}, type: {pipType}) and pip id. Please send the fragment file to BuildXL team for further investigation.", e);
            }
        }
Ejemplo n.º 3
0
        public virtual Pip ReadPip()
        {
            Start <Pip>();
            Pip value = Pip.Deserialize(this);

            End();
            return(value);
        }
Ejemplo n.º 4
0
        public virtual Pip ReadPip()
        {
            Contract.Ensures(Contract.Result <Pip>() != null);
            Start <Pip>();
            Pip value = Pip.Deserialize(this);

            End();
            return(value);
        }
Ejemplo n.º 5
0
        private async Task <bool> DeserializeSeriallyAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            for (int totalPipsRead = 0; totalPipsRead < m_totalPipsToDeserialize; totalPipsRead++)
            {
                var pip   = Pip.Deserialize(reader);
                var pipId = new PipId(reader.ReadUInt32());
                if (!await(handleDeserializedPip?.Invoke(pipId, pip)))
                {
                    successful = false;
                }

                Stats.Increment(pip, serialize: false);
            }

            return(successful);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserializes a pip graph fragment and call the given handleDeserializedPip function on each pip deserialized.
        /// </summary>
        public bool Deserialize(
            AbsolutePath filePath,
            Func <PipGraphFragmentContext, PipGraphFragmentProvenance, PipId, Pip, bool> handleDeserializedPip = null,
            string fragmentDescriptionOverride = null)
        {
            Contract.Requires(filePath.IsValid);

            string fileName = filePath.ToString(m_pipExecutionContext.PathTable);

            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new PipRemapReader(m_pipExecutionContext, m_pipGraphFragmentContext, stream))
                {
                    string serializedDescription = reader.ReadNullableString();
                    FragmentDescription = (fragmentDescriptionOverride ?? serializedDescription) ?? filePath.ToString(m_pipExecutionContext.PathTable);
                    var provenance = new PipGraphFragmentProvenance(filePath, FragmentDescription);

                    m_totalPipsToDeserialize = reader.ReadInt32();

                    for (int i = 0; i < m_totalPipsToDeserialize; i++)
                    {
                        var pip = Pip.Deserialize(reader);

                        // Pip id is not deserialized when pip is deserialized.
                        // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                        // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                        // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                        // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                        // remaps the pip id to a new pip id.
                        var pipId = new PipId(reader.ReadUInt32());

                        var success = handleDeserializedPip?.Invoke(m_pipGraphFragmentContext, provenance, pipId, pip);

                        if (success.HasValue & !success.Value)
                        {
                            return(false);
                        }

                        Stats.Increment(pip, serialize: false);
                    }
                }

            return(true);
        }
Ejemplo n.º 7
0
        private async Task <bool> DeserializeTopSortAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            int totalPipsRead = 0;

            while (totalPipsRead < m_totalPipsToDeserialize)
            {
                var deserializedPips = reader.ReadReadOnlyList <(Pip pip, PipId pipId)>((deserializer) =>
                {
                    var pip = Pip.Deserialize(reader);

                    // Pip id is not deserialized when pip is deserialized.
                    // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                    // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                    // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                    // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                    // remaps the pip id to a new pip id.
                    var pipId = new PipId(reader.ReadUInt32());
                    return(pip, pipId);
                });

                totalPipsRead += deserializedPips.Count;
                Task <bool>[] tasks = new Task <bool> [deserializedPips.Count];

                for (int i = 0; i < deserializedPips.Count; i++)
                {
                    var deserializedPip = deserializedPips[i];
                    tasks[i] = HandleAndReportDeserializedPipAsync(handleDeserializedPip, deserializedPip.pipId, deserializedPip.pip);
                }

                successful &= (await Task.WhenAll(tasks)).All(x => x);
            }

            return(successful);
        }
Ejemplo n.º 8
0
        private bool DeserializeTopSort(Func <PipId, Pip, bool> handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            int totalPipsRead = 0;

            while (totalPipsRead < m_totalPipsToDeserialize)
            {
                var deserializedPips = reader.ReadReadOnlyList <(Pip, PipId)>((deserializer) =>
                {
                    var pip = Pip.Deserialize(reader);

                    // Pip id is not deserialized when pip is deserialized.
                    // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                    // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                    // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                    // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                    // remaps the pip id to a new pip id.
                    var pipId = new PipId(reader.ReadUInt32());
                    return(pip, pipId);
                });
                totalPipsRead += deserializedPips.Count;

                Parallel.ForEach(deserializedPips, new ParallelOptions(), deserializedPip =>
                {
                    if (!(handleDeserializedPip?.Invoke(deserializedPip.Item2, deserializedPip.Item1)).Value)
                    {
                        successful = false;
                    }

                    Stats.Increment(deserializedPip.Item1, serialize: false);
                });
            }

            return(successful);
        }