tools
読み取り中…
検索中…
一致する文字列を見つけられません
debug.h
[詳解]
1
#pragma once
2
#include <iostream>
3
#include <thread>
4
#include <chrono>
5
6
/**
7
* @file debug.h
8
* @brief デバッグ・パフォーマンス計測ユーティリティ
9
*
10
* スレッド追跡用のシーケンスログ出力と、高精度な実行時間計測クラスを提供します。
11
*/
12
13
/// @brief シーケンスログのカウンタ(グローバル)
14
int
SL
= 0;
15
16
/**
17
* @brief シーケンスログを出力する
18
*
19
* 呼び出しごとにカウンタをインクリメントしてスレッド ID と共に出力します。
20
* custom 引数を指定した場合はカスタム値のみ出力します。
21
*
22
* @param custom 任意のカスタムポイント値。デフォルト値(-100000)のときは自動カウントモード
23
* @note 出力例(自動): `SL::0x12345678::3`
24
* @note 出力例(カスタム): `getSL()::0x12345678::CustomPoint: 42`
25
*/
26
void
getSL
(
int
custom = -100000) {
27
if
(custom != -100000) {std::cout <<
"getSL()::"
<< std::this_thread::get_id() <<
"::CustomPoint: "
<< custom <<
"\n"
;
return
;}
28
SL
++;
29
std::cout <<
"SL::"
<< std::this_thread::get_id() <<
"::"
<<
SL
<<
"\n"
;
30
}
31
32
/**
33
* @brief 実行時間計測クラス
34
*
35
* インスタンス生成時に計測開始し、end() 呼び出し時にミリ秒単位で経過時間を出力します。
36
*
37
* @code
38
* checkTime ct;
39
* // ... 計測したい処理 ...
40
* ct.end(); // "CheckTime: 123" のように出力
41
* @endcode
42
*/
43
class
checkTime
{
44
public
:
45
/**
46
* @brief コンストラクタ。計測を開始する
47
*/
48
checkTime
() {
49
start = std::chrono::high_resolution_clock::now();
50
}
51
52
/**
53
* @brief 計測を終了し、経過時間をミリ秒単位で標準出力に表示する
54
*/
55
void
end
() {
56
std::chrono::time_point<std::chrono::high_resolution_clock> e = std::chrono::high_resolution_clock::now();
57
std::chrono::duration<long long, std::milli> duration = std::chrono::duration_cast<std::chrono::milliseconds>(e - start);
58
std::cout <<
"CheckTime: "
<< duration.count() <<
"\n"
;
59
}
60
private
:
61
/// @brief 計測開始時刻
62
std::chrono::time_point<std::chrono::high_resolution_clock> start;
63
};
64
/*
65
struct getInfo {
66
getInfo(int flags) {
67
enum LocationFlags {
68
FileName = 0b0001,
69
FunctionName = 0b0010,
70
Line = 0b0100,
71
Column = 0b1000
72
};
73
}*/
checkTime::end
void end()
計測を終了し、経過時間をミリ秒単位で標準出力に表示する
Definition
debug.h:55
checkTime::checkTime
checkTime()
コンストラクタ。計測を開始する
Definition
debug.h:48
getSL
void getSL(int custom=-100000)
シーケンスログを出力する
Definition
debug.h:26
SL
int SL
シーケンスログのカウンタ(グローバル)
Definition
debug.h:14
debug.h
構築:
1.14.0