Beispiel #1
0
 public ITimer TimerStart(uint delay, Time.TimerDelegate handler, bool periodic)
 {
     return
         (this.isArm ?
          new Standard.Timer(delay, handler, periodic) : // TimeSet/KillEvent API unavailable on ARM
          new Timer(delay, handler, periodic));
 }
Beispiel #2
0
                public Timer(uint delay, Time.TimerDelegate handler, bool periodic)
                {
                    uint ignore    = 0;
                    uint eventType = (uint)(periodic ? 1 : 0);

                    // TIME_KILL_SYNCHRONOUS flag prevents timer event from occurring after timeKillEvent is called
                    eventType |= 0x100;

                    this.id = NativeMethods.TimeSetEvent(delay, 0, handler, ref ignore, eventType);
                }
Beispiel #3
0
 /// <inheritdoc />
 public void Start(Action <DateTime> notifyCompletionTime)
 {
     // notify that this is an infinite source component
     notifyCompletionTime(DateTime.MaxValue);
     if (this.collector != null)
     {
         this.timerDelegate = new Time.TimerDelegate((i, m, c, d1, d2) => this.Update());
         this.timer         = Platform.Specific.TimerStart((uint)this.Config.SamplingInterval.TotalMilliseconds, this.timerDelegate);
         this.running       = true;
     }
 }
Beispiel #4
0
        /// <inheritdoc/>
        public void Start(Action <DateTime> notifyCompletionTime)
        {
            this.notifyCompletionTime = notifyCompletionTime;

            this.startTime = this.pipeline.StartTime;
            this.endTime   = this.pipeline.ReplayDescriptor.End;
            uint realTimeInterval = (uint)this.pipeline.ConvertToRealTime(this.timerInterval).TotalMilliseconds;

            this.timerDelegate = new Time.TimerDelegate(this.PublishTime);
            this.timer         = Platform.Specific.TimerStart(realTimeInterval, this.timerDelegate);
            this.running       = true;
        }
Beispiel #5
0
 public Timer(uint delay, Time.TimerDelegate handler, bool periodic)
 {
     this.timer           = new System.Timers.Timer(delay);
     this.timer.AutoReset = periodic;
     this.timer.Elapsed  += (sender, args) =>
     {
         lock (this.timer)
         {
             handler(0, 0, UIntPtr.Zero, UIntPtr.Zero, UIntPtr.Zero);
         }
     };
     this.timer.Start();
 }
Beispiel #6
0
 public Timer(uint delay, Time.TimerDelegate handler, bool periodic)
 {
     this.timer           = new System.Timers.Timer(delay);
     this.timer.AutoReset = periodic;
     this.timer.Elapsed  += (sender, args) =>
     {
         lock (this.timerDelegateLock)
         {
             // prevents handler from being called if timer has been stopped
             if (this.timer != null)
             {
                 handler(0, 0, UIntPtr.Zero, UIntPtr.Zero, UIntPtr.Zero);
             }
         }
     };
     this.timer.Start();
 }
Beispiel #7
0
        // [TestMethod, Timeout(60000)]
        public void TimerPerfTest()
        {
            uint timerInterval = 1;
            var  currentTime   = DateTime.Now;
            var  timerDelegate = new Time.TimerDelegate(
                (timerID, msg, userCtx, dw1, dw2) =>
            {
                currentTime = Time.GetCurrentTime();

                // currentTime += TimeSpan.FromMilliseconds(timerInterval);
            });
            var timer = Platform.Specific.TimerStart(timerInterval, timerDelegate);

            Console.ReadLine();
            timer.Stop();
            var lastTime = DateTime.Now;

            Console.WriteLine($"Current = {currentTime:H:mm:ss fff}, last = {lastTime:H:mm:ss fff}");
        }
Beispiel #8
0
        /// <summary>
        /// Starts the timer. Called by the runtime when the pipeline starts.
        /// </summary>
        private void OnPipelineStart()
        {
            var replay = this.pipeline.ReplayDescriptor;

            if (replay.Start == DateTime.MinValue)
            {
                this.startTime = this.pipeline.GetCurrentTime();
            }
            else
            {
                this.startTime = replay.Start;
            }

            this.endTime     = replay.End;
            this.currentTime = this.startTime;
            uint realTimeInterval = (uint)this.pipeline.ConvertToRealTime(this.timerInterval).TotalMilliseconds;

            this.timerDelegate = new Time.TimerDelegate(this.PublishTime);
            this.timer         = Platform.Specific.TimerStart(realTimeInterval, this.timerDelegate);
            this.running       = true;
        }
Beispiel #9
0
        // DataFlow baseline. Similar CPU & throughput results, but memory keeps growing.
        public void RunDataFlowPipeline <T>(Func <int, T> create, Func <int, T, T> initialize, Func <T, T, T> increment, Func <T, T, T, T> add, Func <T, int> extract, bool validateNoLoss, bool validateSync)
        {
            int resultCount = 0;
            var dfo         = new DataflowLinkOptions();

            dfo.Append = true;
            List <object> saved = new List <object>();

            // create several parallel branches of components
            var branches = new ISourceBlock <Wrap <T> > [ParallelBranchCount];
            var sources  = new Time.TimerDelegate[SourceCount];

            for (int i = 0; i < SourceCount; i++)
            {
                // make a timer for each source
                var timerSeqId = 0;
                var timer      = new TransformBlock <int, int>(ts => timerSeqId++);
                sources[i] = new Time.TimerDelegate((uint timerID, uint msg, UIntPtr userCtx, UIntPtr dw1, UIntPtr dw2) => timer.Post(i));
                saved.Add(timer);

                // branch and generate data
                for (int k = 0; k < ParallelBranchMultiplier; k++)
                {
                    int b        = (i * ParallelBranchMultiplier) + k;
                    var initInst = new Wrap <T>(create(b), 0);
                    var init     = new TransformBlock <int, Wrap <T> >(seqId => initInst = new Wrap <T>(initialize(seqId, initInst.Inner), seqId).DeepClone());
                    timer.LinkTo(init, dfo);
                    branches[b] = init;
                    saved.Add(init);

                    // apply a sequence of transforms
                    for (int j = 0; j < TransformCount; j++)
                    {
                        var incInst = new Wrap <T>(create(b), 0);
                        var inc     = new TransformBlock <Wrap <T>, Wrap <T> >(src => incInst = new Wrap <T>(increment(incInst.Inner, src.Inner), src.ExpectedResult + 1).DeepClone());
                        branches[b].LinkTo(inc, dfo);
                        branches[b] = inc;
                        saved.Add(inc);
                    }

                    // make sure we didn't lose messages
                    // branches[b] = branches[b].DoT(m => CheckMessageId(m.SequenceId + TransformCount, m.Data.ExpectedResult, validateNoLoss), true, true);
                }
            }

            // join all
            var fullJoin = branches[0];

            for (int i = 1; i < ParallelBranchCount; i++)
            {
                var joinGo = new GroupingDataflowBlockOptions();
                joinGo.Greedy = false;
                var join = new JoinBlock <Wrap <T>, Wrap <T> >(joinGo);
                fullJoin.LinkTo(join.Target1, dfo);
                branches[i].LinkTo(join.Target2, dfo);
                var addInst = new Wrap <T>(create(i), 0);
                var select  = new TransformBlock <Tuple <Wrap <T>, Wrap <T> >, Wrap <T> >(tpl => addInst = new Wrap <T>(add(addInst.Inner, tpl.Item1.Inner, tpl.Item2.Inner), tpl.Item1.ExpectedResult + tpl.Item2.ExpectedResult).DeepClone());
                join.LinkTo(select, dfo);
                fullJoin = select;
                saved.Add(join);
                saved.Add(select);
            }

            // extract final result
            var result = new TransformBlock <Wrap <T>, Wrap <long> >(w => new Wrap <long>(extract(w.Inner), w.ExpectedResult));

            fullJoin.LinkTo(result, dfo);
            saved.Add(result);

            // validate result
            int actionSeqId = 0;
            var final       = new ActionBlock <Wrap <long> >(w =>
            {
                resultCount++;
                this.CheckMessageId(++actionSeqId, resultCount, validateNoLoss);
                if (w.Inner != w.ExpectedResult)
                {
                    throw new Exception("Unexpected computation result.");
                }
            });

            result.LinkTo(final, dfo);
            saved.Add(final);

            // run the pipeline
            for (int i = 0; i < SourceCount; i++)
            {
                Platform.Specific.TimerStart(1000 / this.frequency, sources[i]);
            }

            while (!final.Completion.Wait(1000))
            {
                Console.WriteLine(resultCount);
                if (sources.Length == 0)
                {
                    throw new Exception("This was here just to keep source alive in release mode, why did it hit?");
                }
            }

            Console.WriteLine("Stopped");
            Assert.AreNotEqual(0, resultCount);
        }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Timer"/> class.
 /// The timer fires off messages at the rate specified  by timerInterval.
 /// </summary>
 /// <param name="pipeline">The pipeline this component will be part of</param>
 /// <param name="timerInterval">The timer firing interval, in ms.</param>
 public Timer(Pipeline pipeline, uint timerInterval)
 {
     this.pipeline      = pipeline;
     this.timerInterval = TimeSpan.FromMilliseconds(timerInterval);
     this.timerDelegate = new Time.TimerDelegate(this.PublishTime);
 }
Beispiel #11
0
 internal static ITimer TimerStart(uint delay, Time.TimerDelegate handler, bool periodic = true)
 {
     return(PlatformHighResolutionTime.TimerStart(delay, handler, periodic));
 }
Beispiel #12
0
 public ITimer TimerStart(uint delay, Time.TimerDelegate handler, bool periodic)
 {
     return(new Timer(delay, handler, periodic));
 }
Beispiel #13
0
 internal static extern uint TimeSetEvent(uint delay, uint resolution, Time.TimerDelegate handler, ref uint userCtx, uint eventType);
Beispiel #14
0
                public Timer(uint delay, Time.TimerDelegate handler, bool periodic)
                {
                    uint ignore = 0;

                    this.id = TimeSetEvent(delay, 0, handler, ref ignore, (uint)(periodic ? 1 : 0));
                }