Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@sbaranov
Copy link
Contributor

@sbaranov sbaranov commented Jun 1, 2018

Used to generate delta kernel files for codepush.

@sbaranov sbaranov requested a review from cbracken June 1, 2018 17:50
}());
}

void saveCompilationTrace(String filePath) native 'SaveCompilationTrace';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do some basic sanity checking on the arguments in Dart itself before making the native call. Stuff like null or zero length file paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this argument is already validated for null by Dart_NewStringFromCString() and shows nice stack trace. And empty value is caught by ::open :)

intptr_t size = 0;
Dart_Handle result = Dart_SaveCompilationTrace(&buffer, &size);
if (Dart_IsError(result)) {
FXL_LOG(ERROR) << "Failed to save trace: " << Dart_GetError(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of logging on error, we propagate the error back to the caller in Dart code. The pattern typically followed is to return a string. In case of error, the string describes the error. In case of success, the return string is null. You can convert this scheme into idiomatic Dart code in natives.dart.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the _futurize call in Dart code to see existing uses of this pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Although, would it be cleaner to return Dart Error object instead of converting them to string every time? Or perhaps even simply call Dart_ThrowException(error)?

}

auto fd = fml::UniqueFD{
FML_HANDLE_EINTR(::open(filePath, O_CREAT|O_WRONLY|O_TRUNC, 0660))};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file in unlikely to compile or run on Windows but is built on that platform. I suggest you return a typed unsigned integer list from this method and write the file to a destination using dart:io APIs in the wrappers in natives.dart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work on Windows because Windows doesn't have EINTR problem, and so on Windows we define FML_HANDLE_EINTR(::open(...)) as simply ::open(...). Having said this, let me know if you still want this to use dart::io instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. I would prefer the engine be as simple as possible and just manage trace acquisition. How the trace is stored/transferred doesn't concern the engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

FXL_LOG(ERROR) << "Failed to create file: " << filePath << ", " << errno;
return;
}
if (write(fd.get(), buffer, (size_t) size) != (ssize_t) size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it matters since we probably shouldn't be using these file IO APIs here, but shouldn't you loop if size is less that what was requested for writes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I've seen this pattern. Do you have an example somewhere?

Copy link
Contributor Author

@sbaranov sbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

}

auto fd = fml::UniqueFD{
FML_HANDLE_EINTR(::open(filePath, O_CREAT|O_WRONLY|O_TRUNC, 0660))};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with nits.

#include <sstream>

#include "flutter/common/settings.h"
#include "flutter/fml/eintr_wrapper.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary header includes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

final file = new File(filePath);
file.writeAsBytesSync(result);

print('Saved compilation trace ${filePath}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary print trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

void saveCompilationTrace(String filePath) {
final result = _saveCompilationTrace();
Copy link
Contributor

@dnfield dnfield Jun 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analysis is failing on this line (no type is specified)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be final dynamic result based on _saveCompliationTrace's return type

if (result is Error)
throw result;

final file = new File(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - should be final File file = ...

@dnfield dnfield mentioned this pull request Jun 10, 2018
@sbaranov sbaranov deleted the dart-compilation-trace-native branch July 26, 2018 23:18
}
}

void SaveCompilationTrace(Dart_NativeArguments args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to expose this to all users?

It needs documentation explaining how and when to use it.

@sbaranov
Copy link
Contributor Author

Can we have hidden APIs? We might need this one for all users eventually, but for now it's an experimental function that's only needed for the dev team and another internal team. It would be nice not to have to document it since it might change.

@Hixie
Copy link
Contributor

Hixie commented Dec 19, 2018

We can't really have hidden APIs.

This is now shipped to all our 1.0.0 stable users. We should definitely document it.

@sbaranov
Copy link
Contributor Author

This is no longer experimental, it's now used by the flutter tool for dynamic code. I'll document it.

@Hixie
Copy link
Contributor

Hixie commented Dec 19, 2018

Cool, thanks.

@sbaranov
Copy link
Contributor Author

Fixed in #7256

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants