Exemple #1
0
 public static unsafe string GetWritePointer(BinaryStream bs)
 {
     return("GetWritePointer\t" +
            StepTimer.Time(10, () =>
     {
         bs.GetWritePointer(40 * 1000000, 1);
         bs.GetWritePointer(80 * 1000000, 1);
         bs.GetWritePointer(120 * 1000000, 1);
         bs.GetWritePointer(50 * 1000000, 1);
         bs.GetWritePointer(90 * 1000000, 1);
         bs.GetWritePointer(130 * 1000000, 1);
         bs.GetWritePointer(60 * 1000000, 1);
         bs.GetWritePointer(100 * 1000000, 1);
         bs.GetWritePointer(140 * 1000000, 1);
         bs.GetWritePointer(110 * 1000000, 1);
     }));
 }
        public void Benchmark(uint page, string text)
        {
            Stopwatch sw = new Stopwatch();

            IndexMapper map = new IndexMapper((int)BlockSize);

            System.Console.WriteLine(text +
                                     StepTimer.Time(10, () =>
            {
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
                map.MapPosition(page);
            }));
        }
        public void Test1()
        {
            MemoryPoolTest.TestMemoryLeak();
            MemoryPoolFile file = new MemoryPoolFile(Globals.MemoryPool);

            BinaryStreamIoSessionBase session = file.CreateIoSession();

            BlockArguments blockArguments = new BlockArguments();

            blockArguments.IsWriting = true;
            blockArguments.Position  = 10000000;
            session.GetBlock(blockArguments);


            System.Console.WriteLine("Get Block\t" + StepTimer.Time(10, () =>
            {
                blockArguments.Position = 100000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 200000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 300000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 400000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 500000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 600000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 700000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 800000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 900000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 1000000;
                session.GetBlock(blockArguments);
            }));
            file.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }
        internal static void TestSpeed <TKey, TValue>(SortedTreeNodeBase <TKey, TValue> nodeInitializer, TreeNodeRandomizerBase <TKey, TValue> randomizer, int count, int pageSize)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            int Max = count;

            uint        nextKeyIndex = 2;
            Func <uint> getNextKey   = () =>
            {
                nextKeyIndex++;
                return(nextKeyIndex - 1);
            };


            using (BinaryStream bs = new BinaryStream())
            {
                randomizer.Reset(Max);
                for (int x = 0; x < Max; x++)
                {
                    randomizer.Next();
                }

                TKey   key   = new TKey();
                TValue value = new TValue();
                SortedTreeNodeBase <TKey, TValue> node = null;

                System.Console.WriteLine(StepTimer.Time(count, (sw) =>
                {
                    nextKeyIndex = 2;
                    node         = nodeInitializer.Clone(0);
                    SparseIndex <TKey> sparse = new SparseIndex <TKey>();
                    sparse.Initialize(bs, pageSize, getNextKey, 0, 1);
                    node.Initialize(bs, pageSize, getNextKey, sparse);
                    node.CreateEmptyNode(1);
                    sw.Start();
                    for (int x = 0; x < Max; x++)
                    {
                        //Add the next point
                        randomizer.GetRandom(x, key, value);

                        if (!node.TryInsert(key, value))
                        {
                            throw new Exception();
                        }
                    }
                    sw.Stop();
                }));


                System.Console.WriteLine(StepTimer.Time(count, () =>
                {
                    for (int x = 0; x < Max; x++)
                    {
                        //Add the next point
                        randomizer.GetRandom(x, key, value);

                        if (!node.TryGet(key, value))
                        {
                            throw new Exception();
                        }
                    }
                }));



                System.Console.WriteLine(StepTimer.Time(count, () =>
                {
                    SortedTreeScannerBase <TKey, TValue> scanner = node.CreateTreeScanner();
                    scanner.SeekToStart();
                    while (scanner.Read(key, value))
                    {
                        ;
                    }
                }));

                node = node;
            }
        }
Exemple #5
0
        public (bool result, ChangesDetected changes) CheckForChanges(MusicDb db)
        {
            ChangesDetected changesDetected = ChangesDetected.None;
            bool            result          = false;
            var             st = new StepTimer();

            st.Start();
            var currentMusicFiles = GetMusicFilesFromDb(db);//.ToArray();

            st.Time();
            var filesOnDisk = GetFilesOnDisk();

            st.Time();
            bool anyFilesNotCatalogued()
            {
                bool r    = false;
                var  list = currentMusicFiles.Where(x => x.Track == null);

                r = list.Count() > 0;
                st.Time();
                if (r)
                {
                    changesDetected = ChangesDetected.AtLeastOneFileNotCatalogued;
                    //log.Trace($"anyFilesNotCatalogued() returns true");
                }
                return(r);
            }

            bool anyFilesRewritten()
            {
                bool r  = false;
                var  l1 = currentMusicFiles.Select(x => x.FileLastWriteTimeUtc);
                var  l2 = filesOnDisk.Select(x => new DateTimeOffset(x.fi.LastWriteTimeUtc, TimeSpan.Zero));

                r = !l1.SequenceEqual(l2);
                st.Time();
                if (r)
                {
                    changesDetected = ChangesDetected.AtLeastOneFileModifiedOnDisk;
                    log.Trace($"anyFilesRewritten() returns true");
                }
                return(r);
            }

            bool musicTagsAreNew()
            {
                bool r = false;

                if (HasMusicTags())
                {
                    var tagFile = Path.Combine(Folderpath, ITEOBase.TagFile);
                    var tagTime = new DateTimeOffset(new FileInfo(tagFile).LastWriteTimeUtc, TimeSpan.Zero);
                    r = currentMusicFiles.Any(mf => mf.LastCataloguedAt < tagTime);
                }
                st.Time();
                if (r)
                {
                    changesDetected = ChangesDetected.MusicTagsAreNewer;
                    //log.Trace($"customTagsAreNew() returns true");
                }
                return(r);
            }

            bool additionsOrDeletionsExist()
            {
                var differences = filesOnDisk.Select(f => f.fi.FullName).Except(currentMusicFiles.Select(mf => mf.File), StringComparer.CurrentCultureIgnoreCase);

                st.Time();
                var r = differences.Count() != 0;

                if (r)
                {
                    changesDetected = ChangesDetected.MusicFileCountHasChanged;
                    log.Debug($"music file difference count is {differences.Count()}");
                }
                return(r);
            }

            bool anyImageChanged()
            {
                bool r     = false;
                var  works = currentMusicFiles.Select(mf => mf.Track).Select(x => x.Work).Distinct();
                //currentMusicFiles.Select(mf => mf.Track).Where(x => x.Performance != null)
                //    .Select(x => x.Performance.Composition.Artist).Distinct();
                var artists = works.Select(x => x.Artist)
                              .Union(currentMusicFiles.Select(mf => mf.Track).Where(x => x.Performance != null)
                                     .Select(x => x.Performance.Composition.Artist))
                              .Distinct();

                foreach (var artist in artists.Where(a => a.Type != ArtistType.Various))
                {
                    var f = artist.GetPortraitFile(MusicOptions);
                    if (artist.Portrait.HasChanged(f))
                    {
                        log.Debug($"artist {artist.Name}, portrait file {f} found");
                        r = true;
                        break;
                    }
                }
                if (!r)
                {
                    foreach (var work in works)
                    {
                        //var coverFile = MusicStyle.GetMostRecentOpusCoverFile(MusicOptions, IsCollection ? "Collections" : work.Artist.Name, currentPathData.OpusPath);
                        //var coverFile = MusicStyle.GetMostRecentOpusCoverFile(MusicOptions, work, currentPathData.OpusPath);
                        var coverFile = work.GetMostRecentOpusCoverFile(MusicOptions);
                        if (work.Cover.HasChanged(coverFile))
                        {
                            log.Debug($"artist {work.Artist.Name}, work {work.Name}, cover art file {coverFile}");
                            r = true;
                            break;
                        }
                    }
                }
                if (r)
                {
                    changesDetected = ChangesDetected.CoverArtHasChanged;
                    //log.Trace($"anyImageChanged() returns true");
                }
                return(r);
            }

            if (additionsOrDeletionsExist() || musicTagsAreNew() || anyFilesRewritten() || anyFilesNotCatalogued() || anyImageChanged())
            {
                result = true;
            }
            return(result, changesDetected);
        }