コード例 #1
0
ファイル: Config.cs プロジェクト: jsx15/AndroidDataRecorder
 /// <summary>
 /// Connect to already known devices
 /// </summary>
 private static void ConnectKnownDevices()
 {
     for (int i = 0; i < _source.KnownDevices.Count - 1; i++)
     {
         AdbServer.ConnectWirelessClient(_source.KnownDevices[i]);
     }
 }
コード例 #2
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);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: jsx15/AndroidDataRecorder
 /// <summary>
 /// Checks if the path to adb.exe is correct
 /// </summary>
 /// <returns> true if yes and false if not </returns>
 private static bool ValidateAdbPath()
 {
     try
     {
         if (_source != null)
         {
             AdbServer.InitializeAdbServer(_source.AdbPath);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #5
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());
            }
        }
コード例 #6
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");
            }
        }