Beispiel #1
0
        public void ReadJsonGraph(string path, string targetPath = null, bool loadTargetIfApplicable = true)
        {
            if (loadTargetIfApplicable && targetPath != null && File.Exists(targetPath))
            {
                if (Deserialize(targetPath))
                {
                    return;
                }
            }

            MutableDataflowGraph = new MutableDirectedGraph();
            DataflowGraph        = MutableDataflowGraph;
            using (var stream = new ProgressStream(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 64 << 10), "JsonData"))
                using (var textReader = new StreamReader(stream))
                    using (var textWriter = new StreamWriter(Path.ChangeExtension(targetPath, ".filter.json")))
                        using (var reader = new JsonFilter(path, new JsonTextReader(textReader), new JsonTextWriter(textWriter)))
                        {
                            AssertPostRead(reader, JsonToken.StartObject);
                            while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                            {
                                string propertyName = (string)reader.Value;
                                switch (propertyName)
                                {
                                case "graph":
                                    ReadGraph(reader);
                                    break;

                                case "execution":
                                    ReadExecutions(reader);
                                    break;

                                case "pips":
                                    ReadPips(reader);
                                    break;

                                default:
                                    reader.Skip();
                                    break;
                                }
                            }
                        }

            AddEdges();

            Compute();

            if (targetPath != null)
            {
                Serialize(targetPath);
            }
        }
Beispiel #2
0
        public void ReadExecutions(JsonFilter reader)
        {
            AssertPostRead(reader, JsonToken.StartArray);
            while (reader.Read() && reader.TokenType == JsonToken.StartObject)
            {
                AssertPostRead(reader, JsonToken.PropertyName);
                var id   = reader.ReadAsInt32().Value;
                var node = GetNodeForId(id);

                ulong?startTime = null, endTime = null;

                while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                {
                    string propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "startTime":
                        startTime = reader.ReadAsUInt64();
                        break;

                    case "endTime":
                        endTime = reader.ReadAsUInt64();
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }

                Contract.Assert(startTime.HasValue);
                Contract.Assert(endTime.HasValue);
                Min(ref MinStartTime, startTime.Value);
                Max(ref MaxEndTime, endTime.Value);
                StartTimes[node] = startTime.Value;
                Durations[node]  = endTime.Value - startTime.Value;

                AssertToken(reader, JsonToken.EndObject);
            }

            TotalDuration = MaxEndTime - MinStartTime;

            AssertToken(reader, JsonToken.EndArray);
        }
Beispiel #3
0
        public void ReadPips(JsonFilter reader)
        {
            Dictionary <string, PipType> pipTypeLookup = new Dictionary <string, PipType>();

            foreach (PipType pt in Enum.GetValues(typeof(PipType)))
            {
                pipTypeLookup[pt.ToString()] = pt;
            }

            AssertPostRead(reader, JsonToken.StartArray);
            while (reader.Read() && reader.TokenType == JsonToken.StartObject)
            {
                AssertPostRead(reader, JsonToken.PropertyName);
                var id = (uint)reader.ReadAsInt32();

                while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                {
                    string propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "type":
                        PipTypes[id] = pipTypeLookup[reader.ReadAsString()];
                        break;

                    case "stableId":
                        SemiStableHashes[id] = ulong.Parse(reader.ReadAsString(), NumberStyles.HexNumber);
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }

                AssertToken(reader, JsonToken.EndObject);
            }

            AssertToken(reader, JsonToken.EndArray);
        }
Beispiel #4
0
        public void ReadGraph(JsonFilter reader)
        {
            Dictionary <string, PipType> pipTypeLookup = new Dictionary <string, PipType>();

            foreach (PipType pt in Enum.GetValues(typeof(PipType)))
            {
                pipTypeLookup[pt.ToString()] = pt;
            }

            AssertPostRead(reader, JsonToken.StartArray);
            while (reader.Read() && reader.TokenType == JsonToken.StartObject)
            {
                AssertPostRead(reader, JsonToken.PropertyName);
                var    id   = (int)reader.ReadAsInt32();
                NodeId node = GetNodeForId(id);


                while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                {
                    int    value        = 0;
                    string propertyName = (string)reader.Value;
                    switch (propertyName)
                    {
                    case "type":
                        PipTypes[node] = pipTypeLookup[reader.ReadAsString()];
                        break;

                    case "stableId":
                        SemiStableHashes[node] = ulong.Parse(reader.ReadAsString(), NumberStyles.HexNumber);
                        break;

                    case "dependsOn":
                        AssertPostRead(reader, JsonToken.StartArray);
                        while (reader.TryReadInt32(out value))
                        {
                            MutableDataflowGraph.AddEdge(GetNodeForId(value), node);
                        }

                        AssertToken(reader, JsonToken.EndArray);
                        break;

                    case "consumes":
                        AssertPostRead(reader, JsonToken.StartArray);
                        while (reader.TryReadInt32(out value))
                        {
                            var list = GetOrAddDependenciesList(node);
                            list.Add(value);
                        }

                        AssertToken(reader, JsonToken.EndArray);
                        break;

                    case "produces":
                        AssertPostRead(reader, JsonToken.StartArray);
                        while (reader.TryReadInt32(out value))
                        {
                            m_pipProducers[value] = node;
                        }

                        AssertToken(reader, JsonToken.EndArray);
                        break;

                    case "provenance":
                        AssertPostRead(reader, JsonToken.StartObject);
                        while (reader.Read() && reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.Equals("value"))
                            {
                                var outputValue = FullSymbol.Create(SymbolTable, reader.ReadAsString());
                                OutputValues[node] = outputValue;
                                continue;
                            }

                            reader.Skip();
                        }

                        AssertToken(reader, JsonToken.EndObject);
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }

                AssertToken(reader, JsonToken.EndObject);
            }

            AssertToken(reader, JsonToken.EndArray);
        }