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