18void WriteToFile(
const char* prefix, FILE* file, Isolate* isolate,
19 const debug::ConsoleCallArguments&
args) {
20 if (prefix) fprintf(file,
"%s: ", prefix);
21 for (
int i = 0;
i <
args.Length();
i++) {
22 HandleScope handle_scope(isolate);
23 if (
i > 0) fprintf(file,
" ");
25 Local<Value> arg =
args[
i];
26 Local<String> str_obj;
29 if (!arg->ToString(isolate->GetCurrentContext()).ToLocal(&str_obj))
return;
32 size_t n = fwrite(*str,
sizeof(**str), str.length(), file);
33 if (n != str.length()) {
34 printf(
"Error in fwrite\n");
46 explicit FileOutputStream(
const char*
filename)
49 WriteResult WriteAsciiChunk(
char* data,
int size)
override {
50 os_.write(data, size);
54 void EndOfStream()
override {
os_.close(); }
60static constexpr const char* kCpuProfileOutputFilename =
"v8.prof";
64 WriteResult WriteAsciiChunk(
char* data,
int size)
override {
65 os_.write(data, size);
69 void EndOfStream()
override {}
71 std::string
result() {
return os_.str(); }
74 std::ostringstream
os_;
77std::optional<std::string> GetTimerLabel(
78 const debug::ConsoleCallArguments&
args) {
79 if (
args.Length() == 0)
return "default";
80 Isolate* isolate =
args.GetIsolate();
83 if (*
label ==
nullptr)
return std::nullopt;
153 if (!profile)
return;
155 StringOutputStream out;
156 profile->Serialize(&out);
159 FileOutputStream out(kCpuProfileOutputFilename);
160 profile->Serialize(&out);
167 if (
i::v8_flags.correctness_fuzzer_suppressions)
return;
168 std::optional
label = GetTimerLabel(
args);
169 if (!
label.has_value())
return;
171 printf(
"console.time: Timer '%s' already exists\n",
label.value().c_str());
177 if (
i::v8_flags.correctness_fuzzer_suppressions)
return;
178 std::optional
label = GetTimerLabel(
args);
179 if (!
label.has_value())
return;
182 printf(
"console.timeLog: Timer '%s' does not exist\n",
183 label.value().c_str());
187 printf(
"console.timeLog: %s, %f\n",
label.value().c_str(),
193 if (
i::v8_flags.correctness_fuzzer_suppressions)
return;
194 std::optional
label = GetTimerLabel(
args);
195 if (!
label.has_value())
return;
198 printf(
"console.timeEnd: Timer '%s' does not exist\n",
199 label.value().c_str());
203 printf(
"console.timeEnd: %s, %f\n",
label.value().c_str(),
210 if (
i::v8_flags.correctness_fuzzer_suppressions)
return;
211 std::optional
label = GetTimerLabel(
args);
212 if (!
label.has_value())
return;
214 printf(
"console.timeStamp: %s, %f\n",
label.value().c_str(),
220 if (
i::v8_flags.correctness_fuzzer_suppressions)
return;
222 i_isolate->
PrintStack(stderr, i::Isolate::kPrintStackConcise);
CpuProfilingStatus StartProfiling(Local< String > title, CpuProfilingOptions options, std::unique_ptr< DiscardedSamplesDelegate > delegate=nullptr)
static CpuProfiler * New(Isolate *isolate, CpuProfilingNamingMode=kDebugNaming, CpuProfilingLoggingMode=kLazyLogging)
CpuProfile * StopProfiling(Local< String > title)
D8Console(Isolate *isolate)
void Error(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Debug(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void ProfileEnd(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &context) override
void Trace(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void TimeLog(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Info(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Profile(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &context) override
void TimeEnd(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
std::map< std::string, base::TimeTicks > timers_
void Log(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Assert(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Warn(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void TimeStamp(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
void Time(const debug::ConsoleCallArguments &args, const v8::debug::ConsoleContext &) override
Local< Value > ThrowError(const char(&message)[N])
static V8_INLINE Local< T > Cast(Local< S > that)
static void TriggerOnProfileEndListener(Isolate *isolate, std::string profile)
static bool HasOnProfileEndListener(Isolate *isolate)
static V8_INLINE Local< String > Empty(Isolate *isolate)
static void ExitProcess(int exit_code)
double InMillisecondsF() const
void PrintStack(StringStream *accumulator, PrintStackMode mode=kPrintStackVerbose)
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
V8_EXPORT_PRIVATE FlagValues v8_flags
void WriteToFile(FILE *file, const v8::FunctionCallbackInfo< v8::Value > &info, int first_arg_index=0)