InspectorProfilerAgent.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 Google Inc. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef InspectorProfilerAgent_h
  30. #define InspectorProfilerAgent_h
  31. #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
  32. #include "InspectorBaseAgent.h"
  33. #include "InspectorFrontend.h"
  34. #include <wtf/Forward.h>
  35. #include <wtf/HashMap.h>
  36. #include <wtf/Noncopyable.h>
  37. #include <wtf/PassOwnPtr.h>
  38. #include <wtf/text/WTFString.h>
  39. namespace WebCore {
  40. class InjectedScriptManager;
  41. class InspectorArray;
  42. class InspectorConsoleAgent;
  43. class InspectorFrontend;
  44. class InspectorObject;
  45. class InspectorState;
  46. class InstrumentingAgents;
  47. class Page;
  48. class ScriptHeapSnapshot;
  49. class ScriptProfile;
  50. class WorkerContext;
  51. typedef String ErrorString;
  52. class InspectorProfilerAgent : public InspectorBaseAgent<InspectorProfilerAgent>, public InspectorBackendDispatcher::ProfilerCommandHandler {
  53. WTF_MAKE_NONCOPYABLE(InspectorProfilerAgent); WTF_MAKE_FAST_ALLOCATED;
  54. public:
  55. static PassOwnPtr<InspectorProfilerAgent> create(InstrumentingAgents*, InspectorConsoleAgent*, Page*, InspectorCompositeState*, InjectedScriptManager*);
  56. #if ENABLE(WORKERS)
  57. static PassOwnPtr<InspectorProfilerAgent> create(InstrumentingAgents*, InspectorConsoleAgent*, WorkerContext*, InspectorCompositeState*, InjectedScriptManager*);
  58. #endif
  59. virtual ~InspectorProfilerAgent();
  60. void addProfile(PassRefPtr<ScriptProfile> prpProfile, unsigned lineNumber, unsigned columnNumber, const String& sourceURL);
  61. void addProfileFinishedMessageToConsole(PassRefPtr<ScriptProfile>, unsigned lineNumber, unsigned columnNumber, const String& sourceURL);
  62. void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, unsigned columnNumber, const String& sourceURL);
  63. virtual void collectGarbage(ErrorString*);
  64. virtual void clearProfiles(ErrorString*) { resetState(); }
  65. void resetState();
  66. virtual void causesRecompilation(ErrorString*, bool*);
  67. virtual void recompileScript() = 0;
  68. virtual void isSampling(ErrorString*, bool*);
  69. virtual void hasHeapProfiler(ErrorString*, bool*);
  70. virtual void enable(ErrorString*);
  71. virtual void disable(ErrorString*);
  72. virtual void start(ErrorString* = 0);
  73. virtual void stop(ErrorString* = 0);
  74. void disable();
  75. void enable(bool skipRecompile);
  76. bool enabled() { return m_enabled; }
  77. String getCurrentUserInitiatedProfileName(bool incrementProfileNumber = false);
  78. virtual void getProfileHeaders(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Profiler::ProfileHeader> >&);
  79. virtual void getCPUProfile(ErrorString*, int uid, RefPtr<TypeBuilder::Profiler::CPUProfile>&);
  80. virtual void getHeapSnapshot(ErrorString*, int uid);
  81. virtual void removeProfile(ErrorString*, const String& type, int uid);
  82. virtual void setFrontend(InspectorFrontend*);
  83. virtual void clearFrontend();
  84. virtual void restore();
  85. virtual void takeHeapSnapshot(ErrorString*, const bool* reportProgress);
  86. void toggleRecordButton(bool isProfiling);
  87. virtual void getObjectByHeapObjectId(ErrorString*, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result);
  88. virtual void getHeapObjectId(ErrorString*, const String& objectId, String* heapSnapshotObjectId);
  89. void willProcessTask();
  90. void didProcessTask();
  91. protected:
  92. InspectorProfilerAgent(InstrumentingAgents*, InspectorConsoleAgent*, InspectorCompositeState*, InjectedScriptManager*);
  93. virtual void startProfiling(const String& title) = 0;
  94. virtual PassRefPtr<ScriptProfile> stopProfiling(const String& title) = 0;
  95. private:
  96. typedef HashMap<unsigned int, RefPtr<ScriptProfile> > ProfilesMap;
  97. typedef HashMap<unsigned int, RefPtr<ScriptHeapSnapshot> > HeapSnapshotsMap;
  98. void resetFrontendProfiles();
  99. void restoreEnablement();
  100. PassRefPtr<TypeBuilder::Profiler::ProfileHeader> createProfileHeader(const ScriptProfile&);
  101. PassRefPtr<TypeBuilder::Profiler::ProfileHeader> createSnapshotHeader(const ScriptHeapSnapshot&);
  102. InspectorConsoleAgent* m_consoleAgent;
  103. InjectedScriptManager* m_injectedScriptManager;
  104. InspectorFrontend::Profiler* m_frontend;
  105. bool m_enabled;
  106. bool m_recordingCPUProfile;
  107. int m_currentUserInitiatedProfileNumber;
  108. unsigned m_nextUserInitiatedProfileNumber;
  109. unsigned m_nextUserInitiatedHeapSnapshotNumber;
  110. ProfilesMap m_profiles;
  111. HeapSnapshotsMap m_snapshots;
  112. typedef HashMap<String, double> ProfileNameIdleTimeMap;
  113. ProfileNameIdleTimeMap* m_profileNameIdleTimeMap;
  114. double m_previousTaskEndTime;
  115. };
  116. } // namespace WebCore
  117. #endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
  118. #endif // !defined(InspectorProfilerAgent_h)