@@ -20,14 +20,10 @@ public class Monitor.ProcessDRM {
2020 // Xe driver related fields
2121 private uint64 cycles_rcs = 0 ;
2222 private uint64 cycles_rcs_total = 0 ;
23- private uint64 cycles_bcs = 0 ;
24- private uint64 cycles_bcs_total = 0 ;
25- private uint64 cycles_vcs = 0 ;
26- private uint64 cycles_vcs_total = 0 ;
23+
2724 private uint64 cycles_ccs = 0 ;
2825 private uint64 cycles_ccs_total = 0 ;
29- private uint64 cycles_vecs = 0 ;
30- private uint64 cycles_vecs_total = 0 ;
26+
3127
3228 private uint64 delta_rcs = 0 ;
3329 private uint64 delta_total_rcs = 0 ;
@@ -101,10 +97,8 @@ public class Monitor.ProcessDRM {
10197
10298 foreach (var drm_file in drm_files) {
10399 try {
104- debug (" Reading fdinfo from: %s " , drm_file. get_path ());
105100 var dis = new DataInputStream (drm_file. read ());
106101 string ? line;
107-
108102 while ((line = dis. read_line ()) != null ) {
109103 parse_drm_line (line);
110104 }
@@ -118,14 +112,13 @@ public class Monitor.ProcessDRM {
118112
119113 switch (driver) {
120114 case " i915" :
121- update_engine (ref engine_render, ref last_engine_render);
115+ calculate_percentage_ns (ref engine_render, ref last_engine_render);
122116 break ;
123117 case " xe" :
124- var pre = (float ) delta_rcs / (float ) delta_total_rcs;
125- gpu_percentage = delta_total_rcs > 0 ? 100 * (pre. clamp (0.0f , 1.0f )) : 0 ;
118+ calculate_percentage_cycles (ref delta_rcs, ref delta_total_rcs);
126119 break ;
127120 case " amdgpu" :
128- update_engine (ref engine_gfx, ref last_engine_gfx);
121+ calculate_percentage_ns (ref engine_gfx, ref last_engine_gfx);
129122 break ;
130123 default:
131124 // Handle default case
@@ -134,25 +127,26 @@ public class Monitor.ProcessDRM {
134127
135128 }
136129
137- private void update_engine (ref uint64 engine , ref uint64 last_engine ) {
130+ private void calculate_percentage_ns (ref uint64 engine , ref uint64 last_engine ) {
138131 if (last_engine != 0 ) {
139- gpu_percentage = calculate_percentage (engine, last_engine, update_interval);
132+ // Since values in the files are in nanoseconds, it is also needed to convert interval to nanoseconds (10^9)
133+ gpu_percentage = 100 * ((double ) (engine - last_engine)) / (update_interval * 1e9 );
140134 }
141135 last_engine = engine;
142136 }
143137
138+ private void calculate_percentage_cycles (ref uint64 delta , ref uint64 delta_total ) {
139+ var pre = (float ) delta / (float ) delta_total;
140+ gpu_percentage = delta_total > 0 ? 100 * (pre. clamp (0.0f , 1.0f )) : 0 ;
141+ }
142+
144143 private void update_cycles (string line , ref uint64 last_cycles , ref uint64 delta ) {
145144 var cycles = uint64 . parse (line. strip (). split (" " )[0 ]);
146145 delta = cycles > last_cycles ? cycles - last_cycles : 0 ;
147146 // debug ("pid %d Cycles: %llu, Last Cycles: %llu, Delta: %llu", pid, cycles, last_cycles, delta);
148147 last_cycles = cycles;
149148 }
150149
151- private static double calculate_percentage (uint64 engine , uint64 last_engine , int interval ) {
152- // Since values in the files are in nanoseconds, it is also needed to convert interval to nanoseconds (10^9)
153- return 100 * ((double ) (engine - last_engine)) / (interval * 1e9 );
154- }
155-
156150 // Based on nvtop
157151 // https://github.com/Syllo/nvtop/blob/4bf5db248d7aa7528f3a1ab7c94f504dff6834e4/src/extract_processinfo_fdinfo.c#L88
158152 private static bool is_drm_fd (int fd_dir_fd , string name ) {
0 commit comments