|
3 | 3 | #include <cassert> |
4 | 4 | #include "include/libplatform/libplatform.h" |
5 | 5 | #include "include/v8-inspector.h" |
| 6 | +#include "include/v8-profiler.h" |
6 | 7 | #include "include/v8.h" |
7 | 8 | #include "src/api/api.h" |
8 | 9 | #include "src/inspector/protocol/Runtime.h" |
@@ -1728,6 +1729,57 @@ void v8__base__SetDcheckFunction(void (*func)(const char*, int, const char*)) { |
1728 | 1729 | v8::base::SetDcheckFunction(func); |
1729 | 1730 | } |
1730 | 1731 |
|
| 1732 | +// CpuProfiler |
| 1733 | +// ----------- |
| 1734 | + |
| 1735 | +v8::CpuProfiler* v8__CpuProfiler__Get(v8::Isolate* isolate) { |
| 1736 | + return v8::CpuProfiler::New(isolate); |
| 1737 | +} |
| 1738 | + |
| 1739 | +void v8__CpuProfiler__StartProfiling(v8::CpuProfiler* self, const v8::String& title) { |
| 1740 | + self->StartProfiling(ptr_to_local(&title), true); |
| 1741 | +} |
| 1742 | + |
| 1743 | +const v8::CpuProfile* v8__CpuProfiler__StopProfiling(v8::CpuProfiler* self, const v8::String& title) { |
| 1744 | + return self->StopProfiling(ptr_to_local(&title)); |
| 1745 | +} |
| 1746 | + |
| 1747 | +void v8__CpuProfile__Delete(const v8::CpuProfile* self) { |
| 1748 | + const_cast<v8::CpuProfile*>(self)->Delete(); |
| 1749 | +} |
| 1750 | + |
| 1751 | +const v8::CpuProfileNode* v8__CpuProfile__GetTopDownRoot(const v8::CpuProfile* self) { |
| 1752 | + return self->GetTopDownRoot(); |
| 1753 | +} |
| 1754 | + |
| 1755 | +// Custom OutputStream that collects output into a string |
| 1756 | +class StringOutputStream : public v8::OutputStream { |
| 1757 | +public: |
| 1758 | + void EndOfStream() override {} |
| 1759 | + |
| 1760 | + int GetChunkSize() override { |
| 1761 | + return 1024 * 1024; // 1MB chunks |
| 1762 | + } |
| 1763 | + |
| 1764 | + v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override { |
| 1765 | + buffer_.append(data, size); |
| 1766 | + return v8::OutputStream::kContinue; |
| 1767 | + } |
| 1768 | + |
| 1769 | + const std::string& str() const { return buffer_; } |
| 1770 | + |
| 1771 | +private: |
| 1772 | + std::string buffer_; |
| 1773 | +}; |
| 1774 | + |
| 1775 | +const v8::String* v8__CpuProfile__Serialize(const v8::CpuProfile* self, v8::Isolate* isolate) { |
| 1776 | + StringOutputStream stream; |
| 1777 | + self->Serialize(&stream); |
| 1778 | + return maybe_local_to_ptr( |
| 1779 | + v8::String::NewFromUtf8(isolate, stream.str().c_str(), v8::NewStringType::kNormal, stream.str().length()) |
| 1780 | + ); |
| 1781 | +} |
| 1782 | + |
1731 | 1783 | // Inspector |
1732 | 1784 | // --------- |
1733 | 1785 |
|
|
0 commit comments