ProfilerDatabase.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef ProfilerDatabase_h
  26. #define ProfilerDatabase_h
  27. #if !ENABLE(DETACHED_JIT)
  28. #include "JSCJSValue.h"
  29. #include "ProfilerBytecodes.h"
  30. #include "ProfilerCompilation.h"
  31. #include "ProfilerCompilationKind.h"
  32. #include <wtf/FastAllocBase.h>
  33. #include <wtf/HashMap.h>
  34. #include <wtf/Noncopyable.h>
  35. #include <wtf/PassRefPtr.h>
  36. #include <wtf/SegmentedVector.h>
  37. #include <wtf/text/WTFString.h>
  38. namespace JSC { namespace Profiler {
  39. class Database {
  40. WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(Database);
  41. public:
  42. JS_EXPORT_PRIVATE Database(VM&);
  43. JS_EXPORT_PRIVATE ~Database();
  44. int databaseID() const { return m_databaseID; }
  45. Bytecodes* ensureBytecodesFor(CodeBlock*);
  46. void notifyDestruction(CodeBlock*);
  47. PassRefPtr<Compilation> newCompilation(CodeBlock*, CompilationKind);
  48. PassRefPtr<Compilation> newCompilation(Bytecodes*, CompilationKind);
  49. // Converts the database to a JavaScript object that is suitable for JSON stringification.
  50. // Note that it's probably a good idea to use an ExecState* associated with a global
  51. // object that is "clean" - i.e. array and object prototypes haven't had strange things
  52. // done to them. And yes, it should be appropriate to just use a globalExec here.
  53. JS_EXPORT_PRIVATE JSValue toJS(ExecState*) const;
  54. // Converts the database to a JavaScript object using a private temporary global object,
  55. // and then returns the JSON representation of that object.
  56. JS_EXPORT_PRIVATE String toJSON() const;
  57. // Saves the JSON representation (from toJSON()) to the given file. Returns false if the
  58. // save failed.
  59. JS_EXPORT_PRIVATE bool save(const char* filename) const;
  60. void registerToSaveAtExit(const char* filename);
  61. private:
  62. void addDatabaseToAtExit();
  63. void removeDatabaseFromAtExit();
  64. void performAtExitSave() const;
  65. static Database* removeFirstAtExitDatabase();
  66. static void atExitCallback();
  67. int m_databaseID;
  68. VM& m_vm;
  69. SegmentedVector<Bytecodes> m_bytecodes;
  70. HashMap<CodeBlock*, Bytecodes*> m_bytecodesMap;
  71. Vector<RefPtr<Compilation> > m_compilations;
  72. bool m_shouldSaveAtExit;
  73. CString m_atExitSaveFilename;
  74. Database* m_nextRegisteredDatabase;
  75. };
  76. } } // namespace JSC::Profiler
  77. #endif // #if !ENABLE(DETACHED_JIT)
  78. #endif // ProfilerDatabase_h