Changeset 256910 in webkit
- Timestamp:
- Feb 18, 2020 9:37:45 PM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 11 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r256850 r256910 1 2020-02-18 Keith Miller <keith_miller@apple.com> 2 3 Add an os_log PrintStream 4 https://bugs.webkit.org/show_bug.cgi?id=207898 5 6 Reviewed by Mark Lam. 7 8 Add jsc option to write dataLogs to os_log. 9 10 * runtime/Options.cpp: 11 (JSC::Options::initialize): 12 * runtime/OptionsList.h: 13 1 14 2020-02-18 Paulo Matos <pmatos@igalia.com> 2 15 -
trunk/Source/JavaScriptCore/runtime/Options.cpp
r256500 r256910 43 43 #include <wtf/NumberOfCores.h> 44 44 #include <wtf/Optional.h> 45 #include <wtf/OSLogPrintStream.h> 45 46 #include <wtf/PointerPreparations.h> 46 47 #include <wtf/StdLibExtras.h> … … 614 615 #endif 615 616 617 #if OS(DARWIN) 618 if (Options::useOSLog()) { 619 WTF::setDataFile(OSLogPrintStream::open("com.apple.JavaScriptCore", "DataLog", OS_LOG_TYPE_INFO)); 620 // Make sure no one jumped here for nefarious reasons... 621 RELEASE_ASSERT(useOSLog()); 622 } 623 #endif 624 616 625 #if ASAN_ENABLED && OS(LINUX) && ENABLE(WEBASSEMBLY_FAST_MEMORY) 617 626 if (Options::useWebAssemblyFastMemory()) { -
trunk/Source/JavaScriptCore/runtime/OptionsList.h
r256500 r256910 120 120 v(Unsigned, shadowChickenMaxTailDeletedFramesSize, 128, Normal, nullptr) \ 121 121 \ 122 v(Bool, useOSLog, false, Normal, "Log dataLog()s to os_log instead of stderr") \ 122 123 /* dumpDisassembly implies dumpDFGDisassembly. */ \ 123 124 v(Bool, dumpDisassembly, false, Normal, "dumps disassembly of all JIT compiled code upon compilation") \ -
trunk/Source/WTF/ChangeLog
r256834 r256910 1 2020-02-18 Keith Miller <keith_miller@apple.com> 2 3 Add an os_log PrintStream 4 https://bugs.webkit.org/show_bug.cgi?id=207898 5 6 Reviewed by Mark Lam. 7 8 When debugging on iOS writing to a file can be hard (thanks 9 Sandboxing!) so logging our dataLogs to os_log would make things 10 easier. This patch adds a new subclass of PrintStream, 11 OSLogPrintStream, that converts our file writes to 12 os_log. Unfortunately, os_log doesn't buffer writes so 13 OSLogPrintStream needs to do its own buffering. e.g. if you call 14 `dataLogLn("some text with a ", number, " and a ", string);` 15 os_log will log that as 5 separate logs. 16 17 * WTF.xcodeproj/project.pbxproj: 18 * wtf/CMakeLists.txt: 19 * wtf/DataLog.cpp: 20 (WTF::setDataFile): 21 * wtf/DataLog.h: 22 * wtf/OSLogPrintStream.cpp: Added. 23 (WTF::OSLogPrintStream::OSLogPrintStream): 24 (WTF::OSLogPrintStream::~OSLogPrintStream): 25 (WTF::OSLogPrintStream::open): 26 (WTF::OSLogPrintStream::vprintf): 27 * wtf/OSLogPrintStream.h: Copied from Source/WTF/wtf/DataLog.h. 28 * wtf/PrintStream.cpp: 29 (WTF::printExpectedCStringHelper): 30 (WTF::printInternal): 31 * wtf/text/CString.cpp: 32 (WTF::CString::grow): 33 * wtf/text/CString.h: 34 1 35 2020-02-18 Simon Fraser <simon.fraser@apple.com> 2 36 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r255577 r256910 79 79 5311BD5C1EA822F900525281 /* ThreadMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5311BD5B1EA822F900525281 /* ThreadMessage.cpp */; }; 80 80 53534F2A1EC0E10E00141B2F /* MachExceptions.defs in Sources */ = {isa = PBXBuildFile; fileRef = 53534F291EC0E10E00141B2F /* MachExceptions.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; }; 81 53FC70D023FB950C005B1990 /* OSLogPrintStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */; }; 81 82 5C1F05932164356B0039302C /* CFURLExtras.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1F05912164356B0039302C /* CFURLExtras.cpp */; }; 82 83 5C1F0595216437B30039302C /* URLCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C1F0594216437B30039302C /* URLCF.cpp */; }; … … 400 401 53F08A1BA39D49A8BAD369A1 /* StdSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdSet.h; sourceTree = "<group>"; }; 401 402 53F1D98620477B9800EBC6BF /* FunctionTraits.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = FunctionTraits.h; sourceTree = "<group>"; }; 403 53FC70CE23FB950C005B1990 /* OSLogPrintStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSLogPrintStream.h; sourceTree = "<group>"; }; 404 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSLogPrintStream.cpp; sourceTree = "<group>"; }; 402 405 553071C91C40427200384898 /* TinyLRUCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyLRUCache.h; sourceTree = "<group>"; }; 403 406 5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SynchronizedFixedQueue.h; sourceTree = "<group>"; }; … … 1113 1116 0F9495831C571CC900413A48 /* OrderMaker.h */, 1114 1117 A8A472D7151A825B004123FF /* OSAllocator.h */, 1118 53FC70CF23FB950C005B1990 /* OSLogPrintStream.cpp */, 1119 53FC70CE23FB950C005B1990 /* OSLogPrintStream.h */, 1115 1120 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */, 1116 1121 A8A472DA151A825B004123FF /* OSRandomSource.cpp */, … … 1665 1670 8348BA0E21FBC0D500FD3054 /* ObjectIdentifier.cpp in Sources */, 1666 1671 A3EE5C3A21FFAC5F00FABD61 /* OSAllocatorPOSIX.cpp in Sources */, 1672 53FC70D023FB950C005B1990 /* OSLogPrintStream.cpp in Sources */, 1667 1673 A8A473F9151A825B004123FF /* OSRandomSource.cpp in Sources */, 1668 1674 A8A47402151A825B004123FF /* PageBlock.cpp in Sources */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r255577 r256910 149 149 NumberOfCores.h 150 150 OSAllocator.h 151 OSLogPrintStream.h 151 152 OSObjectPtr.h 152 153 OSRandomSource.h … … 401 402 MonotonicTime.cpp 402 403 NumberOfCores.cpp 404 OSLogPrintStream.cpp 403 405 OSRandomSource.cpp 404 406 ObjectIdentifier.cpp -
trunk/Source/WTF/wtf/DataLog.cpp
r250005 r256910 167 167 } 168 168 169 void setDataFile(std::unique_ptr<PrintStream>&& file) 170 { 171 s_file = file.release(); 172 } 173 169 174 PrintStream& dataFile() 170 175 { -
trunk/Source/WTF/wtf/DataLog.h
r254714 r256910 35 35 WTF_EXPORT_PRIVATE PrintStream& dataFile(); 36 36 WTF_EXPORT_PRIVATE void setDataFile(const char* path); 37 WTF_EXPORT_PRIVATE void setDataFile(std::unique_ptr<PrintStream>&&); 37 38 38 39 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); -
trunk/Source/WTF/wtf/OSLogPrintStream.h
r256909 r256910 1 1 /* 2 * Copyright (C) 20 12Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include <stdarg.h> 29 #include <stdio.h> 28 #if OS(DARWIN) 29 30 #include <wtf/Lock.h> 30 31 #include <wtf/PrintStream.h> 31 #include <wtf/StdLibExtras.h> 32 #include <wtf/RecursiveLockAdapter.h> 33 #include <wtf/text/CString.h> 34 #include <wtf/Vector.h> 35 36 #include <os/log.h> 32 37 33 38 namespace WTF { 34 39 35 WTF_EXPORT_PRIVATE PrintStream& dataFile(); 36 WTF_EXPORT_PRIVATE void setDataFile(const char* path); 40 class WTF_EXPORT_PRIVATE OSLogPrintStream final : public PrintStream { 41 public: 42 OSLogPrintStream(os_log_t, os_log_type_t); 43 virtual ~OSLogPrintStream(); 44 45 static std::unique_ptr<OSLogPrintStream> open(const char* subsystem, const char* category, os_log_type_t = OS_LOG_TYPE_DEFAULT); 46 47 void vprintf(const char* format, va_list) override WTF_ATTRIBUTE_PRINTF(2, 0); 37 48 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 41 42 template<typename... Types> 43 NEVER_INLINE void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 47 48 template<typename... Types> 49 void dataLogLn(const Types&... values) 50 { 51 dataLog(values..., "\n"); 52 } 53 54 template<typename... Types> 55 ALWAYS_INLINE void dataLogIf(bool shouldLog, const Types&... values) 56 { 57 if (UNLIKELY(shouldLog)) 58 dataLog(values...); 59 } 60 61 template<typename... Types> 62 ALWAYS_INLINE void dataLogLnIf(bool shouldLog, const Types&... values) 63 { 64 if (UNLIKELY(shouldLog)) 65 dataLogLn(values...); 66 } 49 private: 50 os_log_t m_log; 51 os_log_type_t m_logType; 52 Lock m_stringLock; 53 // We need a buffer because os_log doesn't wait for a new line to print the characters. 54 CString m_string; 55 size_t m_offset { 0 }; 56 }; 67 57 68 58 } // namespace WTF 69 59 70 using WTF::dataLog; 71 using WTF::dataLogLn; 72 using WTF::dataLogIf; 73 using WTF::dataLogLnIf; 74 using WTF::dataLogF; 75 using WTF::dataLogFString; 60 using WTF::OSLogPrintStream; 61 62 #endif -
trunk/Source/WTF/wtf/PrintStream.cpp
r237099 r256910 78 78 { 79 79 if (UNLIKELY(!expectedCString)) { 80 if (expectedCString.error() == UTF8ConversionError::OutOfMemory) 81 out.print("(Out of memory while converting ", type, " to utf8)"); 82 else 83 out.print("(failed to convert ", type, " to utf8)"); 80 if (expectedCString.error() == UTF8ConversionError::OutOfMemory) { 81 printInternal(out, "(Out of memory while converting "); 82 printInternal(out, type); 83 printInternal(out, " to utf8)"); 84 } else { 85 printInternal(out, "(failed to convert "); 86 printInternal(out, type); 87 printInternal(out, " to utf8)"); 88 } 84 89 return; 85 90 } 86 out.print(expectedCString.value());91 printInternal(out, expectedCString.value()); 87 92 } 88 93 … … 94 99 void printInternal(PrintStream& out, const CString& string) 95 100 { 96 out.print(string.data());101 printInternal(out, string.data()); 97 102 } 98 103 … … 105 110 { 106 111 if (!string) { 107 out.print("(null StringImpl*)");112 printInternal(out, "(null StringImpl*)"); 108 113 return; 109 114 } … … 168 173 void printInternal(PrintStream& out, float value) 169 174 { 170 out.print(static_cast<double>(value));175 printInternal(out, static_cast<double>(value)); 171 176 } 172 177 -
trunk/Source/WTF/wtf/text/CString.cpp
r253987 r256910 107 107 } 108 108 109 void CString::grow(size_t newLength) 110 { 111 ASSERT(newLength > length()); 112 113 auto newBuffer = CStringBuffer::createUninitialized(newLength); 114 memcpy(newBuffer->mutableData(), m_buffer->data(), length() + 1); 115 m_buffer = WTFMove(newBuffer); 116 } 117 109 118 bool operator==(const CString& a, const CString& b) 110 119 { -
trunk/Source/WTF/wtf/text/CString.h
r253987 r256910 85 85 WTF_EXPORT_PRIVATE unsigned hash() const; 86 86 87 // Useful if you want your CString to hold dynamic data. 88 WTF_EXPORT_PRIVATE void grow(size_t newLength); 89 87 90 private: 88 91 void copyBufferIfNeeded();
Note: See TracChangeset
for help on using the changeset viewer.