Exemple #1
0
        public void Initialize()
        {
            var commandsReader1 = new CommandFileReader($"file{Program.Node}.txt");

            _timerExecutor = new TimerExecutor(
                commandsReader1.ReadCommands().ToArray(),
                command =>
            {
                //Console.WriteLine($"Executing command {command.Time}...");
                switch (command.Type)
                {
                case CommandType.Insert:
                    // ReSharper disable once PossibleInvalidOperationException
                    return(InsertAsync(command.Key, command.Value.Value));

                case CommandType.Select:
                    return(command.Key != null
                                ? SelectAsync(command.Key)
                                : SelectAllAsync());

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });

            IsInitialized = true;

            _mainTask = Task.Run(async() =>
            {
                await WaitInitAsync();

                Console.WriteLine("Start executing...");
                await _timerExecutor.Execute();
            });
        }
Exemple #2
0
        public void Run()
        {
            //DebugOut("Z-machine version {0}", zversion);

            ResetHeaderFields(true);
            io.EraseWindow(-1);

            pc = (ushort)GetWord(0x06);

            cache = new LruCache <int, CachedCode>(cacheSize);

#if BENCHMARK
            // reset performance stats
            cycles       = 0;
            startTime    = Environment.TickCount;
            creditedTime = 0;
            cacheHits    = 0;
            cacheMisses  = 0;
#endif

            running = true;
            try
            {
                JitLoop();
            }
            finally
            {
                running = false;
                if (cmdRdr != null)
                {
                    cmdRdr.Dispose();
                    cmdRdr = null;
                }
                if (cmdWtr != null)
                {
                    cmdWtr.Dispose();
                    cmdWtr = null;
                }
            }

#if BENCHMARK
            // show performance report
            int      billedMillis = Environment.TickCount - startTime - creditedTime;
            TimeSpan billedTime   = new TimeSpan(10000 * billedMillis);
            io.PutString("\n\n*** Performance Report ***\n");
            io.PutString(string.Format("Cycles: {0}\nTime: {1}\nSpeed: {2:0.0} cycles/sec\n",
                                       cycles,
                                       billedTime,
                                       cycles * 1000 / (double)billedMillis));
#if DISABLE_CACHE
            io.PutString("Code cache was disabled.\n");
#else
            io.PutString(string.Format("Final cache use: {1} instructions in {0} fragments\n",
                                       cache.Count,
                                       cache.CurrentSize));
            io.PutString(string.Format("Peak cache use: {0} instructions\n", cache.PeakSize));
            io.PutString(string.Format("Cache hits: {0}. Misses: {1}.\n", cacheHits, cacheMisses));
#endif // DISABLE_CACHE
#endif // BENCHMARK
        }
Exemple #3
0
        static async Task Main(string[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            var filePath1       = args[0];
            var filePath2       = args[1];
            var filePath3       = args[2];
            var commandsReader1 = new CommandFileReader(filePath1);
            var commandsReader2 = new CommandFileReader(filePath2);
            var commandsReader3 = new CommandFileReader(filePath3);
            var executor        = new TimerExecutor(
                commandsReader1.ReadCommands()
                .Concat(commandsReader2.ReadCommands())
                .Concat(commandsReader3.ReadCommands())
                .ToArray(),
                command =>
            {
                //Console.WriteLine($"Executing command {command.Time}...");
                switch (command.Type)
                {
                case CommandType.Insert:
                    // ReSharper disable once PossibleInvalidOperationException
                    return(InsertAsync(command.Key, command.Value.Value));

                case CommandType.Select:
                    return(command.Key != null
                                ? SelectAsync(command.Key)
                                : SelectAllAsync());

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });

            await WaitSlavesAsync();

            Console.WriteLine("Start executing...");
            await executor.Execute();

            Console.WriteLine("Show stats...");
            await ShowStatsAsync();

            Console.WriteLine("Done!");
        }
        private void SetInputStream(short num)
        {
            switch (num)
            {
            case 0:
                if (cmdRdr != null)
                {
                    cmdRdr.Dispose();
                    cmdRdr = null;
                }
                break;

            case 1:
                Stream cmdStream = io.OpenCommandFile(false);
                if (cmdStream != null)
                {
                    if (cmdRdr != null)
                    {
                        cmdRdr.Dispose();
                    }

                    try
                    {
                        cmdRdr = new CommandFileReader(cmdStream);
                    }
                    catch
                    {
                        cmdRdr = null;
                    }
                }
                break;

            default:
                throw new Exception("Invalid input stream #" + num.ToString());
            }
        }
Exemple #5
0
        private void SetInputStream(short num)
        {
            switch (num)
            {
                case 0:
                    if (cmdRdr != null)
                    {
                        cmdRdr.Dispose();
                        cmdRdr = null;
                    }
                    break;

                case 1:
                    Stream cmdStream = io.OpenCommandFile(false);
                    if (cmdStream != null)
                    {
                        if (cmdRdr != null)
                            cmdRdr.Dispose();

                        try
                        {
                            cmdRdr = new CommandFileReader(cmdStream);
                        }
                        catch
                        {
                            cmdRdr = null;
                        }
                    }
                    break;

                default:
                    throw new Exception("Invalid input stream #" + num.ToString());
            }
        }
Exemple #6
0
        public void Run()
        {
            //DebugOut("Z-machine version {0}", zversion);

            ResetHeaderFields(true);
            io.EraseWindow(-1);
            if (zversion <= 4)
                io.ScrollFromBottom = true;

            if (zversion == 6)
            {
                EnterFunctionImpl(GetWord(0x06), null, -1, -1);
            }
            else
            {
                pc = (ushort)GetWord(0x06);
            }

            cache = new LruCache<int, CachedCode>(cacheSize);

#if BENCHMARK
            // reset performance stats
            cycles = 0;
            startTime = Environment.TickCount;
            creditedTime = 0;
            cacheHits = 0;
            cacheMisses = 0;
#endif

            running = true;
            try
            {
                JitLoop();
            }
            finally
            {
                running = false;
                if (cmdRdr != null)
                {
                    cmdRdr.Dispose();
                    cmdRdr = null;
                }
                if (cmdWtr != null)
                {
                    cmdWtr.Dispose();
                    cmdWtr = null;
                }
            }

#if BENCHMARK
            // show performance report
            int billedMillis = Environment.TickCount - startTime - creditedTime;
            TimeSpan billedTime = new TimeSpan(10000 * billedMillis);
            io.PutString("\n\n*** Performance Report ***\n");
            io.PutString(string.Format("Cycles: {0}\nTime: {1}\nSpeed: {2:0.0} cycles/sec\n",
                cycles,
                billedTime,
                cycles * 1000 / (double)billedMillis));
#if DISABLE_CACHE
            io.PutString("Code cache was disabled.\n");
#else
            io.PutString(string.Format("Final cache use: {1} instructions in {0} fragments\n",
                cache.Count,
                cache.CurrentSize));
            io.PutString(string.Format("Peak cache use: {0} instructions\n", cache.PeakSize));
            io.PutString(string.Format("Cache hits: {0}. Misses: {1}.\n", cacheHits, cacheMisses));
            MeasureCacheOverlap();
#endif // DISABLE_CACHE
#endif // BENCHMARK
        }