Skip to content

Commit

Permalink
new features - dark/light mode and option to show window
Browse files Browse the repository at this point in the history
- added "-d" to choose between dark/light mode
- added "-s" to turn on a preview window for the graph
  • Loading branch information
Gummientchen committed May 20, 2024
1 parent bf99300 commit bfce33c
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions presentmon-graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@
parser.add_argument("-o", "--Output", help = "Output File Path (.png). Default generated by log.")
parser.add_argument("-t", "--Title", help = "Graph title shown at the top of generated image.")
parser.add_argument("-b", "--Bins", help = "How many bins should be used for histograms. Default 20", default=20, type=int)
parser.add_argument("-d", "--Theme", help = "Switch between light and dark mode. Default 'dark'", choices=['dark', 'light'], default="dark")
parser.add_argument("-s", "--ShowWindow", help = "Enable a window whichs shows the generated graph on screen.", action='store_true')
args = parser.parse_args()

if args.Input:
inputFilename = args.Input

n_bins = args.Bins

# Colors
color = {}

if args.Theme and args.Theme == "light":
# light colors
color['background'] = '#FFF'
color['backgroundLegend'] = '#FFF'
color['text'] = '#000'
color['lines'] = '#000'
color['lightplot'] = '#000'
else:
# dark colors
color['background'] = '#0d1324'
color['backgroundLegend'] = '#252e47'
color['text'] = '#dbebf7'
color['lines'] = '#89b8ef'
color['lightplot'] = '#c3d4e2'


def main():
print("loading input file...")
Expand All @@ -43,16 +63,28 @@ def main():
print("generating graphs...")
fig = plt.figure(tight_layout=True)

fig.patch.set_facecolor(color["background"])



fig.set_size_inches(420/25.4, 320/25.4)

# Set colors
plt.rcParams['axes.facecolor'] = color['background']
plt.rcParams['text.color'] = color['text']
plt.rcParams['axes.labelcolor'] = color['text']
plt.rcParams['xtick.color'] = color['lines']
plt.rcParams['ytick.color'] = color['lines']
plt.rcParams['lines.color'] = color['lines']
plt.rcParams['axes.edgecolor'] = color['lines']
plt.rcParams['legend.facecolor'] = color['backgroundLegend']

# Set title
if args.Title:
fig.suptitle(args.Title)
else:
fig.suptitle("PresentMon - "+applicationName+" - PID:"+str(processId), fontsize=16)



fig.canvas.manager.set_window_title('PresentMon - Results')

gs = fig.add_gridspec(5,2, height_ratios=[1.5, 1, 1, 0.5, 0.5])
Expand Down Expand Up @@ -84,13 +116,6 @@ def main():
axsCPUBusyHistogram.hist(logs["GPUBusy"], bins=n_bins, rwidth=0.9, label="GPUBusy", alpha=0.75, log=True)
axsCPUBusyHistogram.legend(loc='upper right')

# axsGPUBusyHistogram = fig.add_subplot(gs[2, 0])
# axsGPUBusyHistogram.set_title("GPUBusy Histogram")
# axsGPUBusyHistogram.set_xlabel("ms")
# axsGPUBusyHistogram.set_ylabel("frames")
# axsGPUBusyHistogram.hist(logs["GPUBusy"], bins=n_bins, rwidth=0.9)
# axsGPUBusyHistogram.sharex(axsCPUBusyHistogram)

axsFrametimeHistogram = fig.add_subplot(gs[1, 1])
axsFrametimeHistogram.set_title("FrameTime Histogram")
axsFrametimeHistogram.set_xlabel("ms")
Expand All @@ -101,16 +126,16 @@ def main():
axsClickToPhoton.set_title("Click-to-Photon Latency")
axsClickToPhoton.set_xlabel("frames")
axsClickToPhoton.set_ylabel("ms")
axsClickToPhoton.plot(logs["ClickToPhotonLatency"], "+")
axsClickToPhoton.plot(logs["ClickToPhotonLatency"], "+", color=color['lightplot'])

axsClickToPhoton = fig.add_subplot(gs[3, :])
axsClickToPhoton.set_title("GPUPower/GPUTemperature")
axsClickToPhoton.set_xlabel("frames")
axsClickToPhoton.set_ylabel("Watt")
axsClickToPhoton.plot(logs["GPUPower"], linewidth=1, color="orange", label="Power")
axsClickToPhoton.legend(loc='upper left')
axsGPUPower = fig.add_subplot(gs[3, :])
axsGPUPower.set_title("GPUPower/GPUTemperature")
axsGPUPower.set_xlabel("frames")
axsGPUPower.set_ylabel("Watt")
axsGPUPower.plot(logs["GPUPower"], linewidth=1, color="orange", label="Power")
axsGPUPower.legend(loc='upper left')

tempaxs = axsClickToPhoton.twinx()
tempaxs = axsGPUPower.twinx()
tempaxs.set_ylabel("°C")
tempaxs.plot(logs["GPUTemperature"], linewidth=1, color="red", label="Temperature")
tempaxs.legend(loc='upper right')
Expand All @@ -122,20 +147,19 @@ def main():
axsCpuUtilization.set_ylabel("%")
axsCpuUtilization.plot(logs["CPUUtilization"], linewidth=1, label="CPU")
axsCpuUtilization.plot(logs["GPUUtilization"], linewidth=1, label="GPU")
# axsCpuUtilization.legend(loc='upper center', bbox_to_anchor=(1, 2))
axsCpuUtilization.legend(loc='upper right')

# add some basic data
# fig.figte

print("saving graphs...")
plt.savefig(outputFilename)

# plt.show()

# print(logs.columns)

print("All Done!")

# Show windows if enabled
if args.ShowWindow:
plt.show()



def movingaverage(interval, window_size):
window = np.ones(int(window_size))/float(window_size)
Expand Down

0 comments on commit bfce33c

Please sign in to comment.