예제 #1
0
        public static bool TryReadInt32(this JsonFilter reader, out int value)
        {
            var possibleValue = reader.ReadAsInt32();

            if (possibleValue.HasValue)
            {
                value = possibleValue.Value;
                return(true);
            }

            value = 0;
            return(false);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }