MCPcopy Create free account
hub / github.com/Klipper3d/klipper / plot_system

Function plot_system

scripts/graphstats.py:140–182  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

138 return fig
139
140def plot_system(data):
141 # Generate data for plot
142 lasttime = data[0]['#sampletime']
143 lastcputime = float(data[0]['cputime'])
144 times = []
145 sysloads = []
146 cputimes = []
147 memavails = []
148 for d in data:
149 st = d['#sampletime']
150 timedelta = st - lasttime
151 if timedelta <= 0.:
152 continue
153 lasttime = st
154 times.append(datetime.datetime.utcfromtimestamp(st))
155 cputime = float(d['cputime'])
156 cpudelta = max(0., min(1.5, (cputime - lastcputime) / timedelta))
157 lastcputime = cputime
158 cputimes.append(cpudelta * 100.)
159 sysloads.append(float(d['sysload']) * 100.)
160 memavails.append(float(d['memavail']))
161
162 # Build plot
163 fig, ax1 = matplotlib.pyplot.subplots()
164 ax1.set_title("System load utilization")
165 ax1.set_xlabel('Time')
166 ax1.set_ylabel('Load (% of a core)')
167 ax1.plot_date(times, sysloads, '-', label='system load',
168 color='cyan', alpha=0.8)
169 ax1.plot_date(times, cputimes, '-', label='process time',
170 color='red', alpha=0.8)
171 ax2 = ax1.twinx()
172 ax2.set_ylabel('Available memory (KB)')
173 ax2.plot_date(times, memavails, '-', label='system memory',
174 color='yellow', alpha=0.3)
175 fontP = matplotlib.font_manager.FontProperties()
176 fontP.set_size('x-small')
177 ax1li, ax1la = ax1.get_legend_handles_labels()
178 ax2li, ax2la = ax2.get_legend_handles_labels()
179 ax1.legend(ax1li + ax2li, ax1la + ax2la, loc='best', prop=fontP)
180 ax1.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M'))
181 ax1.grid(True)
182 return fig
183
184def plot_mcu_frequencies(data):
185 all_keys = {}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected