add continue session and uncrustify
This commit is contained in:
parent
0fa9dd430b
commit
0b8fb261fa
2 changed files with 95 additions and 99 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.12.0, 2020-05-17T10:10:28. -->
|
<!-- Written by QtCreator 4.12.0, 2020-09-29T16:34:27. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{a59f5d47-09f7-45f4-8f6a-af2e6553b46c}</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{a59f5d47-09f7-45f4-8f6a-af2e6553b46c}</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
|
@ -137,10 +137,11 @@
|
||||||
<valuemap type="QVariantMap" key="Qbs.Configuration">
|
<valuemap type="QVariantMap" key="Qbs.Configuration">
|
||||||
<value type="QString" key="qbs.defaultBuildVariant">release</value>
|
<value type="QString" key="qbs.defaultBuildVariant">release</value>
|
||||||
<value type="QString" key="qbs.profile">qtc_Desktop_842209c4</value>
|
<value type="QString" key="qbs.profile">qtc_Desktop_842209c4</value>
|
||||||
|
<value type="bool" key="qbspm.forceProbes">false</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="bool" key="Qbs.DryKeepGoing">false</value>
|
<value type="bool" key="Qbs.DryKeepGoing">false</value>
|
||||||
<value type="bool" key="Qbs.Install">true</value>
|
<value type="bool" key="Qbs.Install">true</value>
|
||||||
<value type="int" key="Qbs.MaxJobs">0</value>
|
<value type="int" key="Qbs.MaxJobs">48</value>
|
||||||
<value type="bool" key="Qbs.ShowCommandLines">false</value>
|
<value type="bool" key="Qbs.ShowCommandLines">false</value>
|
||||||
<value type="bool" key="Qbs.forceProbesKey">false</value>
|
<value type="bool" key="Qbs.forceProbesKey">false</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
@ -246,19 +247,19 @@
|
||||||
</valuelist>
|
</valuelist>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qbs.RunConfiguration:example-slowFastRendering.</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">example-slowFastRendering.</value>
|
||||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
|
||||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||||
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
|
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
|
||||||
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
|
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||||
|
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||||
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
|
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/pointer/of_v0.11.0_linux64gcc6_release/addons/ofxProfiler/example-slowFastRendering/bin</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
|
|
@ -12,63 +12,61 @@
|
||||||
|
|
||||||
namespace ofxProfiler {
|
namespace ofxProfiler {
|
||||||
|
|
||||||
using FloatingPointMicroseconds = chrono::duration<double, micro>;
|
using FloatingPointMicroseconds = chrono::duration <double, micro>;
|
||||||
|
|
||||||
struct ProfileResult
|
struct ProfileResult {
|
||||||
{
|
string Name;
|
||||||
string Name;
|
|
||||||
|
|
||||||
FloatingPointMicroseconds Start;
|
FloatingPointMicroseconds Start;
|
||||||
chrono::microseconds ElapsedTime;
|
chrono::microseconds ElapsedTime;
|
||||||
thread::id ThreadID;
|
thread::id ThreadID;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InstrumentationSession
|
struct InstrumentationSession {
|
||||||
{
|
string Name;
|
||||||
string Name;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
class Instrumentor
|
class Instrumentor {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
mutex m_Mutex;
|
mutex m_Mutex;
|
||||||
InstrumentationSession* m_CurrentSession;
|
InstrumentationSession * m_CurrentSession;
|
||||||
ofstream m_OutputStream;
|
ofstream m_OutputStream;
|
||||||
public:
|
public:
|
||||||
Instrumentor()
|
Instrumentor()
|
||||||
: m_CurrentSession(nullptr)
|
: m_CurrentSession(nullptr){
|
||||||
{
|
}
|
||||||
|
|
||||||
|
void BeginSession(const string & name = "I do not want to name my profiling sessions.",
|
||||||
|
const string & filepath = "results.json",
|
||||||
|
const bool continueSession = false){
|
||||||
|
lock_guard <mutex> lock(m_Mutex);
|
||||||
|
if(!m_CurrentSession || !continueSession){
|
||||||
|
// if there is no session, or it should not be continued
|
||||||
|
if(m_CurrentSession){
|
||||||
|
// If there is already a current session, then close it before beginning new one.
|
||||||
|
// Subsequent profiling output meant for the original session will end up in the
|
||||||
|
// newly opened session instead. That's better than having badly formatted
|
||||||
|
// profiling output.
|
||||||
|
ofLog(OF_LOG_ERROR, "Instrumentor::BeginSession('%s') when session '%s' already open.", name.c_str(), m_CurrentSession->Name.c_str());
|
||||||
|
InternalEndSession();
|
||||||
|
}
|
||||||
|
m_OutputStream.open(filepath);
|
||||||
|
|
||||||
|
if(m_OutputStream.is_open()){
|
||||||
|
m_CurrentSession = new InstrumentationSession({name});
|
||||||
|
WriteHeader();
|
||||||
|
}else{
|
||||||
|
ofLog(OF_LOG_ERROR, "Instrumentor could not open results file '%s'.", filepath.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginSession(const string& name, const string& filepath = "results.json")
|
void EndSession(){
|
||||||
{
|
lock_guard <mutex> lock(m_Mutex);
|
||||||
lock_guard<mutex> lock(m_Mutex);
|
|
||||||
if (m_CurrentSession) {
|
|
||||||
// If there is already a current session, then close it before beginning new one.
|
|
||||||
// Subsequent profiling output meant for the original session will end up in the
|
|
||||||
// newly opened session instead. That's better than having badly formatted
|
|
||||||
// profiling output.
|
|
||||||
ofLog(OF_LOG_ERROR,"Instrumentor::BeginSession('%s') when session '%s' already open.", name.c_str(), m_CurrentSession->Name.c_str());
|
|
||||||
InternalEndSession();
|
|
||||||
}
|
|
||||||
m_OutputStream.open(filepath);
|
|
||||||
|
|
||||||
if (m_OutputStream.is_open()) {
|
|
||||||
m_CurrentSession = new InstrumentationSession({name});
|
|
||||||
WriteHeader();
|
|
||||||
} else {
|
|
||||||
ofLog(OF_LOG_ERROR,"Instrumentor could not open results file '%s'.", filepath.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EndSession()
|
|
||||||
{
|
|
||||||
lock_guard<mutex> lock(m_Mutex);
|
|
||||||
InternalEndSession();
|
InternalEndSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteProfile(const ProfileResult& result)
|
void WriteProfile(const ProfileResult & result){
|
||||||
{
|
|
||||||
stringstream json;
|
stringstream json;
|
||||||
|
|
||||||
string name = result.Name;
|
string name = result.Name;
|
||||||
|
@ -85,35 +83,33 @@ namespace ofxProfiler {
|
||||||
json << "\"ts\":" << result.Start.count();
|
json << "\"ts\":" << result.Start.count();
|
||||||
json << "}";
|
json << "}";
|
||||||
|
|
||||||
lock_guard<mutex> lock(m_Mutex);
|
lock_guard <mutex> lock(m_Mutex);
|
||||||
if (m_CurrentSession) {
|
if(m_CurrentSession){
|
||||||
m_OutputStream << json.str();
|
m_OutputStream << json.str();
|
||||||
m_OutputStream.flush();
|
m_OutputStream.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Instrumentor& Get() {
|
static Instrumentor & Get(){
|
||||||
static Instrumentor instance;
|
static Instrumentor instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteHeader()
|
void WriteHeader(){
|
||||||
{
|
|
||||||
m_OutputStream << "{\"otherData\": {},\"traceEvents\":[{}";
|
m_OutputStream << "{\"otherData\": {},\"traceEvents\":[{}";
|
||||||
m_OutputStream.flush();
|
m_OutputStream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteFooter()
|
void WriteFooter(){
|
||||||
{
|
|
||||||
m_OutputStream << "]}";
|
m_OutputStream << "]}";
|
||||||
m_OutputStream.flush();
|
m_OutputStream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: you must already own lock on m_Mutex before
|
// Note: you must already own lock on m_Mutex before
|
||||||
// calling InternalEndSession()
|
// calling InternalEndSession()
|
||||||
void InternalEndSession() {
|
void InternalEndSession(){
|
||||||
if (m_CurrentSession) {
|
if(m_CurrentSession){
|
||||||
WriteFooter();
|
WriteFooter();
|
||||||
m_OutputStream.close();
|
m_OutputStream.close();
|
||||||
delete m_CurrentSession;
|
delete m_CurrentSession;
|
||||||
|
@ -121,69 +117,68 @@ namespace ofxProfiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class InstrumentationTimer
|
class InstrumentationTimer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
InstrumentationTimer(const char* name)
|
InstrumentationTimer(const char * name)
|
||||||
: m_Name(name), m_Stopped(false)
|
: m_Name(name), m_Stopped(false){
|
||||||
{
|
|
||||||
m_StartTimepoint = chrono::steady_clock::now();
|
m_StartTimepoint = chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
~InstrumentationTimer()
|
~InstrumentationTimer(){
|
||||||
{
|
if(!m_Stopped){
|
||||||
if (!m_Stopped)
|
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Stop()
|
void Stop(){
|
||||||
{
|
|
||||||
auto endTimepoint = chrono::steady_clock::now();
|
auto endTimepoint = chrono::steady_clock::now();
|
||||||
auto highResStart = FloatingPointMicroseconds{ m_StartTimepoint.time_since_epoch() };
|
auto highResStart = FloatingPointMicroseconds{m_StartTimepoint.time_since_epoch()};
|
||||||
auto elapsedTime = chrono::time_point_cast<chrono::microseconds>(endTimepoint).time_since_epoch() - chrono::time_point_cast<chrono::microseconds>(m_StartTimepoint).time_since_epoch();
|
auto elapsedTime = chrono::time_point_cast <chrono::microseconds>(endTimepoint).time_since_epoch() - chrono::time_point_cast <chrono::microseconds>(m_StartTimepoint).time_since_epoch();
|
||||||
|
|
||||||
Instrumentor::Get().WriteProfile({ m_Name, highResStart, elapsedTime, this_thread::get_id() });
|
Instrumentor::Get().WriteProfile({m_Name, highResStart, elapsedTime, this_thread::get_id()});
|
||||||
|
|
||||||
m_Stopped = true;
|
m_Stopped = true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
const char* m_Name;
|
const char * m_Name;
|
||||||
chrono::time_point<chrono::steady_clock> m_StartTimepoint;
|
chrono::time_point <chrono::steady_clock> m_StartTimepoint;
|
||||||
bool m_Stopped;
|
bool m_Stopped;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFX_PROFILER 1
|
#define OFX_PROFILER 1
|
||||||
#if OFX_PROFILER
|
// Resolve which function signature macro will HZ_PROFILE_BEGIN_SESSIONbe used. Note that this only
|
||||||
// Resolve which function signature macro will HZ_PROFILE_BEGIN_SESSIONbe used. Note that this only
|
// is resolved when the (pre)compiler starts, so the syntax highlighting
|
||||||
// is resolved when the (pre)compiler starts, so the syntax highlighting
|
// could mark the wrong one in your editor!
|
||||||
// could mark the wrong one in your editor!
|
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
|
||||||
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
|
#define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__
|
||||||
#define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__
|
#elif defined(__DMC__) && (__DMC__ >= 0x810)
|
||||||
#elif defined(__DMC__) && (__DMC__ >= 0x810)
|
#define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__
|
||||||
#define OFX_PROFILER_FUNC_SIG __PRETTY_FUNCTION__
|
#elif defined(__FUNCSIG__)
|
||||||
#elif defined(__FUNCSIG__)
|
#define OFX_PROFILER_FUNC_SIG __FUNCSIG__
|
||||||
#define OFX_PROFILER_FUNC_SIG __FUNCSIG__
|
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
|
||||||
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
|
#define OFX_PROFILER_FUNC_SIG __FUNCTION__
|
||||||
#define OFX_PROFILER_FUNC_SIG __FUNCTION__
|
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
|
||||||
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
|
#define OFX_PROFILER_FUNC_SIG __FUNC__
|
||||||
#define OFX_PROFILER_FUNC_SIG __FUNC__
|
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
|
||||||
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
|
#define OFX_PROFILER_FUNC_SIG __func__
|
||||||
#define OFX_PROFILER_FUNC_SIG __func__
|
#elif defined(__cplusplus) && (__cplusplus >= 201103)
|
||||||
#elif defined(__cplusplus) && (__cplusplus >= 201103)
|
#define OFX_PROFILER_FUNC_SIG __func__
|
||||||
#define OFX_PROFILER_FUNC_SIG __func__
|
#else
|
||||||
#else
|
#define OFX_PROFILER_FUNC_SIG "OFX_PROFILER_FUNC_SIG unknown!"
|
||||||
#define OFX_PROFILER_FUNC_SIG "OFX_PROFILER_FUNC_SIG unknown!"
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#if OFX_PROFILER
|
||||||
#define OFX_PROFILER_BEGIN_SESSION(name, filepath) ::ofxProfiler::Instrumentor::Get().BeginSession(name, filepath)
|
#define OFX_PROFILER_BEGIN_SESSION(name, filepath) ::ofxProfiler::Instrumentor::Get().BeginSession(name, filepath)
|
||||||
|
#define OFX_PROFILER_CONTINUE_SESSION(name, filepath) ::ofxProfiler::Instrumentor::Get().BeginSession(name, filepath, true)
|
||||||
#define OFX_PROFILER_END_SESSION() ::ofxProfiler::Instrumentor::Get().EndSession()
|
#define OFX_PROFILER_END_SESSION() ::ofxProfiler::Instrumentor::Get().EndSession()
|
||||||
#define OFX_PROFILER_SCOPE(name) ::ofxProfiler::InstrumentationTimer timer##__LINE__(name);
|
#define OFX_PROFILER_SCOPE(name) ::ofxProfiler::InstrumentationTimer timer ## __LINE__(name);
|
||||||
#define OFX_PROFILER_FUNCTION() OFX_PROFILER_SCOPE(OFX_PROFILER_FUNC_SIG)
|
#define OFX_PROFILER_FUNCTION() OFX_PROFILER_SCOPE(OFX_PROFILER_FUNC_SIG)
|
||||||
#else
|
#else
|
||||||
#define OFX_PROFILER_BEGIN_SESSION(name, filepath)
|
#define OFX_PROFILER_BEGIN_SESSION(name, filepath)
|
||||||
|
#define OFX_PROFILER_CONTINUE_SESSION(name, filepath)
|
||||||
#define OFX_PROFILER_END_SESSION()
|
#define OFX_PROFILER_END_SESSION()
|
||||||
#define OFX_PROFILER_SCOPE(name)
|
#define OFX_PROFILER_SCOPE(name)
|
||||||
#define OFX_PROFILER_FUNCTION()
|
#define OFX_PROFILER_FUNCTION()
|
||||||
|
|
Loading…
Reference in a new issue