vtable_sthread.cpp

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: vtable_sthread.cpp,v 1.16 2010/05/26 01:21:35 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #include "w_defines.h"
00031 
00032 /*  -- do not edit anything above this line --   </std-header>*/
00033 
00034 /*
00035  * Functions to gather info from the threads for
00036  * placing the info into a virtual table
00037  */
00038 
00039 #include <w.h>
00040 #include <w_debug.h>
00041 #include <w_stream.h>
00042 #include <cstdlib>
00043 #include <cstring>
00044 #include "sthread.h"
00045 #include "sthread_stats.h"
00046 #include "sthread_vtable_enum.h"
00047 
00048 
00049 #ifdef EXPLICIT_TEMPLATE
00050 template class vtable_func<sthread_t>;
00051 #endif /* __GNUG__ */
00052 
00053 const char *sthread_vtable_attr_names[] =
00054 {
00055     "Thread id",
00056     "Thread name",
00057     "Thread status",
00058 #include "sthread_stats_msg_gen.h"
00059         0
00060 };
00061 
00062 static vtable_names_init_t names_init(sthread_last, sthread_vtable_attr_names);
00063 
00064 int
00065 sthread_t::collect(vtable_t &v, bool names_too)
00066 {
00067 
00068     CRITICAL_SECTION(cs, _class_list_lock);
00069 
00070     // Traverse once to count the number of entries. Grot.
00071     int nt=0;
00072     {
00073         w_list_i<sthread_t,queue_based_lock_t> i(*_class_list);
00074         while (i.next())  { nt++; }
00075     }
00076 
00077         if(names_too) nt ++;
00078         // nt: number of rows
00079         // sthread_last: number of attributes
00080         // names_init.max_size() : max attribute length
00081     if(v.init(nt, sthread_last, names_init.max_size())) return -1;
00082 
00083     vtable_func<sthread_t> f(v);
00084 
00085 // TODO: REMOVE
00086 // cerr << "collect " << __LINE__ << " " << __FILE__; v.operator<<(cerr); cerr << endl;
00087 
00088     if(names_too) f.insert_names();
00089 
00090 // TODO: REMOVE
00091 // cerr << "collect " << __LINE__ << " " << __FILE__; v.operator<<(cerr); cerr << endl;
00092     {
00093         w_list_i<sthread_t,queue_based_lock_t> i(*_class_list);
00094         while (i.next())  {
00095             // Call the function f to fill a row of the table. 
00096             f(*i.curr());
00097 // TODO: REMOVE
00098 // cerr << "collect " << __LINE__ << " " << __FILE__; v.operator<<(cerr); cerr << endl;
00099         }
00100     }
00101     // TODO: unlock the list
00102 
00103     return 0; // no error
00104 }
00105 
00106 #include <w_strstream.h>
00107 
00108 /**\brief Collect into a virtual-table row the information about this thread
00109  * \details
00110  * The row attributes are described in \code "sthread_vtable_enum.h" \endcode.
00111  * The attributes are:
00112  * Thread id
00113  * Thread name
00114  * Thread status
00115  * + all the attributes generated by the stats Perl tool.
00116  */
00117 void        
00118 sthread_t::vtable_collect(vtable_row_t& t)  // argument MUST be named "t"
00119 {
00120     /* Convert sthread info to strings: */
00121 
00122     t.set_int(sthread_id_attr, id);
00123     t.set_string(sthread_name_attr, name() );
00124     t.set_string(sthread_status_attr,  sthread_t::status_strings[status()]);
00125 
00126 /* define TMP_GET_STAT to the get-stat macro for sthreads: */
00127 #define TMP_GET_STAT(x) SthreadStats.x
00128 #include "sthread_stats_collect_gen.cpp"
00129 }
00130 
00131 void 
00132 sthread_t::vtable_collect_names(vtable_row_t &t)
00133 {
00134     names_init.collect_names(t);
00135 }
00136 

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7