Beispiel #1
0
        internal void AddQueryResults(QueriesPerSubject results)
        {
            if (this.querytimes == null)
            {
                this.querytimes = CreateTable("QueryResults");
            }

            var insertOperation = TableOperation.Insert(results);

            // Execute the insert operation.
            this.querytimes.Execute(insertOperation);
        }
Beispiel #2
0
        public async Task <Tuple <long, long, long> > ComputeRandomQueries(int repetitions, string expId = "DummyExperimentID")
        {
            if (string.IsNullOrEmpty(this.ExperimentID))
            {
                this.ExperimentID = expId;
            }

            var  solutionManager = this.SolutionManager;
            var  random          = new Random();
            long sumTime         = 0;
            long maxTime         = 0;
            long minTime         = long.MaxValue;

            long[] times = new long[repetitions];

            //var numberOfMethods = await solutionManager.GetReachableMethodsCountAsync();

            var warmingUpQueries = 50;

            for (int i = 0; i < repetitions + warmingUpQueries; i++)
            {
                //var methodNumber = random.Next(numberOfMethods);
                //var methodDescriptor = await solutionManager.GetMethodDescriptorByIndexAsync(methodNumber);
                var methodDescriptor = await solutionManager.GetRandomMethodAsync();

                var invocationCount = await CallGraphQueryInterface.GetInvocationCountAsync(solutionManager, methodDescriptor);

                if (invocationCount > 0)
                {
                    var invocation = random.Next(invocationCount) + 1;

                    IEnumerable <MethodDescriptor> result = null;

                    var stopWatch = Stopwatch.StartNew();
                    if (invocation > 0)
                    {
                        result = await CallGraphQueryInterface.GetCalleesAsync(solutionManager, methodDescriptor, invocation, "");
                    }
                    else
                    {
                        result = await CallGraphQueryInterface.GetCalleesAsync(solutionManager, methodDescriptor);
                    }

                    stopWatch.Stop();
                    if (i >= warmingUpQueries)
                    {
                        var time = stopWatch.ElapsedMilliseconds;
                        times[i - warmingUpQueries] = time;
                        if (time > maxTime)
                        {
                            maxTime = time;
                        }
                        if (time < minTime)
                        {
                            minTime = time;
                        }
                        sumTime += time;
                        var currentTime = DateTime.Now;
                        var results     = new QueriesDetailPerSubject()
                        {
                            ExpID        = this.ExperimentID,
                            Time         = currentTime,
                            Subject      = this.subject,
                            Machines     = machines,
                            QueryNumber  = i - warmingUpQueries,
                            QueryTime    = time,
                            PartitionKey = this.ExperimentID,
                            RowKey       = ExperimentID + "-" + (i - warmingUpQueries) + "-" + currentTime.ToFileTime().ToString()
                        };
                        this.AddIndividualQueryResult(results);
                    }
                }
            }

            if (repetitions > 0)
            {
                var avgTime = sumTime / repetitions;
                var stdDev  = 0D;
                for (var i = 0; i < times.Length; i++)
                {
                    stdDev += (times[i] - avgTime) * (times[i] - avgTime);
                }
                stdDev = Math.Sqrt(stdDev / repetitions);
                var time    = DateTime.Now;
                var results = new QueriesPerSubject()
                {
                    ExpID        = this.ExperimentID,
                    Time         = time,
                    Subject      = this.subject,
                    Machines     = machines,
                    Repeticions  = repetitions,
                    AvgTime      = avgTime,
                    MinTime      = minTime,
                    MaxTime      = maxTime,
                    StdDev       = stdDev,
                    Median       = times[repetitions / 2],
                    Observations = "From web",
                    PartitionKey = this.ExperimentID,
                    RowKey       = time.ToFileTime().ToString()
                };
                this.AddQueryResults(results);
                // SaveTable<QueriesPerSubject>("QueryResults", @"Y:\");

                return(Tuple.Create <long, long, long>(avgTime, minTime, maxTime));
            }

            return(Tuple.Create <long, long, long>(0, 0, 0));
        }
Beispiel #3
0
        public async Task <Tuple <long, long, long> > ComputeRandomQueries(string className, string methodPrejix, int numberOfMethods, int repetitions, string assemblyName = "MyProject", string expId = "DummyExperimentID")
        {
            if (String.IsNullOrEmpty(this.ExperimentID))
            {
                this.ExperimentID = expId;
            }

            var    solutionManager = this.SolutionManager;
            Random random          = new Random();
            long   sumTime         = 0;
            long   maxTime         = 0;
            long   minTime         = long.MaxValue;

            long[] times = new long[repetitions];

            for (int i = 0; i < repetitions; i++)
            {
                int methodNumber     = random.Next(numberOfMethods) + 1;
                var typeDescriptor   = new TypeDescriptor("", className, assemblyName);
                var methodDescriptor = new MethodDescriptor(typeDescriptor, methodPrejix + methodNumber, true);
                var invocationCount  = await CallGraphQueryInterface.GetInvocationCountAsync(solutionManager, methodDescriptor);

                if (invocationCount > 0)
                {
                    var invocation = random.Next(invocationCount) + 1;

                    IEnumerable <MethodDescriptor> result = null;

                    var stopWatch = Stopwatch.StartNew();
                    if (invocation > 0)
                    {
                        result = await CallGraphQueryInterface.GetCalleesAsync(solutionManager, methodDescriptor, invocation, "");
                    }
                    else
                    {
                        result = await CallGraphQueryInterface.GetCalleesAsync(solutionManager, methodDescriptor);
                    }

                    stopWatch.Stop();
                    var time = stopWatch.ElapsedMilliseconds;
                    times[i] = time;
                    if (time > maxTime)
                    {
                        maxTime = time;
                    }
                    if (time < minTime)
                    {
                        minTime = time;
                    }
                    sumTime += time;
                }
            }
            if (repetitions > 0)
            {
                var avgTime = sumTime / repetitions;

                var time    = DateTime.Now;
                var results = new QueriesPerSubject()
                {
                    ExpID        = this.ExperimentID,
                    Time         = time,
                    Subject      = this.subject,
                    Machines     = machines,
                    Repeticions  = repetitions,
                    AvgTime      = avgTime,
                    MinTime      = minTime,
                    MaxTime      = maxTime,
                    Median       = times[repetitions / 2],
                    Observations = "From web",
                    PartitionKey = this.ExperimentID,
                    RowKey       = time.ToFileTime().ToString()
                };
                this.AddQueryResults(results);
                // SaveTable<QueriesPerSubject>("QueryResults", @"Y:\");

                return(Tuple.Create <long, long, long>(avgTime, minTime, maxTime));
            }
            return(Tuple.Create <long, long, long>(0, 0, 0));
        }