00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __UT_Performance__
00021 #define __UT_Performance__
00022
00023 #include "UT_API.h"
00024
00025 #include "UT_HashTable.h"
00026 #include "UT_PerfMonProfile.h"
00027 #include "UT_PerfMonTimedEvent.h"
00028 #include "UT_PerfMonTypes.h"
00029 #include "UT_RWLock.h"
00030 #include "UT_Color.h"
00031 #include "UT_Ramp.h"
00032 #include "UT_ThreadSpecificValue.h"
00033
00034 #define UT_PERFMON_INVALID_ID -1
00035
00036 enum UT_PerfMonProfileEventType
00037 {
00038 UT_PERFMON_PROFILE_STARTED,
00039 UT_PERFMON_PROFILE_STOPPED,
00040 UT_PERFMON_PROFILE_REMOVED,
00041 UT_PERFMON_PROFILE_RENAMED,
00042 UT_PERFMON_PROFILE_LOADED,
00043 UT_PERFMON_PROFILE_STATS_UPDATED,
00044 UT_PERFMON_PROFILE_RECORD_OPTIONS_CHANGED,
00045 UT_PERFMON_PROFILE_STATS_CLEARED,
00046 UT_PERFMON_ACTIVE_PROFILE_CHANGED,
00047 UT_PERFMON_NUM_PROFILE_EVENT_TYPES
00048 };
00049
00050 typedef void (*UT_PerfMonProfileEventMethod)
00051 (void *callee, UT_PerfMonProfileEventType type, int profile_id);
00052
00053 typedef void (*UT_PerfMonEventCB)
00054 (void *callee, const UT_PerfMonEvent *event);
00055
00056 class OP_Node;
00057 class SIM_Solver;
00058 class UT_NetSocket;
00059 class UT_PerfMonEvent;
00060 class UT_PerfMonProfile;
00061 class UT_PerfMonStats;
00062 class ut_PerfMonProfileInterest;
00063 class ut_PerfMonEventInterest;
00064
00065 class UT_API UT_Performance
00066 {
00067 public:
00068 UT_Performance();
00069 virtual ~UT_Performance();
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 int startTimedEvent(
00085 const char *event,
00086 const char *object,
00087 bool auto_nest_events=true);
00088 int startMemoryEvent(
00089 const char *object,
00090 bool auto_nest_events=true);
00091
00092
00093
00094
00095 int startTimedCookEvent(
00096 int node_id,
00097 const char *cook_event_name=NULL);
00098 int startMemoryCookEvent(
00099 int node_id,
00100 const char *cook_event_name=NULL);
00101
00102
00103
00104
00105 int startTimedSolveEvent(
00106 SIM_Solver *solver,
00107 const char *solver_event_name=NULL);
00108 int startMemorySolveEvent(
00109 SIM_Solver *solver,
00110 const char *solver_event_name=NULL);
00111
00112
00113
00114
00115
00116 int startTimedDrawEvent(
00117 const char *object,
00118 const char *draw_event_name,
00119 bool is_gpu_draw=false);
00120 int startMemoryDrawEvent(
00121 const char *object,
00122 const char *draw_event_name,
00123 bool is_gpu_draw=false);
00124
00125
00126
00127
00128
00129 int startTimedViewportDrawEvent(
00130 const char *viewport_name,
00131 const char *draw_event_name,
00132 UT_PerfMonViewportType viewport_type,
00133 bool is_gpu_draw=false);
00134 int startMemoryViewportDrawEvent(
00135 const char *viewport_name,
00136 const char *draw_event_name,
00137 UT_PerfMonViewportType viewport_type,
00138 bool is_gpu_draw=false);
00139
00140
00141
00142
00143
00144 void addTimedDrawEvent(
00145 const char *object,
00146 const char *draw_event_name,
00147 fpreal time,
00148 bool is_gpu_draw=false);
00149
00150
00151
00152
00153 int startTimedScriptEvent(
00154 const char *code_description,
00155 UT_PerfMonScriptType script_type,
00156 bool auto_nest_events=true);
00157 int startMemoryScriptEvent(
00158 const char *code_description,
00159 UT_PerfMonScriptType script_type,
00160 bool auto_nest_events=true);
00161
00162
00163
00164
00165 int startTimedRenderEvent(
00166 const char *renderer,
00167 const char *operation,
00168 bool is_renderer_a_node,
00169 int frame_num,
00170 const char *object=NULL);
00171 int startMemoryRenderEvent(
00172 const char *renderer,
00173 const char *operation,
00174 bool is_renderer_a_node,
00175 int frame_num,
00176 const char *object=NULL);
00177
00178
00179
00180
00181
00182 void addTimedRenderEvent(
00183 const char *object,
00184 bool is_renderer_a_node,
00185 int frame_num,
00186 fpreal time);
00187 void addMemoryRenderEvent(
00188 const char *object,
00189 bool is_renderer_a_node,
00190 int frame_num,
00191 fpreal value);
00192
00193
00194
00195
00196 int startTimedFrameEvent(fpreal frame);
00197 int startMemoryFrameEvent(fpreal frame);
00198
00199
00200
00201
00202
00203
00204 fpreal stopEvent(int event_id, bool return_value=false);
00205
00206
00207
00208 int startTimedNodeCreationEvent();
00209 int startMemoryNodeCreationEvent();
00210 void stopNodeCreationEvent(int event_id, int node_id);
00211
00212
00213
00214
00215 void cancelEvent(int event_id);
00216
00217
00218 void logMessage(const char *message);
00219
00220
00221
00222 const UT_PerfMonEvent *getEvent(int event_id) const;
00223
00224
00225
00226
00227 const UT_PerfMonTimedEvent *getTimedEvent(int event_id) const;
00228
00229
00230
00231
00232
00233 virtual int startTaskScope(const UT_TaskScope* task_scope);
00234
00235
00236
00237 virtual void stopTaskScope(
00238 const UT_TaskScope* task_scope,
00239 int event_id);
00240
00241
00242
00243
00244 int getEventListenPort() const;
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 int startProfile(
00255 const char *title,
00256 const UT_PerfMonRecordOptions *options=NULL);
00257
00258
00259
00260 void stopProfile(int profile_id);
00261
00262
00263
00264 void cancelProfile(int profile_id);
00265
00266
00267
00268
00269 void pauseProfile(int profile_id);
00270
00271
00272
00273
00274 void resumeProfile(int profile_id);
00275
00276
00277
00278 int loadProfile(
00279 const char *file_path,
00280 UT_StringArray &errors);
00281
00282
00283
00284 void removeProfile(int profile_id);
00285
00286
00287 void renameProfile(
00288 int profile_id,
00289 const char *profile_name);
00290
00291
00292 void changeProfileRecordOptions(
00293 int profile_id,
00294 const UT_PerfMonRecordOptions &options);
00295
00296
00297
00298 void updateProfileStats(int profile_id);
00299
00300
00301 void clearProfileStats(int profile_id);
00302
00303
00304
00305 const UT_PerfMonProfile *getProfile(int profile_id) const;
00306
00307
00308
00309 int getActiveProfileId() const
00310 { return myActiveProfileId; }
00311
00312
00313 void setActiveProfileId(int profile_id);
00314
00315
00316
00317
00318 int numCompletedProfiles() const;
00319
00320
00321
00322
00323 const UT_PerfMonProfile *getCompletedProfile(int index) const;
00324
00325
00326
00327 void addProfileInterest(
00328 void *callee,
00329 UT_PerfMonProfileEventMethod callback);
00330
00331
00332
00333 void removeProfileInterest(
00334 void *callee,
00335 UT_PerfMonProfileEventMethod callback);
00336
00337
00338
00339 bool hasProfileInterest(
00340 void *callee,
00341 UT_PerfMonProfileEventMethod callback);
00342
00343
00344
00345
00346 void addEventInterest(
00347 void *callee,
00348 UT_PerfMonEventCB callback,
00349 const UT_PerfMonRecordOptions &options);
00350
00351
00352 void changeEventInterestRecordOptions(
00353 void *callee,
00354 UT_PerfMonEventCB callback,
00355 const UT_PerfMonRecordOptions &options);
00356
00357
00358 void removeEventInterest(
00359 void *callee,
00360 UT_PerfMonEventCB callback);
00361
00362
00363
00364 bool hasEventInterest(
00365 void *callee,
00366 UT_PerfMonEventCB callback);
00367
00368
00369
00370 int createDiffProfile(int id1, int id2);
00371
00372
00373
00374
00375
00376
00377
00378 bool isRecording() const
00379 { return myIsRecordingCount > 0
00380 || getDisplayNodeInfo(); }
00381
00382
00383 bool isRecordingCookStats() const
00384 { return myRecordCookStatsCount > 0
00385 || getDisplayNodeInfo(); }
00386
00387
00388 bool isRecordingSolveStats() const
00389 { return myRecordSolveStatsCount > 0; }
00390
00391
00392 bool isRecordingObjectDrawStats() const
00393 { return myRecordObjectDrawStatsCount > 0; }
00394
00395
00396 bool isRecordingObjectGPUDrawStats() const
00397 { return myRecordObjectGPUDrawStatsCount > 0; }
00398
00399
00400 bool isRecordingViewportStats() const
00401 { return myRecordViewportStatsCount > 0; }
00402
00403
00404 bool isRecordingScriptStats() const
00405 { return myRecordScriptStatsCount > 0; }
00406
00407
00408 bool isRecordingRenderStats() const
00409 { return myRecordRenderStatsCount > 0; }
00410
00411
00412 bool isRecordingThreadStats() const
00413 { return myRecordThreadStatsCount > 0; }
00414
00415
00416 bool isRecordingFrameStats() const
00417 { return myRecordFrameStatsCount > 0; }
00418
00419
00420 bool isRecordingMemoryStats() const
00421 { return myRecordMemoryStatsCount > 0; }
00422
00423
00424 bool isRecordingErrors() const
00425 { return myRecordErrorsCount > 0; }
00426
00427
00428
00429
00430
00431
00432
00433 int getNumRecordedTimedFrameEvents() const
00434 { return myTimedFrameEventCounter; }
00435
00436
00437
00438 int getNumRecordedMemoryFrameEvents() const
00439 { return myMemoryFrameEventCounter; }
00440
00441
00442
00443 fpreal getTotalRecordedFrameEventTime() const
00444 { return myTotalFrameTime; }
00445
00446
00447
00448 fpreal getTotalRecordedFrameEventMemory() const
00449 { return myTotalFrameMemory; }
00450
00451
00452 void resetCumulativeFrameStats();
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 virtual const char *getStatsIcon(const UT_PerfMonStats *stats) const;
00463
00464
00465
00466
00467
00468
00469
00470 void setDisplayNodeInfo(bool display);
00471 bool getDisplayNodeInfo() const
00472 { return myDisplayNodeInfo; }
00473
00474
00475
00476 void getPerformanceColor(fpreal pos, UT_Color &c);
00477
00478
00479 const UT_Ramp &getRampColorScheme() const;
00480
00481
00482 void setRampColorScheme(const UT_Ramp &src_ramp);
00483
00484
00485 void loadRampColorScheme(const char *str_color_scheme);
00486
00487
00488 void saveRampColorScheme(UT_String &str_color_scheme);
00489
00490
00491 static const UT_Ramp &getDefaultRampColorScheme();
00492
00493
00494
00495
00496
00497
00498
00499
00500 void reset();
00501
00502 protected:
00503
00504
00505 virtual int getCurrentFrameSubclass_();
00506
00507
00508 virtual OP_Node *getNodeSubclass_(int node_id) const;
00509
00510
00511 virtual OP_Node *getNodeFromSolverSubclass_(
00512 SIM_Solver *solver) const;
00513
00514
00515
00516 virtual void getObjectPathFromNodeSubclass_(
00517 OP_Node *node, const char *event_name,
00518 UT_String &object_path) const;
00519
00520
00521
00522 virtual void getObjectPathFromSolverAndNodeSubclass_(
00523 SIM_Solver *solver, OP_Node *node,
00524 const char *event_name, UT_String &object_path)
00525 const;
00526
00527
00528
00529 virtual void getExtraInfoFromNodeSubclass_(
00530 OP_Node *node, UT_String &extra_info) const;
00531
00532 private:
00533
00534 int newEventId_();
00535 int newProfileId_();
00536
00537
00538
00539
00540
00541 UT_PerfMonTimedEvent *getTimedEvent_(int event_id) const;
00542
00543
00544
00545 UT_PerfMonEvent *getEvent_(int event_id) const;
00546
00547
00548
00549 int startEvent_(
00550 const char *event,
00551 const char *object,
00552 bool auto_nest_events,
00553 UT_PerfMonCategory category,
00554 UT_PerfMonEventType type,
00555 UT_PerfMonObjectType object_type,
00556 const char *object_icon,
00557 int *frame_num=NULL,
00558 const char *extra_info=NULL);
00559
00560
00561 int startCookEvent_(
00562 UT_PerfMonEventType type,
00563 int node_id, const char *cook_event_name);
00564
00565
00566 int startSolveEvent_(
00567 UT_PerfMonEventType type,
00568 SIM_Solver *solver,
00569 const char *solver_event_name);
00570
00571
00572 int startDrawEvent_(
00573 UT_PerfMonEventType type,
00574 const char *object,
00575 const char *draw_event_name,
00576 bool is_gpu_draw);
00577
00578
00579 int startViewportDrawEvent_(
00580 UT_PerfMonEventType type,
00581 const char *viewport_name,
00582 const char *draw_event_name,
00583 UT_PerfMonViewportType viewport_type,
00584 bool is_gpu_draw);
00585
00586
00587 int startGenericDrawEvent_(
00588 UT_PerfMonEventType type,
00589 const char *object,
00590 const char *draw_event_name,
00591 UT_PerfMonObjectType object_type,
00592 const char *object_icon,
00593 bool is_gpu_draw);
00594
00595
00596 int startScriptEvent_(
00597 UT_PerfMonEventType type,
00598 const char *code_description,
00599 UT_PerfMonScriptType script_type,
00600 bool auto_nest_events);
00601
00602
00603 int startRenderEvent_(
00604 UT_PerfMonEventType type,
00605 const char *renderer,
00606 const char *operation,
00607 bool is_renderer_a_node,
00608 int frame_num,
00609 const char *object);
00610
00611
00612
00613 UT_PerfMonProfile *getProfile_(int profile_id) const;
00614
00615
00616 void activateProfile_(UT_PerfMonProfile *profile);
00617
00618
00619 void deactivateProfile_(UT_PerfMonProfile *profile);
00620
00621
00622 void incrementRecordingCounters_(
00623 const UT_PerfMonRecordOptions &options);
00624
00625
00626 void decrementRecordingCounters_(
00627 const UT_PerfMonRecordOptions &options);
00628
00629
00630 void removeProfile_(UT_PerfMonProfile *profile);
00631
00632
00633 void removeEvent_(
00634 int event_id,
00635 UT_PerfMonEvent *event,
00636 bool is_cancelled=false);
00637
00638
00639 void updateProfileStats_(UT_PerfMonProfile *profile);
00640
00641
00642
00643 void findAndLinkToRunningParentEvent_(
00644 UT_PerfMonEvent *event);
00645
00646 UT_PerfMonEvent *findRunningParentEvent_(
00647 const UT_TaskScope *task,
00648 bool for_memory_event,
00649 bool require_auto_nest);
00650
00651
00652
00653
00654 UT_PerfMonEventList *getOrCreateRunningEventList_(
00655 const UT_TaskScope *task,
00656 bool for_memory_event);
00657
00658
00659
00660
00661 UT_PerfMonEventList *getRunningEventList_(
00662 const UT_TaskScope *task,
00663 bool for_memory_event) const;
00664
00665
00666
00667
00668 void removeFromRunningEventList_(
00669 const UT_TaskScope *task,
00670 UT_PerfMonEvent *event);
00671
00672
00673
00674 void addToRunningEventList_(
00675 const UT_TaskScope *task,
00676 UT_PerfMonEvent *event);
00677
00678
00679 void resetRunningEventLists_();
00680
00681
00682
00683 int addEventToProfiles_(UT_PerfMonEvent *event);
00684
00685
00686
00687 int findProfileInterest_(void *callee,
00688 UT_PerfMonProfileEventMethod callback) const;
00689
00690
00691 void notifyProfileInterests_(
00692 UT_PerfMonProfileEventType event_type,
00693 int profile_id) const;
00694
00695
00696
00697 int findEventInterest_(void *callee,
00698 UT_PerfMonEventCB callback) const;
00699
00700
00701 void notifyEventInterests_(
00702 const UT_PerfMonEvent *event) const;
00703
00704
00705 UT_RWLock &getRunningEventsLock_(
00706 const UT_TaskScope *task,
00707 bool for_memory_event);
00708
00709
00710
00711 bool areOptionsInterestedInEvent_(
00712 const UT_PerfMonRecordOptions &options,
00713 const UT_PerfMonEvent *event) const;
00714
00715
00716
00717 void addToCumulativeFrameStats_(
00718 fpreal frame_value, bool is_memory_value);
00719
00720
00721
00722 void initAndStartEventListenThread_();
00723
00724
00725 int myActiveProfileId;
00726
00727
00728
00729 bool myDisplayNodeInfo;
00730
00731 UT_Ramp myColorsRamp;
00732
00733
00734 int myEventIdCounter;
00735 UT_HashTable myEvents;
00736
00737
00738 int myProfileIdCounter;
00739 UT_HashTable myProfiles;
00740 UT_PerfMonProfileList myRecordingProfiles;
00741 UT_PerfMonProfileList myCompletedProfiles;
00742
00743
00744
00745
00746 mutable UT_RWLock myEventsLock;
00747 mutable UT_RWLock myProfilesLock;
00748 mutable UT_RWLock myProfileInterestsLock;
00749 mutable UT_RWLock myEventInterestsLock;
00750
00751
00752 UT_ThreadSpecificValue<UT_HashTable*> myTasksToRunningTimedEvents;
00753 UT_ThreadSpecificValue<UT_RWLock> myTasksToRunningTimedEventsLock;
00754
00755
00756 UT_ThreadSpecificValue<UT_HashTable*> myTasksToRunningMemoryEvents;
00757 UT_ThreadSpecificValue<UT_RWLock> myTasksToRunningMemoryEventsLock;
00758
00759
00760 UT_PtrArray<ut_PerfMonProfileInterest *> myProfileInterests;
00761
00762
00763 UT_PtrArray<ut_PerfMonEventInterest *> myEventInterests;
00764
00765
00766
00767 UT_NetSocket *myEventSocket;
00768 UT_Thread *myEventListenThread;
00769
00770
00771 int myIsRecordingCount;
00772 int myRecordCookStatsCount;
00773 int myRecordSolveStatsCount;
00774 int myRecordObjectDrawStatsCount;
00775 int myRecordObjectGPUDrawStatsCount;
00776 int myRecordViewportStatsCount;
00777 int myRecordScriptStatsCount;
00778 int myRecordRenderStatsCount;
00779 int myRecordThreadStatsCount;
00780 int myRecordFrameStatsCount;
00781 int myRecordMemoryStatsCount;
00782 int myRecordErrorsCount;
00783
00784
00785 fpreal myTotalFrameTime;
00786 fpreal myTotalFrameMemory;
00787 int myTimedFrameEventCounter;
00788 int myMemoryFrameEventCounter;
00789 };
00790
00791 UT_API UT_Performance *UTgetPerformance(bool create=true);
00792 UT_API void UTsetPerformance(UT_Performance *perfmon);
00793
00794 #endif
00795