async Task StartRecording() { try { _CancellationSource = new CancellationTokenSource(); if(_TrackActivities.Checked) StartRecordingActivities(); var last_resumed = false; for (;;) { var p = new Process(); p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = AdbPath; p.StartInfo.Arguments = string.Format("{1} shell dumpsys meminfo {0}", _PackageText.Text, DeviceSelector); p.Start(); var output = await p.StandardOutput.ReadToEndAsync(); var when = (DateTime.Now - _Start).TotalSeconds; var last = _Categories[0].Samples.Count; var extras = default(string); var items = new List<string>(); if (last_resumed != _Resumed) { items.Add(_Resumed ? "FG" : "BG"); last_resumed = _Resumed; } _Resumed = false; foreach (var a in _Activities) items.Add(a); _Activities.Clear(); if (items.Count > 0) extras = string.Join("\n", items); foreach (var c in _Categories) { var m = c.Regex.Match(output); if (!m.Success) break; var pt = new MemPoint { When = when, Pss = double.Parse(m.Groups[1].Value) / 1000, Dirty = double.Parse(m.Groups[2].Value) / 1000, Extras = c.Name == "TOTAL" ? extras : default(string), }; c.Samples.Add(pt); Console.WriteLine("{0} {1} {2} {3}", c.Name, pt.When, pt.Pss, pt.Dirty); } _NotFoundLabel.Visible = _Categories[0].Samples.Count == last; RefreshData(); await Task.Delay(TimeSpan.FromSeconds((int)_FrequencySpinner.Value), _CancellationSource.Token); } } catch (OperationCanceledException e) { } finally { _PackageText.Enabled = true; _TrackActivities.Enabled = true; _RecordButton.Text = "Record"; _Recording = null; } }
async Task StartRecording() { try { _CancellationSource = new CancellationTokenSource(); if (_TrackActivities.Checked) { StartRecordingActivities(); } var last_resumed = false; for (;;) { var p = new Process(); p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = AdbPath; p.StartInfo.Arguments = string.Format("{1} shell dumpsys meminfo {0}", _PackageText.Text, DeviceSelector); p.Start(); var output = await p.StandardOutput.ReadToEndAsync(); var when = (DateTime.Now - _Start).TotalSeconds; var last = _Categories[0].Samples.Count; var extras = default(string); var items = new List <string>(); if (last_resumed != _Resumed) { items.Add(_Resumed ? "FG" : "BG"); last_resumed = _Resumed; } _Resumed = false; foreach (var a in _Activities) { items.Add(a); } _Activities.Clear(); if (items.Count > 0) { extras = string.Join("\n", items); } foreach (var c in _Categories) { var m = c.Regex.Match(output); if (!m.Success) { break; } var pt = new MemPoint { When = when, Pss = double.Parse(m.Groups[1].Value) / 1000, Dirty = double.Parse(m.Groups[2].Value) / 1000, Extras = c.Name == "TOTAL" ? extras : default(string), }; c.Samples.Add(pt); Console.WriteLine("{0} {1} {2} {3}", c.Name, pt.When, pt.Pss, pt.Dirty); } _NotFoundLabel.Visible = _Categories[0].Samples.Count == last; RefreshData(); await Task.Delay(TimeSpan.FromSeconds((int)_FrequencySpinner.Value), _CancellationSource.Token); } } catch (OperationCanceledException e) { } finally { _PackageText.Enabled = true; _TrackActivities.Enabled = true; _RecordButton.Text = "Record"; _Recording = null; } }