private static JSC.JSValue SetAlarm(JSC.JSValue func, JSC.JSValue time) { var jd = time.Value as JSL.Date; if (jd != null) { return(JsExtLib.SetTimer(func, jd.ToDateTime(), null)); } else { throw new ArgumentException("SetAlarm(, Date)"); } }
private void PrThread() { DateTime now = DateTime.Now, today = now.Date, perfomanceDT = now.AddSeconds(10), gcTick = now.AddSeconds(5); Tuple <bool, DateTime, double> perf_cpu = new Tuple <bool, DateTime, double>(true, now, 0); if (!IsLinux) { int cpuCnt = System.Environment.ProcessorCount; if (cpuCnt > 1) { int r = CSWindowsServiceRecoveryProperty.Win32.SetThreadAffinityMask(CSWindowsServiceRecoveryProperty.Win32.GetCurrentThread(), 1 << (cpuCnt - 1)); } } InitPlugins(); StartPlugins(); _tickTimer = new Timer(Tick, null, 100, 15); // Tick = 1000/64 = 15.625 mS int i; //int j=1920; //TimeSpan t = TimeSpan.Zero; //var sw = new System.Diagnostics.Stopwatch(); //sw.Start(); do { now = DateTime.Now; if (perfomanceDT < now) { perfomanceDT = now.AddSeconds(317); var perf = X13.Repository.Topic.root.Get("/$YS/Perfomance"); if (perf.GetState().ValueType != NiL.JS.Core.JSValueType.Boolean) { perf.SetAttribute(Repository.Topic.Attribute.DB | Repository.Topic.Attribute.Required); perf.SetState(false); } else if ((bool)perf.GetState()) { perf.Get("GC").SetState(Math.Round(GC.GetTotalMemory(false) / 1048576.0, 2)); // MB using (var proc = System.Diagnostics.Process.GetCurrentProcess()) { perf.Get("Memory").SetState(Math.Round(proc.PrivateMemorySize64 / 1048576.0, 2)); // MB perf.Get("Virtual").SetState(Math.Round(proc.VirtualMemorySize64 / 1048576.0, 2)); // MB var cpu = proc.TotalProcessorTime.TotalSeconds; if (perf_cpu.Item1) { perf.Get("CPU").SetState(Math.Round((cpu - perf_cpu.Item3) * 100 / (now - perf_cpu.Item2).TotalSeconds, 2)); // Sec } perf_cpu = new Tuple <bool, DateTime, double>(true, now, cpu); perf.Get("Physical").SetState(Math.Round(proc.WorkingSet64 / 1048576.0, 2)); // MB } perf.Get("Updated").SetState(NiL.JS.Core.JSValue.Marshal(now)); } else { perf_cpu = new Tuple <bool, DateTime, double>(false, now, 0); } } if (_isLinux && gcTick < now) { gcTick = now.AddSeconds(887); GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized); } _tick.WaitOne(); //sw.Stop(); //t+=sw.Elapsed; //if(--j<=0) { // j=1920; // Log.Debug("Tick = {0:0.000} mS", t.TotalMilliseconds/1920); // t = TimeSpan.Zero; //} //sw.Restart(); JsExtLib.Tick(); for (i = 0; i < _modules.Length; i++) { try { _modules[i].Tick(); } catch (Exception ex) { Log.Error("{0}.Tick() - {1}", _modules[i].GetType().FullName, ex.ToString()); } } if (today != now.Date) { today = now.Date; Log.Info("{0} v.{1}", today.ToLongDateString(), Assembly.GetExecutingAssembly().GetName().Version.ToString(4)); } } while(!_terminate); _tickTimer.Change(-1, -1); //sw.Stop(); StopPlugins(); }