Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / utils / monitor / monitor_client.cpp
blobcc9999e14f0f2ef443b433c91d6045f2f5400c5b
1 #include "ace/streams.h"
2 #include "ace/OS_NS_unistd.h"
3 #include "ace/Get_Opt.h"
5 #include "tao/Strategies/advanced_resource.h"
6 #include "tao/Monitor/Monitor.h"
8 const ACE_TCHAR *monitor_ior = ACE_TEXT ("file://monitor.ior");
9 ::Monitor::NameList* monitor_point = 0;
10 bool mp_clear = false;
11 int n_iterations = 1;
12 ACE_Time_Value sleep_time = ACE_Time_Value (1);
13 const ACE_TCHAR * filter = ACE_TEXT ("");
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:p:ci:s:f:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'f':
25 filter = get_opts.opt_arg ();
26 break;
27 case 'k':
28 monitor_ior = get_opts.opt_arg ();
29 break;
30 case 'p':
32 if (monitor_point == 0)
34 ACE_NEW_THROW_EX (monitor_point,
35 ::Monitor::NameList,
36 CORBA::NO_MEMORY ());
39 monitor_point->length (monitor_point->length () + 1);
40 (*monitor_point)[monitor_point->length () - 1] =
41 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ()));
42 break;
44 case 'c':
45 mp_clear = true;
46 break;
47 case 'i':
48 n_iterations = ACE_OS::atoi (get_opts.opt_arg ());
49 break;
50 case 's':
51 sleep_time.set(ACE_OS::atoi (get_opts.opt_arg ()), 0);
52 break;
53 case '?':
54 default:
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "usage: %s "
57 "-k <ior> "
58 "-p <point> "
59 "-i <iterations> "
60 "-c clear "
61 "-s <sleeptime> "
62 "-f <filter> "
63 "\n",
64 argv [0]),
65 -1);
68 // Indicates successful parsing of the command line
69 return 0;
73 int
74 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
76 try
78 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
80 if (parse_args (argc, argv) != 0)
82 return 1;
85 /// Get the MC object reference that the client has exposed.
86 CORBA::Object_var obj =
87 orb->string_to_object (monitor_ior);
89 if (CORBA::is_nil (obj.in ()))
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "Monitor client - string_to_object failed\n"),
93 -1);
96 Monitor::MC_var monitor = Monitor::MC::_narrow (obj.in ());
98 if (CORBA::is_nil (monitor.in ()))
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "Monitor client - narrow failed\n"),
102 -1);
105 if (monitor_point != 0)
107 /// Access the monitor's value a few times and watch it grow.
108 for (int i = 0; i < n_iterations; ++i)
110 Monitor::DataList_var data;
112 if (mp_clear)
114 data = monitor->get_and_clear_statistics (*monitor_point);
116 else
118 data = monitor->get_statistics (*monitor_point);
121 for (CORBA::ULong index = 0; index < data->length (); ++index)
123 ACE_DEBUG ((LM_DEBUG, "MP <%C>:\n", data[index].itemname.in ()));
124 Monitor::Data dlist = data[index];
126 if (dlist.data_union._d() == Monitor::DATA_TEXT)
128 for (CORBA::ULong valueindex = 0;
129 valueindex < dlist.data_union.num().dlist.length ();
130 ++valueindex)
132 Monitor::DataValue d = dlist.data_union.num().dlist[valueindex];
133 ACE_DEBUG ((LM_DEBUG, "\t value <%A>:\n", d.value));
138 ACE_OS::sleep (sleep_time);
141 else
143 Monitor::NameList_var list = monitor->get_statistic_names (ACE_TEXT_ALWAYS_CHAR (filter));
145 for (CORBA::ULong index = 0; index < list->length (); ++index)
147 ACE_DEBUG ((LM_DEBUG, "MP: <%C>\n", list[index].in ()));
151 orb->destroy ();
153 catch (const CORBA::Exception &ex)
155 ex._tao_print_exception ("Monitor_client: Exception caught:");
156 return 1;
159 return 0;