NCBI C++ ToolKit
dump_sysinfo.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: dump_sysinfo.cpp 47294 2022-12-23 02:44:35Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Mike DiCuccio
27  *
28  * File Description:
29  * OpenGL utility functions
30  */
31 
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbifile.hpp>
35 #include <corelib/ncbi_system.hpp>
36 #include <gui/opengl.h>
38 
39 #ifdef NCBI_OS_UNIX
40 #include <connect/ncbi_pipe.hpp>
41 #endif
42 
43 #ifdef NCBI_OS_DARWIN
44 #include <CoreServices/CoreServices.h>
45 #import <Foundation/Foundation.h>
46 #import <Foundation/NSProcessInfo.h>
47 
48 size_t GetPhysicalMemory(void)
49 {
50  return [NSProcessInfo processInfo].physicalMemory;
51 }
52 #endif
53 
54 #if defined(__WXGTK20__) || defined(__WXGTK__)
55 extern "C"
56 {
57 #include <gdk/gdkx.h>
58 #include <GL/glx.h>
59 }
60 #endif
61 
62 #include <wx/gdicmn.h>
63 #include <wx/utils.h>
64 
65 #include <connect/ncbi_socket.hpp>
66 
68 
70 {
71  ///
72  /// build our system info
73  ///
74 
75  ostr << "System Info" << endl << string(72, '-') << endl << endl;
76  {{
77 
78 #ifdef NCBI_OS_UNIX
79  ostr << "Host info: ";
80  /// system info
81  CPipe pipe;
82  vector<string> args;
83  args.push_back("-a");
84  pipe.Open("uname", args);
85 
86  char buf[128];
87  size_t bytes;
88  while( pipe.Read(buf, 128, &bytes) == eIO_Success ){
89  ostr << string( buf, bytes );
90  }
91 #endif
92 
93  ostr << "Number of CPUs: ";
94  ostr << CSystemInfo::GetCpuCount();
95  ostr << endl;
96 
97 #ifdef NCBI_OS_DARWIN
98  size_t ram_size = GetPhysicalMemory();
99 
100  ostr << "RAM size: " << ram_size / 1048576 << "MB" << endl;
101 
102  ostr << "OS Version: " << wxGetOsDescription().ToUTF8() << endl;
103 #endif
104 
105 
106 #ifdef NCBI_OS_MSWIN
107  SYSTEM_INFO sysinfo;
108  memset(&sysinfo, 0, sizeof(sysinfo));
109 
110  typedef void (WINAPI *PGetSysInfo)(SYSTEM_INFO*);
111 
112  PGetSysInfo pGetSysInfo = (PGetSysInfo)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
113  if( pGetSysInfo != NULL ){
114  pGetSysInfo( &sysinfo );
115  } else {
116  GetSystemInfo( &sysinfo );
117  }
118 
119  ostr << "Processor type: ";
120  switch (sysinfo.wProcessorArchitecture) {
121  default:
122  case PROCESSOR_ARCHITECTURE_UNKNOWN:
123  ostr << "unknown" << endl;
124  break;
125  case PROCESSOR_ARCHITECTURE_INTEL:
126  ostr << "Intel x32" << endl;
127  break;
128  case PROCESSOR_ARCHITECTURE_AMD64:
129  ostr << "Intel x64" << endl;
130  break;
131  case PROCESSOR_ARCHITECTURE_IA64:
132  ostr << "Itanium" << endl;
133  break;
134  }
135  ostr << "Processor level: "
136  << sysinfo.wProcessorLevel << endl
137  ;
138  ostr << "Processor revision: "
139  << hex << sysinfo.wProcessorRevision << dec << endl
140  ;
141 
142  ostr << "Page size: " << sysinfo.dwPageSize << endl;
143 
144  DWORDLONG ramSize = 0;
145  typedef BOOL (WINAPI *PGMSE)(LPMEMORYSTATUSEX);
146  PGMSE pGMSE = (PGMSE)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GlobalMemoryStatusEx");
147  if (pGMSE) {
148  MEMORYSTATUSEX mi;
149  memset(&mi, 0, sizeof(MEMORYSTATUSEX));
150  mi.dwLength = sizeof(MEMORYSTATUSEX);
151  if (pGMSE(&mi))
152  ramSize = mi.ullTotalPhys;
153  }
154  if (ramSize == 0) {
155  MEMORYSTATUS mi;
156  memset(&mi, 0, sizeof(MEMORYSTATUS));
157  mi.dwLength = sizeof(MEMORYSTATUS);
158  GlobalMemoryStatus(&mi);
159  ramSize = mi.dwTotalPhys;
160  }
161  ostr << "RAM size: " << (ramSize / 1024 / 1024) << "MB" << endl;
162 
163  ostr << "OS Version: " << wxGetOsDescription().ToUTF8() << endl;
164 
165  ostr << "Number of monitors: " << GetSystemMetrics(SM_CMONITORS) << endl;
166  ostr << "Base Monitor Resolution: "
167  << GetSystemMetrics(SM_CXSCREEN) << "x"
168  << GetSystemMetrics(SM_CYSCREEN) << endl
169  ;
170  ostr << "Virtual Monitor Resolution: "
171  << GetSystemMetrics(SM_CXVIRTUALSCREEN) << "x"
172  << GetSystemMetrics(SM_CYVIRTUALSCREEN) << endl
173  ;
174  ostr << "Network detected: "
175  << (GetSystemMetrics(SM_NETWORK) & 0x01 ? "yes" : "no") << endl
176  ;
177  ostr << "Remote Session: "
178  << (GetSystemMetrics(SM_REMOTESESSION) ? "yes" : "no") << endl
179  ;
180 #endif
181 
182 #ifdef NCBI_OS_LINUX
183  ostr << "Linux Distribution: "
184  << wxGetLinuxDistributionInfo().Description.ToUTF8() << endl << endl;
185 
186  typedef pair<const char*, const char*> TPair;
187  static TPair s_ProcEntries[] = {
188  TPair("CPU Information", "/proc/cpuinfo"),
189  TPair("Memory Information", "/proc/meminfo"),
190  };
191 
192  for( size_t i = 0; i < sizeof(s_ProcEntries) / sizeof (TPair); ++i ){
193  CNcbiIfstream istr(s_ProcEntries[i].second);
194  if (istr.good()) {
195  ostr << s_ProcEntries[i].first << ":" << endl;
196  string line;
197  while (NcbiGetlineEOL(istr, line)) {
198  ostr << " " << line << endl;
199  }
200  }
201  }
202 #endif
203  ostr << "IP address: ";
204 
205  unsigned int host = CSocketAPI::GetLocalHostAddress();
206  ostr << CSocketAPI::ntoa( host );
207  ostr << endl;
208 
209  ostr << endl << endl;
210  }}
211 
212  ostr << "Graphics Subsystem Info" << endl << string(72, '-') << endl << endl;
213  int x, y, w, h;
214  wxClientDisplayRect(&x, &y, &w, &h);
215  ostr << "Root window size: " << w << " x " << h << endl;
216 
217  {{
218  const GLubyte* na_text = (const GLubyte*)"NOT AVAILABLE";
219  const GLubyte* ptr = glGetString(GL_VENDOR);
220  if ( !ptr ) {
221  ptr = na_text;
222  }
223  ostr << "GL_VENDOR: " << ptr << endl;
224 
225  ptr = glGetString(GL_RENDERER);
226  if ( !ptr ) {
227  ptr = na_text;
228  }
229  ostr << "GL_RENDERER: " << ptr << endl;
230 
231  ptr = glGetString(GL_VERSION);
232  if ( !ptr ) {
233  ptr = na_text;
234  }
235  ostr << "GL_VERSION: " << ptr << endl;
236 
237  ptr = glGetString(GLU_VERSION);
238  if ( !ptr ) {
239  ptr = na_text;
240  }
241  ostr << "GLU_VERSION: " << ptr << endl;
242 
243 #if defined(__WXGTK20__) || defined(__WXGTK__)
244  int glxMajorVer = 1, glxMinorVer = 0;
245  glXQueryVersion(wxGetX11Display(), &glxMajorVer, &glxMinorVer);
246  ostr << "GLX Version: " << glxMajorVer << "." << glxMinorVer << endl;
247 #endif
248  ptr = glGetString(GL_EXTENSIONS);
249  if (ptr) {
250  string s(reinterpret_cast<const char*>(ptr));
251  list<string> toks;
252  NStr::Split(s, " ", toks, NStr::fSplit_Tokenize);
253  ostr << "GL_EXTENSIONS:" << endl;
254  ITERATE (list<string>, iter, toks) {
255  ostr << " " << *iter << endl;
256  }
257  }
258 
259  ptr = gluGetString(GLU_EXTENSIONS);
260  if (ptr) {
261  string s(reinterpret_cast<const char*>(ptr));
262  list<string> toks;
263  NStr::Split(s, " ", toks, NStr::fSplit_Tokenize);
264  ostr << "GLU_EXTENSIONS:" << endl;
265  ITERATE (list<string>, iter, toks) {
266  ostr << " " << *iter << endl;
267  }
268  }
269  }}
270 
271  {{
272  typedef pair<const char*, GLenum> TPair;
273  static const TPair s_EnumPairs[] = {
274  TPair("GL_DOUBLEBUFFER", GL_DOUBLEBUFFER),
275  TPair("GL_RED_BITS", GL_RED_BITS),
276  TPair("GL_GREEN_BITS", GL_GREEN_BITS),
277  TPair("GL_BLUE_BITS", GL_BLUE_BITS),
278  TPair("GL_ALPHA_BITS", GL_ALPHA_BITS),
279  TPair("GL_DEPTH_BITS", GL_DEPTH_BITS),
280  TPair("GL_MAX_ATTRIB_STACK_DEPTH", GL_MAX_ATTRIB_STACK_DEPTH),
281  TPair("GL_MAX_LIGHTS", GL_MAX_LIGHTS),
282  TPair("GL_MAX_LIST_NESTING", GL_MAX_LIST_NESTING),
283  TPair("GL_MAX_PROJECTION_STACK_DEPTH", GL_MAX_PROJECTION_STACK_DEPTH),
284  TPair("GL_MAX_TEXTURE_SIZE", GL_MAX_TEXTURE_SIZE),
285  TPair("GL_MAX_TEXTURE_STACK_DEPTH", GL_MAX_TEXTURE_STACK_DEPTH),
286  TPair("GL_MAX_MODELVIEW_STACK_DEPTH", GL_MAX_MODELVIEW_STACK_DEPTH),
287  TPair("GL_MAX_VIEWPORT_DIMS", GL_MAX_VIEWPORT_DIMS),
288  TPair("GL_MAX_NAME_STACK_DEPTH", GL_MAX_NAME_STACK_DEPTH),
289  };
290 
291  size_t max_len = 0;
292  for (size_t i = 0; i < sizeof(s_EnumPairs) / sizeof(TPair); ++i) {
293  max_len = max(max_len, strlen(s_EnumPairs[i].first));
294  }
295 
296  for (size_t i = 0; i < sizeof(s_EnumPairs) / sizeof(TPair); ++i) {
297  GLint vals[4];
298  glGetIntegerv(s_EnumPairs[i].second, vals);
299  ostr << s_EnumPairs[i].first << ":"
300  << string(max_len - strlen(s_EnumPairs[i].first) + 3, ' ')
301  << vals[0] << endl;
302  }
303  }}
304 
305 }
306 
307 
308 
static void DumpSystemInfo(CNcbiOstream &ostr)
Dump a text formatted report of the current system configuration.
CPipe –.
Definition: ncbi_pipe.hpp:76
static unsigned int GetCpuCount(void)
Return number of active CPUs/cores (never less than 1).
SStaticPair< const char *, const char * > TPair
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
EIO_Status Open(const string &cmd, const vector< string > &args, TCreateFlags create_flags=0, const string &current_dir=kEmptyStr, const char *const envp[]=0, size_t pipe_size=0)
Open pipe.
Definition: ncbi_pipe.cpp:1926
EIO_Status Read(void *buf, size_t count, size_t *read=0, EChildIOHandle from_handle=eDefault)
Read data from the pipe's default read handle.
Definition: ncbi_pipe.cpp:2001
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string ntoa(unsigned int host)
BSD-like API. NB: when int, "host" must be in network byte order.
static unsigned int GetLocalHostAddress(ESwitch reget=eDefault)
Local host address in network byte order (cached for faster retrieval)
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, string::size_type *count=NULL)
Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
@ eIO_Success
everything is fine, no error occurred
Definition: ncbi_core.h:133
char * buf
int i
static void hex(unsigned char c)
Definition: mdb_dump.c:56
Portable class to work with a spawned process via pipes.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
T max(T x_, T y_)
#define BOOL
Definition: odbcinst.h:18
Standard mechanism to include OpenGL headers for all platforms.
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
first_type first
Definition: static_set.hpp:64
Modified on Fri Apr 12 17:14:50 2024 by modify_doxy.py rev. 669887