DPL static block usage for profiling
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 22 Feb 2013 08:37:01 +0000 (09:37 +0100)
committerGerrit Code Review <gerrit2@kim11>
Wed, 27 Feb 2013 09:27:21 +0000 (18:27 +0900)
[Issue#]       N/A
[Bug]          Refactoring to static block abstract which was aded in related change
[Cause]        N/A
[Solution]     Use added construction
[Verification] Build repository with profiling. Run wrt-client. Assure no assert is thrown.

This change needs merged: https://tizendev.org/gerrit/#/c/47415/ from wrt-commons

Change-Id: I057a90b102962a50f856164cb4bd77dcece6118d

src/profiling/profiling_util.cpp

index b8a08ef..cd94c0f 100644 (file)
@@ -32,6 +32,8 @@
 #include <dpl/foreach.h>
 #include <dpl/log/log.h>
 #include <dpl/mutex.h>
+#include <dpl/static_block.h>
+#include <dpl/assert.h>
 
 namespace {
 const int PROFILING_OUTPUT_DESCRIPTOR = 3;
@@ -110,21 +112,16 @@ void sigUsrHandler(int /*num*/)
     dumpStatistic();
 }
 
-int initialize();
-
-const int i = initialize();
 DPL::Mutex* m_mutex = NULL;
 
-int initialize()
+void initialize()
 {
-    (void)i;
     m_mutex = new DPL::Mutex;
     results.reserve(64 * 1024);
     signal(SIGUSR1, &sigUsrHandler);
     signal(SIGUSR2, &sigUsrHandler);
     LogDebug("Initialized profiling");
     AddProfilingMeasurment("Profiling_Started");
-    return 1;
 }
 
 std::string GetFormattedTime()
@@ -149,6 +146,7 @@ std::string GetFormattedTime()
 
 void AddStdoutProfilingMeasurment(const char* name, bool start)
 {
+    Assert(m_mutex != NULL);
     std::ostringstream output;
     output << "[" << GetFormattedTime() << "] [](): " << name << " ";
     output << (start ? "profiling##start" : "profiling##stop");
@@ -166,3 +164,9 @@ void AddProfilingMeasurment(const char* name,
     results.push_back(
         PacketResult(toULong(value), name, prefix, description));
 }
+
+STATIC_BLOCK
+{
+    initialize();
+}
+