12#if defined(TARGET_ARCH_IS_64_BIT) && defined(DART_PRECOMPILED_RUNTIME) && \
13 (defined(DART_TARGET_OS_ANDROID) || defined(DART_TARGET_OS_LINUX))
14#define SUPPORT_ANALYZE_SNAPSHOT
17#ifdef SUPPORT_ANALYZE_SNAPSHOT
23#ifdef SUPPORT_ANALYZE_SNAPSHOT
24#define STRING_OPTIONS_LIST(V) V(out, out_path)
26#define BOOL_OPTIONS_LIST(V) \
28 V(sdk_version, sdk_version)
30#define STRING_OPTION_DEFINITION(flag, variable) \
31 static const char* variable = nullptr; \
32 DEFINE_STRING_OPTION(flag, variable)
34#undef STRING_OPTION_DEFINITION
36#define BOOL_OPTION_DEFINITION(flag, variable) \
37 static bool variable = false; \
38 DEFINE_BOOL_OPTION(flag, variable)
40#undef BOOL_OPTION_DEFINITION
45"Usage: analyze_snapshot [<vm-flags>] [<options>] <snapshot_data> \n"
49" Display this message. \n"
51" Print the SDK version. \n"
53" Path to generate the analysis results JSON. \n"
54"If omitting [<vm-flags>] the VM parsing the snapshot is created with the \n"
55"following default flags: \n"
56"--enable_mirrors=false \n"
57"--background_compilation \n"
66const uint8_t* vm_isolate_data =
nullptr;
67const uint8_t* vm_isolate_instructions =
nullptr;
90 inputs->AddArgument(
argv[i]);
97 }
else if (sdk_version) {
103 if (inputs->count() < 1) {
123 if (file ==
nullptr) {
124 PrintErrAndExit(
"Error: Unable to write file: %s\n\n", filename);
129static void WriteFile(
const char* filename,
131 const intptr_t size) {
134 if (!file->WriteFully(
buffer, size)) {
135 PrintErrAndExit(
"Error: Unable to write file: %s\n\n", filename);
139int RunAnalyzer(
int argc,
char**
argv) {
141 const int EXTRA_VM_ARGUMENTS = 7;
149 if (out_path ==
nullptr) {
156 if (vm_options.
count() == 0) {
158 vm_options.
AddArgument(
"--background_compilation");
163 if (
error !=
nullptr) {
169 const char* script_name =
nullptr;
170 script_name = inputs.GetArgument(0);
175 if (file ==
nullptr) {
181 const char* loader_error =
nullptr;
186 if (loaded_elf ==
nullptr) {
193 memset(&init_params, 0,
sizeof(init_params));
203#if defined(DART_HOST_OS_FUCHSIA)
204 init_params.vmex_resource = Platform::GetVMEXResource();
208 if (
error !=
nullptr) {
214 auto isolate_group_data = std::unique_ptr<IsolateGroupData>(
221 vm_isolate_instructions, &isolate_flags,
222 isolate_group_data.get(),
225 if (
error !=
nullptr) {
233 vm_isolate_instructions};
236 intptr_t out_len = 0;
239 Dart_DumpSnapshotInformationAsJson(
info, &out, &out_len);
255int main(
int argc,
char** argv) {
256#ifdef SUPPORT_ANALYZE_SNAPSHOT
257 return dart::bin::RunAnalyzer(argc,
argv);
261 "Requires SDK with following "
262 "flags:\n\tTARGET_ARCH_IS_64_BIT\n\tDART_PRECOMPILED_RUNTIME\n\tDART_"
263 "TARGET_OS_ANDROID || DART_TARGET_OS_LINUX");
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
const char ** arguments() const
void AddArgument(const char *argument)
static void ReadFile(uint8_t **data, intptr_t *file_len, void *stream)
static bool EntropySource(uint8_t *buffer, intptr_t length)
static void CloseFile(void *stream)
static void * OpenFile(const char *name, bool write)
static void WriteFile(const void *buffer, intptr_t num_bytes, void *stream)
static File * Open(Namespace *namespc, const char *path, FileOpenMode mode)
static bool TryProcess(const char *option, CommandLineOptions *options)
static bool IsValidShortFlag(const char *name)
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
#define BOOL_OPTIONS_LIST(V)
#define STRING_OPTION_DEFINITION(flag, variable)
#define BOOL_OPTION_DEFINITION(flag, variable)
#define STRING_OPTIONS_LIST(V)
void WriteFile(const void *buffer, intptr_t num_bytes, void *stream)
const uint8_t * vm_snapshot_data
const uint8_t * vm_snapshot_instructions
constexpr int kErrorExitCode
static int ParseArguments(int argc, char **argv, CommandLineOptions *vm_options, CommandLineOptions *inputs)
void * OpenFile(const char *name, bool write)
DART_EXPORT void Dart_EnterScope()
DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags *flags)
DART_EXPORT char * Dart_Initialize(Dart_InitializeParams *params)
DART_EXPORT const char * Dart_VersionString()
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroup(const char *script_uri, const char *name, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
DART_EXPORT char * Dart_SetVMFlags(int argc, const char **argv)
Dart_FileReadCallback file_read
const uint8_t * vm_snapshot_data
Dart_FileOpenCallback file_open
Dart_FileWriteCallback file_write
Dart_EntropySource entropy_source
const uint8_t * vm_snapshot_instructions
Dart_FileCloseCallback file_close
DART_EXPORT Dart_LoadedElf * Dart_LoadELF(const char *filename, uint64_t file_offset, const char **error, const uint8_t **vm_snapshot_data, const uint8_t **vm_snapshot_instrs, const uint8_t **vm_isolate_data, const uint8_t **vm_isolate_instrs)
Please see documentation for Dart_LoadElf_Fd.
DART_EXPORT void Dart_UnloadELF(Dart_LoadedElf *loaded)