LoginSignup
3
3

More than 5 years have passed since last update.

プログラムを使った実験で必要になる情報を取ってくる方法(window/mac)

Posted at

はじめに

卒論などでプログラムを書く際には,実験に使用した計算機の情報が必要になる時があります.例えば,以下の情報が挙げられます.

  • 使用したCPU
  • メモリサイズ
  • コア数
  • 実験した日時
  • ピークメモリ使用量

これを自分で調べたり,タスクマネージャーとにらめっこするのはあまりよくないので,それぞれを調べられるような方法をWindowsとMacでしらべて,両方で動く関数群を(大分昔に)作成しました.

コード

  • https://github.com/tmichi/mibase : 自作ライブラリ mi::SystemInfoに実装しています.単独で利用したい場合は, include/mi/SystemInfo.hpp とsrc/SystemInfo.cppを持って来ればokです.

関数

static std::string mi::SystemInfo::getCpuName ( void )
CPUの名前を文字列で取得する.
static double mi::SystemInfo::getMemorySize ( void )
メモリ使用量(GB)を取得する.
static int mi::SystemInfo::getNumCores ( void )
CPUのコア数を取得する
static std::string mi::SystemInfo::getDate ( void )
実行日時を取得する.
static double mi::SystemInfo::getPeakMemorySize ( const SIZE_TYPE type = MI_MEGA_BYTE )
この関数が呼ばれた時点での最大メモリ使用量を取得する.引数には,単位を指定できる(MI_BYTE, MI_KILO_BYTE, MI_MEGA_BYTE, MI_GIGA_BYTE)

サンプルコード

system0.cpp
#include <mi/SystemInfo.hpp>
#include <iostream>

int main ( int argc, char** argv )
{
        std::cerr << "cpu name: " << mi::SystemInfo::getCpuName() << std::endl;
        std::cerr << "mem size: " << mi::SystemInfo::getMemorySize() << "[gb]" << std::endl;
        std::cerr << "date: " << mi::SystemInfo::getDate() << std::endl;
        std::cerr << "#cores: " << mi::SystemInfo::getNumCores() << std::endl;
        return 0;
}
実行結果
$ ./samples/system0 
cpu name: Intel(R) Core(TM) M-5Y51 CPU @ 1.10GHz
mem size: 8[gb]
date: 2015-07-08-12:25:37
#cores: 2
$ 

使い方

計算結果を出力する際に計算結果と一緒に出力しておくと,いつ,どの環境で実験したのかがわかりやすくなると思います.

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3