00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PLOTLOGGER_H_
00028 #define PLOTLOGGER_H_
00029
00030 #include <graphics/GenericPlotter/PlotOptions.h>
00031
00032 #include <casa/Logging/LogSinkInterface.h>
00033 #include <casa/Utilities/CountedPtr.h>
00034
00035 #include <map>
00036 #include <time.h>
00037 #include <vector>
00038
00039 namespace casa {
00040
00041
00042 class PlotCanvas;
00043 class Plotter;
00044
00045
00046
00047
00048 class PlotLogMessage : public LogMessage {
00049 public:
00050
00051
00052
00053 static const int DEFAULT_EVENT_TYPE;
00054
00055
00056
00057
00058
00059 PlotLogMessage(int eventType = DEFAULT_EVENT_TYPE);
00060
00061
00062 PlotLogMessage(const String& origin1, const String& origin2,
00063 int eventType = DEFAULT_EVENT_TYPE);
00064
00065
00066
00067 PlotLogMessage(const String& origin1, const String& origin2,
00068 const String& message, int eventType = DEFAULT_EVENT_TYPE);
00069
00070
00071 PlotLogMessage(const PlotLogMessage& copy);
00072
00073
00074 virtual ~PlotLogMessage();
00075
00076
00077
00078 virtual int eventType() const;
00079
00080 protected:
00081
00082
00083 int m_eventType;
00084 };
00085
00086
00087
00088
00089
00090
00091
00092 class PlotLogMeasurement : public PlotLogMessage {
00093 public:
00094
00095
00096
00097
00098 enum TimeUnit {
00099 SECOND
00100 };
00101
00102
00103 enum MemoryUnit {
00104 BYTE, KILOBYTE, MEGABYTE
00105 };
00106
00107
00108
00109 static const TimeUnit DEFAULT_TIME_UNIT;
00110 static const MemoryUnit DEFAULT_MEMORY_UNIT;
00111
00112
00113
00114
00115 static String timeUnits(TimeUnit t);
00116 static String memoryUnits(MemoryUnit m);
00117
00118
00119
00120
00121
00122
00123
00124 PlotLogMeasurement(const String& origin1, const String& origin2,
00125 TimeUnit timeUnit = DEFAULT_TIME_UNIT,
00126 MemoryUnit memoryUnit = DEFAULT_MEMORY_UNIT,
00127 int eventType = DEFAULT_EVENT_TYPE);
00128
00129
00130 PlotLogMeasurement(const PlotLogMeasurement& copy);
00131
00132
00133 ~PlotLogMeasurement();
00134
00135
00136
00137
00138 time_t startTime() const;
00139 unsigned int startMemory() const;
00140
00141
00142
00143
00144
00145
00146 double time() const;
00147 double memory() const;
00148
00149
00150
00151
00152 TimeUnit timeUnit() const;
00153 MemoryUnit memoryUnit() const;
00154
00155
00156
00157
00158
00159 void startMeasurement();
00160
00161
00162
00163 void stopMeasurement();
00164
00165 private:
00166
00167 time_t m_startTime;
00168
00169
00170 unsigned int m_startMemory;
00171
00172
00173 double m_time, m_memory;
00174
00175
00176 TimeUnit m_timeUnit;
00177
00178
00179 MemoryUnit m_memoryUnit;
00180 };
00181
00182
00183
00184
00185 class PlotLogLocate : public PlotLogMessage {
00186 public:
00187
00188
00189
00190
00191 static PlotLogLocate canvasLocate(PlotCanvas* canvas,
00192 const PlotRegion& region);
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 PlotLogLocate(const String& origin1, const String& origin2,
00204 const PlotRegion& locateRegion,
00205 std::vector<std::vector<std::pair<unsigned int,unsigned int> > >* locatedIndices,
00206 int eventType = DEFAULT_EVENT_TYPE,
00207 bool deleteIndicesOnDestruction = true);
00208
00209
00210
00211
00212 PlotLogLocate(const PlotLogLocate& copy);
00213
00214
00215 ~PlotLogLocate();
00216
00217
00218
00219 const PlotRegion& locateRegion() const;
00220
00221
00222 unsigned int numLocatedIndices() const;
00223
00224
00225 unsigned int numSearchedPlots() const;
00226
00227
00228 std::vector<std::vector<std::pair<unsigned int, unsigned int> > >* indices() const;
00229
00230
00231
00232 std::vector<std::pair<unsigned int, unsigned int> >* plotIndices(
00233 unsigned int index) const;
00234
00235
00236
00237 bool willDeleteIndices() const;
00238
00239 private:
00240
00241 PlotRegion m_region;
00242
00243
00244 std::vector<std::vector<std::pair<unsigned int, unsigned int> > >* m_indices;
00245
00246
00247 bool m_shouldDelete;
00248 };
00249
00250
00251
00252 class PlotLogMethod : public PlotLogMessage {
00253 public:
00254
00255
00256
00257 PlotLogMethod(const String& className, const String& methodName,
00258 bool entering, const String& message = String(),
00259 int eventType = DEFAULT_EVENT_TYPE);
00260
00261
00262 ~PlotLogMethod();
00263 };
00264
00265
00266
00267 class PlotLogObject : public PlotLogMessage {
00268 public:
00269
00270
00271
00272 PlotLogObject(const String& className, void* address, bool creation,
00273 const String& message = String(),
00274 int eventType = DEFAULT_EVENT_TYPE);
00275
00276
00277 ~PlotLogObject();
00278 };
00279
00280
00281
00282
00283 class PlotLoggerFilter : public LogFilterInterface {
00284 public:
00285
00286 PlotLoggerFilter(int eventFlags, LogMessage::Priority minPriority);
00287
00288
00289 ~PlotLoggerFilter();
00290
00291
00292 LogFilterInterface* clone() const;
00293
00294
00295 Bool pass(const LogMessage& message) const;
00296
00297
00298
00299 int eventFlags() const;
00300 void setEventFlags(int flags);
00301
00302
00303
00304
00305 LogMessage::Priority minimumPriority() const;
00306 void setMinimumPriority(LogMessage::Priority minPriority);
00307
00308
00309 private:
00310
00311 int m_eventFlags;
00312
00313
00314 LogMessage::Priority m_minPriority;
00315 };
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 class PlotLogger {
00329 public:
00330
00331
00332
00333
00334
00335
00336 static const int MSG_INFO = -1;
00337 static const int MSG_WARN = -2;
00338 static const int MSG_ERROR = -3;
00339
00340
00341
00342 static const int MSG_DEBUG = 1;
00343
00344
00345 static const int DRAW_TOTAL = 2;
00346
00347
00348 static const int DRAW_INDIVIDUAL = 4;
00349
00350
00351 static const int METHODS_MAJOR = 8;
00352
00353
00354 static const int OBJECTS_MAJOR = 16;
00355
00356
00357 static const int EXPORT_TOTAL = 32;
00358
00359
00360
00361 static const int NO_EVENTS = 0;
00362
00363
00364 static int ALL_EVENTS_FLAG();
00365
00366
00367 static std::vector<int> ALL_EVENTS();
00368
00369
00370
00371
00372 static int REGISTER_EVENT_TYPE(const String& name,
00373 LogMessage::Priority priority = LogMessage::NORMAL);
00374
00375
00376
00377
00378 static void UNREGISTER_EVENT_TYPE(int event);
00379 static void UNREGISTER_EVENT_TYPE(const String& name);
00380
00381
00382
00383 static std::vector<String> EVENT_NAMES();
00384
00385
00386
00387 static String EVENT(int type);
00388 static int EVENT(const String& name);
00389
00390
00391
00392
00393 static int FLAG_FROM_EVENTS(const std::vector<int>& events);
00394 static int FLAG_FROM_EVENTS(const std::vector<String>& names);
00395
00396
00397
00398
00399 static int FLAG_FROM_PRIORITY(LogMessage::Priority minPriority);
00400
00401
00402
00403
00404
00405 static LogMessage::Priority EVENT_PRIORITY(int event);
00406 static void SET_EVENT_PRIORITY(int event, LogMessage::Priority priority);
00407
00408
00409
00410
00411
00412 static void disableGlobalSink();
00413
00414
00415 static void enableGlobalSink();
00416
00417
00418
00419
00420
00421
00422 PlotLogger(Plotter* plotter, int filterEventFlags = NO_EVENTS,
00423 LogMessage::Priority filterMinPriority = LogMessage::DEBUGGING);
00424
00425
00426 virtual ~PlotLogger();
00427
00428
00429
00430
00431
00432
00433 CountedPtr<LogSinkInterface> sink();
00434 const CountedPtr<LogSinkInterface> sink() const;
00435
00436
00437
00438 LogSinkInterface* localSinkCopy() const;
00439
00440
00441
00442
00443 const String& sinkLocation() const;
00444 void setSinkLocation(const String& logFile);
00445
00446
00447
00448
00449 bool usingGlobalSink() const { return sinkLocation().empty(); }
00450
00451
00452
00453
00454
00455
00456 LogMessage::Priority filterMinPriority() const;
00457 void setFilterMinPriority(PlotLogMessage::Priority minPriority);
00458
00459
00460
00461
00462 bool filterEventFlag(int flag) const;
00463 void setFilterEventFlag(int flag, bool on);
00464
00465
00466
00467
00468
00469 int filterEventFlags() const;
00470 void setFilterEventFlags(int flags);
00471
00472
00473
00474
00475
00476
00477
00478 void postMessage(const PlotLogMessage& message);
00479 void postMessage(const String& origin1, const String& origin2,
00480 const String& message,
00481 int eventType = PlotLogMessage::DEFAULT_EVENT_TYPE);
00482
00483
00484
00485
00486
00487
00488
00489
00490 PlotLogMessage markMeasurement(const String& origin1,const String& origin2,
00491 int eventType = PlotLogMessage::DEFAULT_EVENT_TYPE,
00492 bool postStartMessage = true);
00493
00494
00495
00496 PlotLogMeasurement releaseMeasurement(bool postReleaseMessage = true);
00497
00498
00499
00500
00501
00502
00503 PlotLogLocate locate(PlotCanvas* canvas, const PlotRegion& region,
00504 int eventType = MSG_INFO, bool postLocateMessage = true);
00505
00506 private:
00507
00508 Plotter* m_plotter;
00509
00510
00511 CountedPtr<LogSinkInterface> m_logger;
00512
00513
00514 PlotLoggerFilter m_filter;
00515
00516
00517 String m_loggerLocation;
00518
00519
00520 std::vector<PlotLogMeasurement> m_measurements;
00521
00522
00523
00524
00525
00526 static std::vector<int> EXTENDED_TYPES;
00527
00528
00529 static std::vector<String> EXTENDED_NAMES;
00530
00531
00532 static std::map<int, LogMessage::Priority> EVENT_PRIORITIES;
00533
00534
00535 static LogFilterInterface* DISABLED_GLOBAL_FILTER;
00536 };
00537 typedef CountedPtr<PlotLogger> PlotLoggerPtr;
00538
00539 }
00540
00541 #endif