| 
5 | 5 | #ifndef SRC_TRACING_TRACED_VALUE_H_  | 
6 | 6 | #define SRC_TRACING_TRACED_VALUE_H_  | 
7 | 7 | 
 
  | 
8 |  | -#include "node.h"  | 
9 |  | -#include "util.h"  | 
10 |  | -#include "v8.h"  | 
 | 8 | +#include "v8-platform.h"  | 
11 | 9 | 
 
  | 
12 |  | -#include <cstddef>  | 
13 |  | -#include <memory>  | 
 | 10 | +#include <cstdint>  | 
 | 11 | +#include <span>  | 
14 | 12 | #include <string>  | 
15 | 13 | 
 
  | 
16 | 14 | namespace node {  | 
17 | 15 | namespace tracing {  | 
18 | 16 | 
 
  | 
 | 17 | +template <typename T>  | 
 | 18 | +std::unique_ptr<v8::ConvertableToTraceFormat> CastTracedValue(const T& value) {  | 
 | 19 | +  return value.Cast();  | 
 | 20 | +}  | 
 | 21 | + | 
 | 22 | +class EnvironmentArgs {  | 
 | 23 | + public:  | 
 | 24 | +  EnvironmentArgs(std::span<const std::string> args,  | 
 | 25 | +                  std::span<const std::string> exec_args)  | 
 | 26 | +      : args_(args), exec_args_(exec_args) {}  | 
 | 27 | + | 
 | 28 | +  std::unique_ptr<v8::ConvertableToTraceFormat> Cast() const;  | 
 | 29 | + | 
 | 30 | + private:  | 
 | 31 | +  std::span<const std::string> args_;  | 
 | 32 | +  std::span<const std::string> exec_args_;  | 
 | 33 | +};  | 
 | 34 | + | 
 | 35 | +class AsyncWrapArgs {  | 
 | 36 | + public:  | 
 | 37 | +  AsyncWrapArgs(int64_t execution_async_id, int64_t trigger_async_id)  | 
 | 38 | +      : execution_async_id_(execution_async_id),  | 
 | 39 | +        trigger_async_id_(trigger_async_id) {}  | 
 | 40 | + | 
 | 41 | +  std::unique_ptr<v8::ConvertableToTraceFormat> Cast() const;  | 
 | 42 | + | 
 | 43 | + private:  | 
 | 44 | +  int64_t execution_async_id_;  | 
 | 45 | +  int64_t trigger_async_id_;  | 
 | 46 | +};  | 
 | 47 | + | 
 | 48 | +class ProcessMeta {  | 
 | 49 | + public:  | 
 | 50 | +  std::unique_ptr<v8::ConvertableToTraceFormat> Cast() const;  | 
 | 51 | +};  | 
 | 52 | + | 
 | 53 | +// Do not use this class directly. Define a custom structured class to provide  | 
 | 54 | +// a conversion method so that the class can be used with both V8 legacy  | 
 | 55 | +// trace API and perfetto API.  | 
 | 56 | +//  | 
 | 57 | +// These classes provide a JSON-inspired way to write structed data into traces.  | 
 | 58 | +//  | 
 | 59 | +// To define how a custom class should be written into the trace, users should  | 
 | 60 | +// define one of the two following functions:  | 
 | 61 | +// - Foo::Cast(TracedValue) const  | 
 | 62 | +//   (preferred for code which depends on perfetto directly)  | 
 | 63 | +//  | 
 | 64 | +// After defining a conversion method, the object can be used as a  | 
 | 65 | +// TRACE_EVENT argument:  | 
 | 66 | +//  | 
 | 67 | +// Foo foo;  | 
 | 68 | +// TRACE_EVENT("cat", "Event", "arg", CastTracedValue(foo));  | 
 | 69 | +//  | 
 | 70 | +// class Foo {  | 
 | 71 | +//   std::unique_ptr<v8::ConvertableToTraceFormat> Cast() const {  | 
 | 72 | +//     auto traced_value = tracing::TracedValue::Create();  | 
 | 73 | +//     dict->SetInteger("key", 42);  | 
 | 74 | +//     dict->SetString("foo", "bar");  | 
 | 75 | +//     return traced_value;  | 
 | 76 | +//   }  | 
 | 77 | +// }  | 
19 | 78 | class TracedValue : public v8::ConvertableToTraceFormat {  | 
20 | 79 |  public:  | 
21 | 80 |   ~TracedValue() override = default;  | 
 | 
0 commit comments