Example #1
0
        /// <summary>
        /// Save the third party apps into the according table
        /// </summary>
        private void SaveApps()
        {
            var receiver = new ConsoleOutputReceiver();

            _tableApp.DeleteRow(_device.Serial);
            AdbServer.GetClient().ExecuteRemoteCommand("pm list packages -3", _device, receiver);
            var appList = receiver.ToString().Split("\r\n").ToList();

            for (var i = 0; i < appList.Count - 1; i++)
            {
                _tableApp.InsertValues(appList[i], _device.Serial);
            }
        }
Example #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());
            }
        }
Example #3
0
        /// <summary>
        /// Creates a logcat process and calls saveLogs
        /// Starts a new Thread to log the workload data of the device
        /// </summary>
        private void InitializeProcess()
        {
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = Config.GetAdbPath(),
                    Arguments              = "-s " + _device.Serial + " logcat -v year",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            try
            {
                var receiver = new ConsoleOutputReceiver();

                //Empty the logs before starting to log
                AdbServer.GetClient().ExecuteRemoteCommand("logcat -b all -c", _device, receiver);

                receiver = new ConsoleOutputReceiver();

                //Decide which command to use for accessing the cpu usage by checking the devices build version
                AdbServer.GetClient().ExecuteRemoteCommand("getprop ro.build.version.release", _device, receiver);
                _cpuUsageCommand = Convert.ToInt32(receiver.ToString()) < 9 ? "top -b -n 1" : "top -b -m 5 -n 1";

                //Start the logging and accessing of the workload
                new Thread(() => SaveLogs(proc)).Start();
                AccessWorkload();
            }
            catch (Exception)
            {
                Console.WriteLine("Error while initializing process ... continuing");
            }
        }