/// <inheritdoc />
        public override void ProcessFingerprintComputed(ProcessFingerprintComputationEventData data)
        {
            if (data.Kind == FingerprintComputationKind.CacheCheck)
            {
                ObservedInputCounts?cacheMaxCounts = null;
                if (data.StrongFingerprintComputations != null)
                {
                    foreach (var strongFingerprintComputation in data.StrongFingerprintComputations)
                    {
                        if (strongFingerprintComputation.Succeeded)
                        {
                            var computationCounts = GetObservedInputCount(strongFingerprintComputation.ObservedInputs);
                            cacheMaxCounts = cacheMaxCounts?.Max(computationCounts) ?? computationCounts;
                        }
                    }

                    if (cacheMaxCounts.HasValue)
                    {
                        m_observedInputCounts.TryAdd(data.PipId, cacheMaxCounts.Value);
                    }
                }
            }
            else
            {
                Contract.Assert(data.Kind == FingerprintComputationKind.Execution);

                if (((data.StrongFingerprintComputations?.Count ?? 0) != 0) && data.StrongFingerprintComputations[0].Succeeded)
                {
                    ObservedInputCounts cacheMaxCounts;
                    if (m_observedInputCounts.TryRemove(data.PipId, out cacheMaxCounts))
                    {
                        var executionCounts = GetObservedInputCount(data.StrongFingerprintComputations[0].ObservedInputs);
                        ObservedInputCounts.LogForLowObservedInputs(
                            Events.StaticContext,
                            GetDescription(GetPip(data.PipId)),
                            executionCounts: executionCounts,
                            cacheMaxCounts: cacheMaxCounts);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to remove producer.
        /// </summary>
        public bool TryRemoveProducer(PipStableId producer)
        {
            if (m_producedPaths.ContainsKey(producer))
            {
                m_producedPaths.AddOrUpdate(
                    producer,
                    (HashSet <AbsolutePath>)null,
                    (p, nullValue) => new HashSet <AbsolutePath>(),
                    (p, nullValue, existingSet) =>
                {
                    foreach (var path in existingSet)
                    {
                        m_pipProducers.TryRemove(path, out var dummyId);
                    }

                    return(new HashSet <AbsolutePath>());
                });

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public void TestConcurrentBigMapOperations()
        {
            var map = new ConcurrentBigMap <int, string>();

            XAssert.IsTrue(map.TryAdd(0, "value"));
            XAssert.IsFalse(map.TryAdd(0, "not added value"));
            XAssert.AreEqual("value", map[0]);
            map[0] = "newValue";
            map[1] = "value1";

            var value0 = "newValue";

            XAssert.AreEqual(value0, map[0]);
            XAssert.IsTrue(map.ContainsKey(0));
            XAssert.IsTrue(map.ContainsKey(1));
            XAssert.IsFalse(map.ContainsKey(12));

            XAssert.AreEqual(2, map.Count);

            // Test TryGetValue
            string value1;

            XAssert.IsTrue(map.TryGetValue(1, out value1));
            XAssert.AreEqual("value1", value1);
            string value31;

            XAssert.IsFalse(map.TryGetValue(31, out value31));

            // Test update
            XAssert.IsFalse(map.TryUpdate(1, "notUpdatedValue1", "notActualValue1"));
            XAssert.AreEqual("value1", map[1]);
            XAssert.IsTrue(map.TryUpdate(1, "updatedValue1", "value1"));
            value1 = map[1];
            XAssert.AreEqual("updatedValue1", value1);

            // Test remove
            int    beforeFailedRemoveCount = map.Count;
            string value23;

            XAssert.IsFalse(map.TryRemove(23, out value23));
            XAssert.AreEqual(beforeFailedRemoveCount, map.Count);
            map.Add(23, "value23");
            XAssert.AreEqual(beforeFailedRemoveCount + 1, map.Count);
            XAssert.IsTrue(map.TryRemove(23, out value23));
            XAssert.AreEqual("value23", value23);
            XAssert.AreEqual(beforeFailedRemoveCount, map.Count);

            Assert.Equal(new int[] { 0, 1 }, map.Keys.ToArray());
            Assert.Equal(new string[] { value0, value1 }, map.Values.ToArray());

            XAssert.AreEqual(2, map.Count);

            string addedData    = "added data";
            string notAddedData = "not added data";
            var    result       = map.GetOrAdd(2, addedData, (key, data0) => data0);

            XAssert.IsFalse(result.IsFound);
            XAssert.AreEqual(addedData, result.Item.Value);
            XAssert.AreEqual(addedData, map[2]);

            // Ensure entry is not updated for get or add
            result = map.GetOrAdd(2, notAddedData, (key, data0) => data0);
            XAssert.IsTrue(result.IsFound);
            XAssert.AreEqual(addedData, result.Item.Value);
            XAssert.AreEqual(addedData, map[2]);

            Func <int, string, string, string> updateFunction =
                (key, data0, currentValue) => "updated " + currentValue;

            var updatedData = updateFunction(2, notAddedData, addedData);

            result = map.AddOrUpdate(2, notAddedData, (key, data0) => data0, updateFunction);
            XAssert.IsTrue(result.IsFound);
            XAssert.AreEqual(addedData, result.OldItem.Value);
            XAssert.AreEqual(updatedData, result.Item.Value);
            XAssert.AreEqual(updatedData, map[2]);

            result = map.AddOrUpdate(3, addedData, (key, data0) => data0, updateFunction);
            XAssert.IsFalse(result.IsFound);
            XAssert.AreEqual(addedData, result.Item.Value);
            XAssert.AreEqual(addedData, map[3]);

            TestOperationsHelper(parallel: false);
        }