16 using FloatingPointMicroseconds = std::chrono::duration<
double, std::micro>;
22 FloatingPointMicroseconds
Start;
38 void BeginSession(
const std::string& name,
const std::string& filepath =
"results.json")
40 std::lock_guard lock(m_Mutex);
53 m_OutputStream.open(filepath);
71 std::lock_guard lock(m_Mutex);
77 std::stringstream json;
79 json << std::setprecision(3) << std::fixed;
81 json <<
"\"cat\":\"function\",";
82 json <<
"\"dur\":" << (result.ElapsedTime.count()) <<
',';
83 json <<
"\"name\":\"" << result
.Name <<
"\",";
84 json <<
"\"ph\":\"X\",";
86 json <<
"\"tid\":" << result
.ThreadID <<
",";
87 json <<
"\"ts\":" << result.Start.count();
90 std::lock_guard lock(m_Mutex);
150 m_StartTimepoint = std::chrono::steady_clock::now();
161 auto endTimepoint = std::chrono::steady_clock::now();
162 auto highResStart = FloatingPointMicroseconds{ m_StartTimepoint.time_since_epoch() };
163 auto elapsedTime = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch() - std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimepoint).time_since_epoch();
165 Instrumentor::Get().WriteProfile({ m_Name, highResStart, elapsedTime, std::this_thread::get_id() });
183 template <size_t N, size_t K>
192 size_t matchIndex = 0;
193 while (matchIndex < K - 1 && srcIndex + matchIndex < N - 1 && expr[srcIndex + matchIndex] == remove[matchIndex])
195 if (matchIndex == K - 1)
196 srcIndex += matchIndex;
197 result.Data[dstIndex++] = expr[srcIndex] ==
'"' ?
'\'' : expr[srcIndex];
205#define SPICES_PROFILE 1
210#if defined(__GNUC__
) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000
)) || (defined(__ICC) && (__ICC >= 600
)) || defined(__ghs__)
211#define SPICES_FUNC_SIG __PRETTY_FUNCTION__
212#elif defined(__DMC__) && (__DMC__ >= 0x810
)
213#define SPICES_FUNC_SIG __PRETTY_FUNCTION__
214#elif (defined(__FUNCSIG__) || (_MSC_VER))
215#define SPICES_FUNC_SIG __FUNCSIG__
216#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600
)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500
))
217#define SPICES_FUNC_SIG __FUNCTION__
218#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550
)
219#define SPICES_FUNC_SIG __FUNC__
220#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901
)
221#define SPICES_FUNC_SIG __func__
222#elif defined(__cplusplus) && (__cplusplus >= 201103
)
223#define SPICES_FUNC_SIG __func__
225#define SPICES_FUNC_SIG "SPICES_FUNC_SIG unknown!"
228#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath) ::SpicesTest::Instrumentor::Get().BeginSession(name, filepath)
229#define SPICESTEST_PROFILE_END_SESSION() ::SpicesTest::Instrumentor::Get().EndSession()
230#define SPICESTEST_PROFILE_SCOPE_LINE2(name, line) constexpr auto fixedName##line = ::SpicesTest::InstrumentorUtils::CleanupOutputString(name, "__cdecl ");
231 ::SpicesTest::InstrumentationTimer timer##line(fixedName##line.Data)
238#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath)
239#define SPICESTEST_PROFILE_END_SESSION()
240#define SPICESTEST_PROFILE_SCOPE(name)
241#define SPICESTEST_PROFILE_FUNCTION()
#define SPICESTEST_PROFILE_SCOPE_LINE2(name, line)
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICESTEST_PROFILE_END_SESSION()
#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath)
#define SPICESTEST_PROFILE_SCOPE_LINE(name, line)
InstrumentationTimer(const char *name)
std::chrono::time_point< std::chrono::steady_clock > m_StartTimepoint
Instrumentor(Instrumentor &&)=delete
static Instrumentor & Get()
void BeginSession(const std::string &name, const std::string &filepath="results.json")
void WriteProfile(const ProfileResult &result)
InstrumentationSession * m_CurrentSession
std::ofstream m_OutputStream
Instrumentor(const Instrumentor &)=delete
void InternalEndSession()
int main(int argc, char **argv)
The Entry of SpicesTest.
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start