Пример #1
0
        /// <summary>
        /// Starts a Stopwatch and gives the device 30 seconds to change its state to online
        /// If the device state changes to online it starts logging
        /// If the device state doesn't change to online it will just execute
        /// </summary>
        /// <param name="obj"> the CancellationToken </param>
        public void CheckDeviceState(object obj)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            _token = (CancellationToken)obj;

            do
            {
                try
                {
                    if (_device.State == DeviceState.Online)
                    {
                        foreach (var d in AdbServer.GetConnectedDevices())
                        {
                            if (d.Serial.Equals(_device.Serial))
                            {
                                watch.Stop();
                                _device = d;
                                if (!_tableDevices.DeviceList().Exists(x => x.Serial.Equals(_device.Serial)))
                                {
                                    _tableDevices.InsertValues(_device.Serial, _device.Name);
                                }
                                new Thread(SaveApps).Start();
                                InitializeProcess();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Device not authorized ... continuing");
                }
            }while (watch.Elapsed.Milliseconds < 30000 && watch.IsRunning);
        }
Пример #2
0
        /// <summary>
        /// Get the CpuUsage, MemoryUsage and the BatteryLevel periodically every 30 seconds and write them into the database --> Resources
        /// Also gets the five most expensive processes and their CPU/mem usage and writes them into the database --> ResIntens
        /// </summary>
        private void AccessWorkload()
        {
            while (!_token.IsCancellationRequested && AdbServer.GetConnectedDevices().Exists(x => x.Serial.Equals(_device.Serial)))
            {
                var receiver = new ConsoleOutputReceiver();

                try
                {
                    //Get the cpu usage and the five most expensive processes
                    AdbServer.GetClient().ExecuteRemoteCommand(_cpuUsageCommand, _device, receiver);
                    var cpu              = GetCpuUsage(receiver.ToString());
                    var fiveProcesses    = GetFiveProcesses(receiver.ToString());
                    var cpuFiveProcesses = GetCpuFiveProcesses(receiver.ToString());
                    var memFiveProcesses = GetMemFiveProcesses(receiver.ToString());

                    //Get the memusage
                    AdbServer.GetClient().ExecuteRemoteCommand("cat /proc/meminfo", _device, receiver);
                    var mem = GetMemUsage(receiver.ToString());

                    //Get the battery level
                    AdbServer.GetClient().ExecuteRemoteCommand("dumpsys battery", _device, receiver);
                    GetBatteryLevel(receiver.ToString());

                    var time = DateTime.Now;

                    //Insert CPU/mem usage and the battery level into Resources
                    _tableResources.InsertValues(_device.Serial, _device.Name, cpu, mem, _batteryLevel, time);

                    //Insert the five most expensive processes into ResIntens
                    for (var i = 0; i < 5; i++)
                    {
                        _tableResIntens.InsertValues(_device.Serial, _device.Name,
                                                     Math.Round((double.Parse(cpuFiveProcesses[i].ToString(), CultureInfo.InvariantCulture) / _cpuTotal) * 100, 2),
                                                     double.Parse(memFiveProcesses[i].ToString(), CultureInfo.InvariantCulture),
                                                     fiveProcesses[i].ToString(), time);
                    }

                    //Invoke the DeviceWorkloadChanged event and wait 30 seconds
                    AdbServer.CustomMonitor.Instance.OnDeviceWorkloadChanged(new DeviceDataEventArgs(_device));
                }
                catch (Exception)
                {
                    Console.WriteLine("Error while fetching data ... continuing");
                }

                Thread.Sleep(Config.GetAccessWorkloadInterval());
            }
        }