tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1165450 - in /tuscany/sca-cpp/trunk/kernel: fstream.hpp parallel-test.cpp parallel.hpp
Date Mon, 05 Sep 2011 23:30:21 GMT
Author: jsdelfino
Date: Mon Sep  5 23:30:20 2011
New Revision: 1165450

URL: http://svn.apache.org/viewvc?rev=1165450&view=rev
Log:
Improve logging with multiple threads and processes.

Modified:
    tuscany/sca-cpp/trunk/kernel/fstream.hpp
    tuscany/sca-cpp/trunk/kernel/parallel-test.cpp
    tuscany/sca-cpp/trunk/kernel/parallel.hpp

Modified: tuscany/sca-cpp/trunk/kernel/fstream.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/fstream.hpp?rev=1165450&r1=1165449&r2=1165450&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/fstream.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/fstream.hpp Mon Sep  5 23:30:20 2011
@@ -29,6 +29,11 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <time.h>
+#include <sys/time.h>
+#include <unistd.h>
+#ifdef WANT_THREADS
+#include <pthread.h>
+#endif
 #include "string.hpp"
 #include "stream.hpp"
 
@@ -149,10 +154,14 @@ ifstream cin(stdin);
  * Format the current time.
  */
 const string logTime() {
-    const time_t t = ::time(NULL);
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    const time_t t = tv.tv_sec;
     const tm* lt = localtime(&t);
     char ft[32];
-    strftime(ft, 31, "%a %b %d %H:%M:%S %Y", lt);
+    strftime(ft, 20, "%a %b %d %H:%M:%S", lt);
+    sprintf(ft + 19, ".%06lu ", (unsigned long)tv.tv_usec);
+    strftime(ft + 27, 5, "%Y", lt);
     return ft;
 }
 
@@ -203,11 +212,19 @@ private:
     bool owner;
     bool head;
 
+    const unsigned long tid() const {
+#ifdef WANT_THREADS
+        return (unsigned long)pthread_self();
+#else
+        return 0;
+#endif
+    }
+
     logfstream& whead() {
         if (head)
             return *this;
         head = true;
-        *this << "[" << logTime() << "] [" << type << "] ";
+        *this << "[" << logTime() << "] [" << type << "] [pid
" << (unsigned long)getpid() << ":tid " << tid() << "] ";
         return *this;
     }
 };

Modified: tuscany/sca-cpp/trunk/kernel/parallel-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/parallel-test.cpp?rev=1165450&r1=1165449&r2=1165450&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/parallel-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/parallel-test.cpp Mon Sep  5 23:30:20 2011
@@ -136,15 +136,15 @@ bool checkSquareResults(const list<futur
     return true;
 }
 
-const gc_ptr<long int> tlsvc() {
-    gc_ptr<long int> i = new (gc_new<long int>()) long int();
+const gc_ptr<unsigned long> tlsvc() {
+    gc_ptr<unsigned long> i = new (gc_new<unsigned long>()) unsigned long();
     *i = 0l;
     return i;
 }
-const perthread_ptr<long int> tlsv(tlsvc);
+const perthread_ptr<unsigned long> tlsv(tlsvc);
 
 const long int tlsset(gc_ptr<wqueue<bool>> wq, gc_ptr<wqueue<bool>>
xq) {
-    const long int v = *tlsv;
+    const unsigned long v = *tlsv;
     *tlsv = threadId();
     enqueue(*xq, true);
     dequeue(*wq);
@@ -183,8 +183,7 @@ bool checkTLSSets(const list<future<long
     if (isNil(s))
         return true;
     assert(car(s) == 0);
-    checkTLSSets(cdr(s));
-    return true;
+    return checkTLSSets(cdr(s));
 }
 
 const list<future<bool> > submitTLSChecks(worker& w, wqueue<bool>&
wq, wqueue<bool>& xq, const int max, const int i) {
@@ -198,23 +197,21 @@ bool checkTLSResults(const list<future<b
     if (isNil(r))
         return true;
     assert(car(r) == true);
-    checkTLSResults(cdr(r));
-    return true;
+    return checkTLSResults(cdr(r));
 }
 
 bool testWorker() {
-    worker w(20);
+    const int max = 100;
+    worker w(max);
     {
         const lambda<int()> func = curry(lambda<int(const int)> (mtsquare), 2);
         assert(submit(w, func) == 4);
     }
     {
-        const int max = 20;
         const list<future<int> > r(submitSquares(w, max, 0));
         checkSquareResults(r, 0);
     }
     {
-        const int max = 20;
         wqueue<bool> wq(max);
         unblockWorkers(wq, max);
         waitForWorkers(wq, max);
@@ -222,7 +219,6 @@ bool testWorker() {
         waitForWorkers(wq, max);
     }
     {
-        const int max = 20;
         wqueue<bool> wq(max);
         wqueue<bool> xq(max);
         const list<future<long int> > s(submitTLSSets(w, wq, xq, max, 0));

Modified: tuscany/sca-cpp/trunk/kernel/parallel.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/parallel.hpp?rev=1165450&r1=1165449&r2=1165450&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/parallel.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/parallel.hpp Mon Sep  5 23:30:20 2011
@@ -26,10 +26,9 @@
  * Simple parallel work execution functions.
  */
 
+#include <unistd.h>
 #ifdef WANT_THREADS
 #include <pthread.h>
-#include <sys/syscall.h>
-#include <unistd.h>
 #endif
 
 #include "function.hpp"
@@ -37,17 +36,20 @@
 
 namespace tuscany {
 
+/**
+ * Returns the current process id.
+ */
+unsigned long processId() {
+    return (unsigned long)getpid();
+}
+
 #ifdef WANT_THREADS
 
 /**
  * Returns the current thread id.
  */
-long int threadId() {
-#ifdef IS_DARWIN
-    return syscall(SYS_thread_selfid);
-#else
-    return syscall(SYS_gettid);
-#endif
+unsigned long threadId() {
+    return (unsigned long)pthread_self();
 }
 
 /**
@@ -317,6 +319,15 @@ const bool cancel(worker& w) {
     return true;
 }
 
+#else
+
+/**
+ * Returns the current thread id.
+ */
+unsigned long threadId() {
+    return 0;
+}
+
 #endif
 
 /**



Mime
View raw message