Add CPU/GPU frequency in Full overlay

This commit is contained in:
Kamil Trzciński 2022-11-20 18:10:05 +01:00
parent ed7180a116
commit b9d871f6ec
3 changed files with 89 additions and 8 deletions

View file

@ -170,19 +170,31 @@ namespace PerformanceOverlay
Nested = {
new Entry("<A5>{CPU_%}<A><A1><S1> %<S><A>"),
new Entry("<A5>{CPU_W}<A><A1><S1> W<S>"),
new Entry("<A5>{MEM_MB}<A><A1><S1> MB<S>"),
new Entry("<A5>{CPU_T}<A><A1><S1> C<S><A>") { IgnoreMissing = true },
}
},
new Entry("\t ")
{
Nested = {
new Entry("<A5>{MEM_MB}<A><A1><S1> MB<S>"),
new Entry("<A5>{CPU_MHZ}<A><A1><S1> MHz<S><A>")
}
},
new Entry("<C1>GPU<C>\t ")
{
Nested = {
new Entry("<A5>{GPU_%}<A><A1><S1> %<S><A>"),
new Entry("<A5>{GPU_W}<A><A1><S1> W<S><A>"),
new Entry("<A5>{GPU_MB}<A><A1><S1> MB<S><A>"),
new Entry("<A5>{GPU_T}<A><A1><S1> C<S><A>") { IgnoreMissing = true },
}
},
new Entry("\t ")
{
Nested = {
new Entry("<A5>{GPU_MB}<A><A1><S1> MB<S><A>"),
new Entry("<A5>{GPU_MHZ}<A><A1><S1> MHz<S><A>") { IgnoreMissing = true }
}
},
new Entry("<C1>FAN<C>\t ")
{
Nested = {

View file

@ -25,13 +25,15 @@ namespace PerformanceOverlay
public float Multiplier { get; set; } = 1.0f;
public bool IgnoreZero { get; set; }
protected string? ConvertToString(float value)
protected string? ConvertToString(float? value)
{
if (value is null)
return null;
if (value == 0 && IgnoreZero)
return null;
value *= Multiplier;
return value.ToString(Format, CultureInfo.GetCultureInfo("en-US"));
return value.Value.ToString(Format, CultureInfo.GetCultureInfo("en-US"));
}
}
@ -84,18 +86,56 @@ namespace PerformanceOverlay
}
}
public class CompositeSensor : Sensor
public class CompositeSensor : ValueSensor
{
public IList<Sensor> Sensors { get; set; } = new List<Sensor>();
public enum AggregateType
{
First,
Min,
Max,
Avg
};
public override string? GetValue(Sensors sensors)
public IList<Sensor> Sensors { get; set; } = new List<Sensor>();
public AggregateType Aggregate { get; set; } = AggregateType.First;
public String? Format { get; set; }
private IEnumerable<string> GetValues(Sensors sensors)
{
foreach (var sensor in Sensors)
{
var result = sensor.GetValue(sensors);
if (result is not null)
return result;
yield return result;
}
}
private IEnumerable<float> GetNumericValues(Sensors sensors)
{
return GetValues(sensors).Select((value) => float.Parse(value));
}
public override string? GetValue(Sensors sensors)
{
if (Aggregate == AggregateType.First)
return GetValues(sensors).FirstOrDefault();
var numbers = GetNumericValues(sensors);
if (numbers.Count() == 0)
return null;
switch (Aggregate)
{
case AggregateType.Min:
return ConvertToString(numbers.Min());
case AggregateType.Max:
return ConvertToString(numbers.Max());
case AggregateType.Avg:
return ConvertToString(numbers.Average());
}
return null;
}
}
@ -133,6 +173,24 @@ namespace PerformanceOverlay
IgnoreZero = true
}
},
{
"CPU_MHZ", new CompositeSensor()
{
Format = "F0",
Aggregate = CompositeSensor.AggregateType.Max,
Sensors = Enumerable.Range(1, 4).Select((index) => {
return new HardwareSensor()
{
HardwareType = HardwareType.Cpu,
HardwareName = "AMD Custom APU 0405",
SensorType = SensorType.Clock,
SensorName = "Core #" + index.ToString(),
Format = "F0",
IgnoreZero = true
};
}).ToList<Sensor>()
}
},
{
"MEM_GB", new HardwareSensor()
{
@ -195,6 +253,16 @@ namespace PerformanceOverlay
Format = "F1"
}
},
{
"GPU_MHZ", new HardwareSensor()
{
HardwareType = HardwareType.GpuAmd,
HardwareName = "AMD Custom GPU 0405",
SensorType = SensorType.Clock,
SensorName = "GPU Core",
Format = "F0"
}
},
{
"GPU_T", new HardwareSensor()
{

View file

@ -7,5 +7,6 @@
- Allow to disable SMT (second threads of each physical cores)
- Show Full OSD if in PowerControl mode
- Highly risky: Allow to change CPU and GPU frequency (enable `EnableExperimentalFeatures` in `PowerControl.dll.config`)
- Show CPU/GPU frequency in Full overlay
If you found it useful buy me [Ko-fi](https://ko-fi.com/ayufan).