Exemplo n.º 1
0
		public static IBufferManager CreateManager(RunModeInfo mode,
			AlgorithmSpec algo, uint npages)
		{
			string lowerName = algo.Name.ToLower();

			string algoString = normalNames[lowerName] + algo.ArgumentString;
			IBlockDevice dev = CreateDevice(mode, algoString);

			return (IBufferManager)creators[lowerName].Invoke(
				null, new object[] { dev, npages, algo.Arguments });
		}
Exemplo n.º 2
0
        public static ManagerGroup InitGroup(uint[] npageses,
            AlgorithmSpec[] algorithms, RunModeInfo mode)
        {
            if (npageses.Length == 1)
                return InitSubGroup(npageses[0], algorithms, mode);

            ManagerGroup group = new ManagerGroup();

            foreach (uint npages in npageses)
                group.Add(InitSubGroup(npages, algorithms, mode));

            return group;
        }
Exemplo n.º 3
0
		public static IBlockDevice CreateDevice(RunModeInfo mode, string algostring)
		{
			switch (mode.Mode)
			{
				case RunMode.Verify:
					return new MemorySimulatedDevice(1);

				case RunMode.File:
					return new FileSimulatedDevice(PageSize,
						(string)((object[])mode.ExtInfo)[0],
						(bool)((object[])mode.ExtInfo)[1]);

				case RunMode.Trace:
					return new TraceLogDevice(
						(string)mode.ExtInfo + "." + algostring + ".trace");

				default:
					return new NullBlockDevice();
			}
		}
Exemplo n.º 4
0
        private static ManagerGroup InitSubGroup(uint npages,
            AlgorithmSpec[] algorithms, RunModeInfo mode)
        {
            string algoname = null;

            try
            {
                ManagerGroup group = new ManagerGroup();
                foreach (AlgorithmSpec algo in algorithms)
                {
                    algoname = algo.Name;
                    group.Add(Config.CreateManager(mode, algo, npages));
                }
                return group;
            }
            catch (Exception ex)
            {
                throw new InvalidCmdLineArgumentException(string.Format(
                    "Exception occurs when creating {0}. Details: {1}",
                    algoname, ex.Message), ex);
            }
        }
Exemplo n.º 5
0
        public static void ParseArguments(string[] args, out string filename,
            out decimal readCost, out decimal writeCost, out uint[] npageses,
            out AlgorithmSpec[] algorithms, out RunModeInfo mode)
        {
            // Init
            readCost = 80;
            writeCost = 200;
            npageses = new uint[] { 1024 };

            bool verify = false, tracelog = false;
            bool fileop = false, fileopWithoutCheckSize = false;
            string opfilename = null, tracelogfile = null;
            Regex regexAlgo = new Regex(@"(\w+)(?:\(([^)]+)\))?");
            List<AlgorithmSpec> algos = new List<AlgorithmSpec>();

            // Parse
            Getopt g = new Getopt(Utils.ProgramName, args, ":a:cf:F:hp:r:t:w:");
            g.Opterr = false;
            int c;

            while ((c = g.getopt()) != -1)
            {
                switch (c)
                {
                    case 'a':
                        foreach (Match m in regexAlgo.Matches(g.Optarg))
                        {
                            string name = m.Groups[1].Value;
                            string[] arg = m.Groups[2].Value.Split(',');

                            if (m.Groups[2].Success)
                                algos.Add(new AlgorithmSpec(name, arg));
                            else
                                algos.Add(new AlgorithmSpec(name));
                        }
                        break;

                    case 'c':
                        verify = true;
                        break;

                    case 'f':
                        fileop = true;
                        fileopWithoutCheckSize = true;
                        opfilename = g.Optarg;
                        break;

                    case 'F':
                        fileop = true;
                        fileopWithoutCheckSize = false;
                        opfilename = g.Optarg;
                        break;

                    case 'h':
                        throw new CmdLineHelpException();

                    case 'p':
                        string[] strs = g.Optarg.Split(',');
                        npageses = new uint[strs.Length];

                        for (int i = 0; i < strs.Length; i++)
                        {
                            if (!uint.TryParse(strs[i], out npageses[i]) || npageses[i] == 0)
                                throw new InvalidCmdLineArgumentException(
                                    "Positive integer(s) are expected after -p");
                        }

                        break;

                    case 'r':
                        if (!decimal.TryParse(g.Optarg, out readCost) || readCost <= 0)
                            throw new InvalidCmdLineArgumentException(
                                "A positive integer is expected after -r");
                        break;

                    case 't':
                        tracelog = true;
                        tracelogfile = g.Optarg;
                        break;

                    case 'w':
                        if (!decimal.TryParse(g.Optarg, out writeCost) || writeCost <= 0)
                            throw new InvalidCmdLineArgumentException(
                                "A positive integer is expected after -w");
                        break;

                    case ':':
                        throw new InvalidCmdLineArgumentException(
                            "Uncomplete argument: -" + (char)g.Optopt);
                    case '?':
                        throw new InvalidCmdLineArgumentException(
                            "Invalid argument: -" + (char)g.Optopt);
                    default:
                        break;
                }
            }

            // Filename
            if (args.Length > g.Optind)
                filename = args[g.Optind];
            else
                filename = null;

            // Algorithm
            if (algos.Count == 0)
                algorithms = new AlgorithmSpec[] { new AlgorithmSpec("Trival") };
            else
                algorithms = algos.ToArray();

            // Run Mode
            if (fileop && (algorithms.Length > 1 || npageses.Length > 1))
                throw new InvalidCmdLineArgumentException(
                    "In -f mode, only ONE algorithm and only ONE npages is allowed.");

            if (verify && fileop)
                throw new InvalidCmdLineArgumentException(
                    "Cannot specify both -c and -f/-F");
            else if (verify && tracelog)
                throw new InvalidCmdLineArgumentException(
                    "Cannot specify both -c and -s");
            else if (fileop && tracelog)
                throw new InvalidCmdLineArgumentException(
                    "Cannot specify both -s and -f/-F");
            else if (verify)
                mode = new RunModeInfo(RunMode.Verify, null);
            else if (fileop)
                mode = new RunModeInfo(RunMode.File, new object[] {
                    opfilename, fileopWithoutCheckSize });
            else if (tracelog)
                mode = new RunModeInfo(RunMode.Trace, tracelogfile);
            else
                mode = new RunModeInfo(RunMode.Normal, null);
        }