ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
info.m
Go to the documentation of this file.
1%> \brief
2%> Return a MATLAB string containing the current system information.<br>
3%>
4%> \return
5%> ``str`` : The output scalar MATLAB string containing the current system information.<br>
6%> ``cache`` : The output scalar MATLAB string representing the path to the
7%> cache file containing the current system information.<br>
8%> The returned cache file path has the form:<br>
9%> \code{.m}
10%> <DIR>/.info<YEAR><MONTH>.cache<br>
11%> \endcode
12%> where,<br>
13%> <ol>
14%> <li> ``<DIR>`` is replaced by the directory containing the function [pm.sys.info()](@ref info),
15%> <li> ``<YEAR>`` is replaced by the current year,
16%> <li> ``<MONTH>`` is replaced by the current month.
17%> </ol>
18%> This means that the cache file contents are supposed to be updated only every month if necessary.<br>
19%> A cache file is generated because retrieving system information is an expensive shell command-line operation.<br>
20%> The time expense is particularly notable on Windows systems.<br>
21%>
22%> \interface{info}
23%> \code{.m}
24%>
25%> [str, cache] = pm.sys.info()
26%>
27%> \endcode
28%>
29%> \example{info}
30%> \include{lineno} example/sys/info/main.m
31%> \output{info}
32%> \include{lineno} example/sys/info/main.out.m
33%>
34%> \final{info}
35%>
36%> \author
37%> \JoshuaOsborne, May 21 2024, 5:31 AM, University of Texas at Arlington<br>
38%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
39%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
40function [str, cache] = info()
41 prefix = ".info";
42 suffix = ".cache";
43 [dirname, ~, ~] = fileparts(mfilename('fullpath'));
44 cache = fullfile(string(dirname), prefix + string(year(date)) + string(month(date)) + suffix); % update cache once a month.
45 if ~isfile(cache)
46 delete(prefix + "*" + suffix);
47 if ispc
48 cmd = "systeminfo";
49 end
50 if ismac
51 cmd = "uname -a; sysctl -a | grep machdep.cpu";
52 end
53 if isunix && ~ismac
54 cmd = "uname -a; lscpu";
55 end
56 [failed, str] = system(cmd);
57 failed = failed ~= 0;
58 if failed
59 warning ( newline ...
60 + "Failed to fetch the system information on the current system. skipping..." ...
61 + newline ...
62 );
63 end
64 fid = fopen(cache, 'wt');
65 fprintf(fid, "%s", str);
66 fclose(fid);
67 else
68 str = fileread(cache);
69 end
70 str = string(str);
71end
function info()
Return a MATLAB string containing the current system information.