예제 #1
0
        /// <summary>
        /// Helper functions for putting entries into the fingerprint store for sub-components.
        /// { pip formatted semi stable hash : weak fingerprint, strong fingerprint, path set hash }
        /// { weak fingerprint hash : weak fingerprint inputs }
        /// { strong fingerprint hash : strong fingerprint inputs }
        /// { path set hash : path set inputs }
        /// </summary>
        private FingerprintStoreEntry CreateAndStoreFingerprintStoreEntry(
            FingerprintStore fingerprintStore,
            Process pip,
            PipFingerprintKeys pipFingerprintKeys,
            WeakContentFingerprint weakFingerprint,
            ProcessStrongFingerprintComputationData strongFingerprintData,
            bool cacheWeakFingerprintSerialization = false)
        {
            // If we got this far, a new pip is being put in the store
            Counters.IncrementCounter(FingerprintStoreCounters.NumPipFingerprintEntriesPut);

            UpdateOrStorePipUniqueOutputHashEntry(fingerprintStore, pip);

            // A content hash-keyed entry will have the same value as long as the key is the same, so overwriting it is unnecessary
            var mustStorePathEntry = !fingerprintStore.ContainsContentHash(pipFingerprintKeys.FormattedPathSetHash) || CacheMissAnalysisEnabled;

            var entry = CreateFingerprintStoreEntry(
                pip,
                pipFingerprintKeys,
                weakFingerprint,
                strongFingerprintData,
                mustStorePathEntry: mustStorePathEntry,
                cacheWeakFingerprintSerialization: cacheWeakFingerprintSerialization);

            fingerprintStore.PutFingerprintStoreEntry(entry, storePathSet: mustStorePathEntry);
            return(entry);
        }
예제 #2
0
        internal FingerprintStoreEntry CreateFingerprintStoreEntry(
            Process pip,
            PipFingerprintKeys pipFingerprintKeys,
            WeakContentFingerprint weakFingerprint,
            ProcessStrongFingerprintComputationData strongFingerprintData,
            bool mustStorePathEntry = true,
            bool cacheWeakFingerprintSerialization = false)
        {
            Counters.IncrementCounter(FingerprintStoreCounters.CreateFingerprintStoreEntryCount);

            using (Counters.StartStopwatch(FingerprintStoreCounters.CreateFingerprintStoreEntryTime))
            {
                string pipSerializedWeakFingerprint = null;

                if (cacheWeakFingerprintSerialization)
                {
                    pipSerializedWeakFingerprint = m_weakFingerprintSerializationTransientCache.GetOrAdd(
                        pip.PipId,
                        (pipId, p) =>
                    {
                        Counters.IncrementCounter(FingerprintStoreCounters.JsonSerializationWeakFingerprintCount);
                        return(JsonSerialize(p));
                    },
                        pip);
                }
                else
                {
                    if (!m_weakFingerprintSerializationTransientCache.TryRemove(pip.PipId, out pipSerializedWeakFingerprint))
                    {
                        Counters.IncrementCounter(FingerprintStoreCounters.JsonSerializationWeakFingerprintCount);
                        pipSerializedWeakFingerprint = JsonSerialize(pip);
                    }
                }

                return(new FingerprintStoreEntry
                {
                    // { pip formatted semi stable hash : weak fingerprint, strong fingerprint, path set hash }
                    PipToFingerprintKeys = new PipKVP(pip.FormattedSemiStableHash, pipFingerprintKeys),
                    // { weak fingerprint hash : weak fingerprint inputs }
                    WeakFingerprintToInputs = new KVP(pipFingerprintKeys.WeakFingerprint, pipSerializedWeakFingerprint),
                    StrongFingerprintEntry = new StrongFingerprintEntry
                    {
                        // { strong fingerprint hash: strong fingerprint inputs }
                        StrongFingerprintToInputs = new KVP(pipFingerprintKeys.StrongFingerprint, JsonSerialize(weakFingerprint, strongFingerprintData.PathSetHash, strongFingerprintData.ObservedInputs)),
                        // { path set hash : path set inputs }
                        // If fingerprint comparison is enabled, the entry should contain the pathset json.
                        PathSetHashToInputs = mustStorePathEntry ? new KVP(pipFingerprintKeys.FormattedPathSetHash, JsonSerialize(strongFingerprintData)) : default,
 internal FingerprintStoreEntry CreateFingerprintStoreEntry(
     Process pip,
     PipFingerprintKeys pipFingerprintKeys,
     WeakContentFingerprint weakFingerprint,
     ProcessStrongFingerprintComputationData strongFingerprintData,
     bool mustStorePathEntry = true)
 {
     return(new FingerprintStoreEntry
     {
         // { pip formatted semi stable hash : weak fingerprint, strong fingerprint, path set hash }
         PipToFingerprintKeys = new PipKVP(pip.FormattedSemiStableHash, pipFingerprintKeys),
         // { weak fingerprint hash : weak fingerprint inputs }
         WeakFingerprintToInputs = new KVP(pipFingerprintKeys.WeakFingerprint, JsonSerialize(pip)),
         StrongFingerprintEntry = new StrongFingerprintEntry
         {
             // { strong fingerprint hash: strong fingerprint inputs }
             StrongFingerprintToInputs = new KVP(pipFingerprintKeys.StrongFingerprint, JsonSerialize(weakFingerprint, strongFingerprintData.PathSetHash, strongFingerprintData.ObservedInputs)),
             // { path set hash : path set inputs }
             // If fingerprint comparison is enabled, the entry should contain the pathset json.
             PathSetHashToInputs = mustStorePathEntry ? new KVP(pipFingerprintKeys.FormattedPathSetHash, JsonSerialize(strongFingerprintData)) : default,