File: NvidiaInfo.cs

package info (click to toggle)
sysinfo 0.7-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,832 kB
  • ctags: 1,140
  • sloc: cs: 2,933; sh: 701; makefile: 115; xml: 98
file content (178 lines) | stat: -rw-r--r-- 4,390 bytes parent folder | download | duplicates (2)
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
170
171
172
173
174
175
176
177
178
// Filename: NvidiaInfo.cs
// Contains functions to extract information displayed in NVIDIA category

using System;
using System.IO;
using System.Diagnostics;

namespace Sysinfo {
	
	public class NvidiaInfo {
		
		public Boolean nvidiaB = false;
		public Boolean nvidiaSettings = false;
		
		public String nvidia_model = "unknown";
		public String nvidia_ctype = "unknown";
		
		public String nvidia_version = "unknown";
		
		public String nvidia_videoram = "unknown";
		public String nvidia_busrate = "";
		public String nvidia_gpu = "unknown";
		
		//check for nvidia driver
		public NvidiaInfo() {
			
			if ( Directory.Exists("/proc/driver/nvidia/") )
				nvidiaB = true;
		}

                 //check nvidia-settings is installed
		public void NvidiaSettingsInstalled() {

			if ( System.IO.File.Exists("/usr/bin/nvidia-settings") )
				nvidiaSettings = true;
		}
		
		//read some basic info
		public void MainInfo(){
			
			String temp;
			
			try {
					
				using (TextReader textread = File.OpenText("/proc/driver/nvidia/cards/0")) {
						
					while ( textread.Peek() != (-1)  ) {
							
						temp = textread.ReadLine();
						
						if ( temp.StartsWith("Model:") ) {
							
							temp = temp.Remove(0, 10);
							
							nvidia_model = temp;
						}
						
						if ( temp.StartsWith("Card Type:") ) {
							
							temp = temp.Remove(0, 13);
							
							nvidia_ctype = temp;
						}
						
					}
				}
			}
			catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
			catch (DirectoryNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read driver version
		public void Version() {
			
			String temp;
			
			try {
				
				using (TextReader textread = File.OpenText("/proc/driver/nvidia/version")) {
							
					while ( textread.Peek() != (-1)  ) {
								
						temp = textread.ReadLine();
							
						if ( temp.StartsWith("NVRM version:") ) {
								
							temp = temp.Remove(0, 14);
								
							nvidia_version = temp;
						}
					}
				}
			}
			catch (FileNotFoundException ex) {  Console.WriteLine( ex );  }
			catch (DirectoryNotFoundException ex) {  Console.WriteLine( ex );  }
		}
		
		//read extra info using nvidia-settings
		public void AditionaInfo() {
			
			String temp;
			
			try {
				NvidiaSettingsInstalled();

				if (nvidiaSettings) {
				
				//run command and read output: nvidia-settings --query
				//video ram
				Process proc1 = new Process();
				proc1.StartInfo.FileName = "nvidia-settings";
				proc1.StartInfo.Arguments = "-q VideoRam";
				proc1.StartInfo.UseShellExecute = false;
				proc1.StartInfo.RedirectStandardOutput = true;
				proc1.Start();
				proc1.WaitForExit(); 
				
				temp = proc1.StandardOutput.ReadLine();
				temp = proc1.StandardOutput.ReadLine();
	

				if (temp != null) {
				    temp = temp.Remove(0, temp.LastIndexOf(":") + 2);
				    nvidia_videoram = ( Double.Parse(temp) / 1024 ).ToString() + " MB";
				}
				
				proc1.Close();
				
				//bus rate
				Process proc2 = new Process();
				proc2.StartInfo.FileName = "nvidia-settings";
				proc2.StartInfo.Arguments = "-q BusRate";
				proc2.StartInfo.UseShellExecute = false;
				proc2.StartInfo.RedirectStandardOutput = true;
				proc2.Start();
				proc2.WaitForExit(); 
				
				temp = proc2.StandardOutput.ReadLine();
				temp = proc2.StandardOutput.ReadLine();
	
				if (temp != null) {
				    temp = temp.Remove(0, temp.LastIndexOf(":") + 2);
 				    nvidia_busrate = temp.Remove(temp.LastIndexOf("."), 1) + "x";
 				}
				
				proc2.Close();
				
				//gpu frequency
				Process proc3 = new Process();
				proc3.StartInfo.FileName = "nvidia-settings";
				proc3.StartInfo.Arguments = "-q GPUCurrentClockFreqs";
				proc3.StartInfo.UseShellExecute = false;
				proc3.StartInfo.RedirectStandardOutput = true;
				proc3.Start();
				proc3.WaitForExit(); 
				
				temp = proc3.StandardOutput.ReadLine();
				temp = proc3.StandardOutput.ReadLine();

				if (temp != null) {
				    temp = temp.Remove(0, temp.LastIndexOf(":") + 2);
				    nvidia_gpu = temp.Remove(temp.LastIndexOf(","), 5) + " MHz";
				}
				
				proc3.Close();

				} // end of nvidiaSettings test
			}
			catch (System.ComponentModel.Win32Exception ex) {  Console.WriteLine( ex );  }
			catch (ArgumentOutOfRangeException ex) {  Console.WriteLine( ex );  }
			catch (FormatException ex) {  Console.WriteLine( ex );  }
			
		}
		
	}
}

//ghaefb