This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathIPerformanceMonitor.cs
More file actions
169 lines (142 loc) · 5.56 KB
/
IPerformanceMonitor.cs
File metadata and controls
169 lines (142 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable enable
using System;
using System.Diagnostics;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.Quantum.IQSharp
{
/// <summary>
/// Represents details about the performance of a simulator used from
/// the IQ# kernel.
/// </summary>
public class SimulatorPerformanceArgs : EventArgs
{
public SimulatorPerformanceArgs(string simulatorName, int nQubits, TimeSpan duration)
{
this.SimulatorName = simulatorName;
this.NQubits = nQubits;
this.Duration = duration;
}
/// <summary>
/// The fully-qualified name of the simulator whose performance
/// is described by these event arguments.
/// </summary>
public string SimulatorName { get; }
/// <summary>
/// The maximum number of qubits simulated by the simulator whose
/// performance is described by these event arguments.
/// </summary>
public int NQubits { get; }
/// <summary>
/// The total time that the simulator whose performance
/// is described by these event arguments ran for.
/// </summary>
public TimeSpan Duration { get; }
}
/// <summary>
/// Represents details about the performance of the IQ# kernel process
/// itself.
/// </summary>
public class KernelPerformanceArgs : EventArgs
{
public KernelPerformanceArgs(long managedRamUsed, long totalRamUsed)
{
this.ManagedRamUsed = managedRamUsed;
this.TotalRamUsed = totalRamUsed;
}
/// <summary>
/// The approximate amount of RAM (in bytes) used by managed code
/// in the kernel process.
/// </summary>
public long ManagedRamUsed { get; }
/// <summary>
/// The approximate amount of RAM (in bytes) used by all code in
/// the IQ# kernel process.
/// </summary>
public long TotalRamUsed { get; }
}
public class TaskPerformanceArgs : EventArgs
{
public TaskPerformanceArgs(ITaskReporter task, string statusDescription, string statusId, TimeSpan timeSinceTaskStart)
{
this.Task = task;
this.StatusDescription = statusDescription;
this.StatusId = statusId;
this.TimeSinceTaskStart = timeSinceTaskStart;
}
public ITaskReporter Task { get; }
public string StatusDescription { get; }
public string StatusId { get; }
public TimeSpan TimeSinceTaskStart { get; }
public override string ToString() =>
$"[T+{TimeSinceTaskStart.TotalMilliseconds}ms] {Task.Description}: {StatusDescription}";
}
public class TaskCompleteArgs : EventArgs
{
public TaskCompleteArgs(ITaskReporter task, TimeSpan timeSinceTaskStart)
{
this.Task = task;
this.TimeSinceTaskStart = timeSinceTaskStart;
}
public ITaskReporter Task { get; }
public TimeSpan TimeSinceTaskStart { get; }
public override string ToString() =>
$"[T+{TimeSinceTaskStart.TotalMilliseconds}ms] {Task.Description} complete.";
}
/// <summary>
/// An object that can be used to report progress through a given task.
/// The task is considered complete when this object is disposed.
/// </summary>
public interface ITaskReporter : IDisposable
{
public ITaskReporter? Parent { get; }
public string Description { get; }
public string Id { get; }
public TimeSpan TimeSinceStart { get; }
public TimeSpan TotalTimeSinceStart { get; }
public void ReportStatus(string description, string id);
public ITaskReporter BeginSubtask(string description, string id);
public int Depth =>
Parent == null
? 0
: 1 + Parent.Depth;
}
/// <summary>
/// A service for reporting kernel performance, and collecting
/// performance reports from other kernel services.
/// </summary>
public interface IPerformanceMonitor
{
/// <summary>
/// Forces a report of current kernel performance data to be
/// emitted.
/// </summary>
public void Report();
public bool EnableBackgroundReporting { get; set; }
/// <summary>
/// Raised when a simulator reports information about its
/// performance.
/// </summary>
public event EventHandler<SimulatorPerformanceArgs>? OnSimulatorPerformanceAvailable;
/// <summary>
/// Raised when information about kernel performance (e.g. RAM
/// usage) is available.
/// </summary>
public event EventHandler<KernelPerformanceArgs>? OnKernelPerformanceAvailable;
public event EventHandler<TaskPerformanceArgs>? OnTaskPerformanceAvailable;
public event EventHandler<TaskCompleteArgs>? OnTaskCompleteAvailable;
/// <summary>
/// Begins performance monitoring. Does nothing if performance
/// monitoring has already been started.
/// </summary>
public void Start();
/// <summary>
/// Returns an object that can be used to report progress through
/// a given task.
/// </summary>
public ITaskReporter BeginTask(string description, string id);
}
}