Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(perf): support performance api #3341

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d92e048
fix(perf): support performance api
Jun 8, 2023
2fb52f5
fix(perf): support performance api
Jun 8, 2023
49129b8
fix(perf): support performance api
Jun 8, 2023
97120ad
fix(perf): support performance api
Jun 9, 2023
55adca2
fix(perf): support performance api
Jun 9, 2023
ad14473
fix(perf): support performance api
Jun 9, 2023
760bf8b
feat(ios): add bridge time point performance
ozonelmy Jun 9, 2023
6935879
fix(perf): support performance api
Jun 9, 2023
a824bba
fix(perf): support performance api
Jun 9, 2023
e99bf53
Merge branch 'v3.0-dev' into performance_api
Jun 12, 2023
5b5b7f1
fix(perf): support performance api
Jun 13, 2023
17cd64c
Merge branch 'v3.0-dev' into performance_api
Jun 13, 2023
0654974
feat(ios): remove old ios performance logger
ozonelmy Jun 12, 2023
118f443
feat(ios): add performance point for engine start/end
ozonelmy Jun 14, 2023
fc6e169
fix(perf): support performance api
Jun 14, 2023
148ec7d
feat(ios): engine init point and execute source point and resource point
ozonelmy Jun 14, 2023
aae5494
Merge branch 'v3.0-dev' into performance_api
Jun 15, 2023
68a82bb
fix(perf): support performance api
Jun 15, 2023
2984f6e
fix(perf): support performance api
Jun 15, 2023
d960294
Merge branch 'v3.0-dev' into performance_api
Jun 15, 2023
d3ea62c
feat(ios): add first frame naviation timing point
ozonelmy Jun 16, 2023
62b0f62
Merge branch 'v3.0-dev' into performance_api
Jun 20, 2023
41e39d1
fix(perf): support performance api
Jun 20, 2023
7d44234
fix(perf): support performance api
Jun 20, 2023
cc6fc6a
fix(perf): support performance api
Jun 20, 2023
6fb5162
feat(android): add performace impl
siguangli2018 Jun 21, 2023
558fd8a
fix(perf): support performance api
Jun 21, 2023
4620839
Merge branch 'v3.0-dev' into performance_api
Jun 21, 2023
0ff0e7b
feat(ios): fix conflicts & add performance api
ozonelmy Jun 22, 2023
78fb529
feat(ios): add performance api
ozonelmy Jun 22, 2023
e503914
fix(android): remove OnNativeInitStart interface
siguangli2018 Jun 25, 2023
b7f0f59
fix(perf): support performance api
Jun 25, 2023
4ff2c0b
feat(ios): update ios navigation timing report
ozonelmy Jun 25, 2023
420ba1e
Merge branch 'v3.0-dev' into performance_api
Jun 25, 2023
af225d3
feat(docs): add vue-next integration doc
gguoyu Jun 29, 2023
e4fdbef
feat(docs): update vue-next integration doc
gguoyu Jun 29, 2023
58fd6a9
perf(ios): reduce call of waterfall reload method frequency
ozonelmy Jun 29, 2023
cddd2a6
fix(ios): fixed a bug where the extracomponents did not take effect
ozonelmy Jun 29, 2023
1a34398
chore(action): add github release and compare action
zealotchen0 Jun 29, 2023
cac965f
fix(ios): add semaphore to make sure scope is created
ozonelmy Jun 29, 2023
dc5d36d
Merge branch 'v3.0-dev' into performance_api
etkmao Jun 30, 2023
2c01183
fix(ios): fix correct copyright header
etkmao Jun 30, 2023
d9ded26
fix(jsc): fix jsc crash on ios12
etkmao Jul 3, 2023
13ef5f9
Merge branch 'main' into performance_api
etkmao Jul 3, 2023
54071e4
refactor(core): reduce header file dependencies
ozonelmy Jun 30, 2023
94135b0
Merge branch 'main' into performance_api
etkmao Jul 3, 2023
6e72a07
chore(ios): add pod spec lint workflow file
ozonelmy Jul 3, 2023
a802e22
fix(ios): remove the semicolon after namespace syntax
ozonelmy Jul 3, 2023
f261ef0
feat(voltron): update workflow xcode version
henryjin0511 Jul 3, 2023
851318d
Merge branch 'main' into performance_api
etkmao Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions driver/js/include/driver/performance/performance.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "footstone/string_view.h"
#include "driver/performance/performance_entry.h"
#include "driver/performance/performance_resource_timing.h"
#include "driver/performance/performance_navigation_timing.h"
#include "driver/performance/performance_paint_timing.h"

namespace hippy {
inline namespace driver {
Expand All @@ -54,6 +56,10 @@ class Performance {
return time_origin_;
}

std::shared_ptr<PerformanceNavigationTiming> PerformanceNavigation(const string_view& name);
std::shared_ptr<PerformancePaintTiming> PerformancePaint(const PerformancePaintTiming::Type& type);
std::shared_ptr<PerformanceResourceTiming> PerformanceResource(const string_view& name);

void Mark(const string_view& name);
void ClearMarks(const string_view& name);
void ClearMarks();
Expand All @@ -67,8 +73,8 @@ class Performance {
void ClearResourceTimings();
std::vector<std::shared_ptr<PerformanceEntry>> GetEntries(const PerformanceEntryFilterOptions& options);
std::vector<std::shared_ptr<PerformanceEntry>> GetEntries();
std::shared_ptr<PerformanceEntry> GetEntriesByName(const string_view& name);
std::shared_ptr<PerformanceEntry> GetEntriesByName(const string_view& name, PerformanceEntry::Type type);
std::vector<std::shared_ptr<PerformanceEntry>> GetEntriesByName(const string_view& name);
std::vector<std::shared_ptr<PerformanceEntry>> GetEntriesByName(const string_view& name, PerformanceEntry::Type type);
std::vector<std::shared_ptr<PerformanceEntry>> GetEntriesByType(PerformanceEntry::Type type);
string_view ToJSON();

Expand Down
6 changes: 6 additions & 0 deletions driver/js/include/driver/performance/performance_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class PerformanceEntry {
start_time_(start_time),
duration_(duration) {}

PerformanceEntry(const string_view& name,
SubType sub_type,
Type type) : name_(name),
sub_type_(sub_type),
type_(type) {}

virtual ~PerformanceEntry() = default;

inline auto GetName() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,62 +33,48 @@ inline namespace performance {
class PerformanceNavigationTiming : public PerformanceEntry {
public:
struct BundleInfo {
string_view bundle_url;
TimePoint start;
TimePoint end;
string_view url_;
TimePoint execute_source_start_;
TimePoint execute_source_end_;
};

PerformanceNavigationTiming(const string_view& name, const TimePoint& start,
const TimePoint& engine_initialization_start, const TimePoint& engine_initialization_end,
std::vector<BundleInfo> bundle_info,
const TimePoint& load_instance_start, const TimePoint& load_instance_end,
const TimePoint& first_frame);
PerformanceNavigationTiming(const string_view& name);

inline auto GetEngineInitializationStart() const {
return engine_initialization_start_;
#define DEFINE_SET_AND_GET_METHOD(method_name, member_type, member) \
void Set##method_name(member_type t) { \
member = t; \
} \
inline auto Get##method_name() const { \
return member; \
}
DEFINE_SET_AND_GET_METHOD(HippyNativeInitStart, TimePoint, hippy_native_init_start_)
DEFINE_SET_AND_GET_METHOD(HippyNativeInitEnd, TimePoint, hippy_native_init_end_)
DEFINE_SET_AND_GET_METHOD(HippyJsEngineInitStart, TimePoint, hippy_js_engine_init_start_)
DEFINE_SET_AND_GET_METHOD(HippyJsEngineInitEnd, TimePoint, hippy_js_engine_init_end_)
DEFINE_SET_AND_GET_METHOD(HippyRunApplicationStart, TimePoint, hippy_run_application_start_)
DEFINE_SET_AND_GET_METHOD(HippyRunApplicationEnd, TimePoint, hippy_run_application_end_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameStart, TimePoint, hippy_first_frame_start_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameEnd, TimePoint, hippy_first_frame_end_)
#undef DEFINE_SET_AND_GET_METHOD

inline auto GetEngineInitializationEnd() const {
return engine_initialization_end_;
inline const std::vector<BundleInfo>& GetBundleInfoArray() const {
return bundle_info_array_;
}

inline auto GetBundleInfo() const {
return bundle_info_;
}

inline auto GetLoadInstanceStart() const {
return load_instance_start_;
}

inline auto GetLoadInstanceEnd() const {
return load_instance_end_;
}

inline auto GetFirstFrame() const {
return first_frame_;
}
BundleInfo& BundleInfoOfUrl(const string_view& url);

virtual string_view ToJSON() override;

private:
// TimePoint dom_complete_;
// TimePoint dom_content_loaded_event_end_;
// TimePoint dom_content_loaded_event_start_;
// TimePoint dom_interactive_;
// TimePoint load_event_end_;
// TimePoint load_event_start_;
// uint32_t redirect_count_;
// TimePoint request_start_;
// TimePoint response_start_;
// string_view type_; // navigate, reload, back_forward or prerender
// TimePoint unload_event_end_;
// TimePoint unload_event_start_;
TimePoint engine_initialization_start_;
TimePoint engine_initialization_end_;
std::vector<BundleInfo> bundle_info_;
TimePoint load_instance_start_;
TimePoint load_instance_end_;
TimePoint first_frame_;
TimePoint hippy_native_init_start_;
TimePoint hippy_native_init_end_;
TimePoint hippy_js_engine_init_start_;
TimePoint hippy_js_engine_init_end_;
std::vector<BundleInfo> bundle_info_array_;
TimePoint hippy_run_application_start_;
TimePoint hippy_run_application_end_;
TimePoint hippy_first_frame_start_;
TimePoint hippy_first_frame_end_;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PerformancePaintTiming : public PerformanceEntry {
};

PerformancePaintTiming(Type type, const TimePoint& start_time);
PerformancePaintTiming(Type type);

virtual string_view ToJSON() override;

Expand Down
107 changes: 15 additions & 92 deletions driver/js/include/driver/performance/performance_resource_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,109 +31,32 @@ inline namespace performance {
class PerformanceResourceTiming: public PerformanceEntry {
public:
enum class InitiatorType {
AUDIO, BEACON, BODY, CSS, EARLY_HINT, EMBED, FETCH, FRAME, IFRAME, ICON, IMAGE, IMG, INPUT, LINK, NAVIGATION, OBJECT,
OTHER, AUDIO, BEACON, BODY, CSS, EARLY_HINT, EMBED, FETCH, FRAME, IFRAME, ICON, IMAGE, IMG, INPUT, LINK, NAVIGATION, OBJECT,
PING, SCRIPT, TRACK, VIDEO, XMLHTTPREQUEST
};

PerformanceResourceTiming(const string_view& name, TimePoint start_time, TimeDelta duration,
const InitiatorType& initiator_type, const string_view& next_hop_protocol, TimePoint worker_start,
TimePoint redirect_start, TimePoint redirect_end, TimePoint fetch_start,
TimePoint domain_lookup_start, TimePoint domain_lookup_end, TimePoint connect_start,
TimePoint connect_end, TimePoint secure_connection_start, TimePoint request_start_,
TimePoint response_start, TimePoint response_end, uint64_t transfer_size,
uint64_t encoded_body_size, uint64_t decoded_body_size);
PerformanceResourceTiming(const string_view& name);

inline InitiatorType GetInitiatorType() {
return initiator_type_;
}

inline string_view GetNextHopProtocol() {
return next_hop_protocol_;
}

inline TimePoint GetWorkerStart() {
return worker_start_;
}

inline TimePoint GetRedirectStart() {
return redirect_start_;
}

inline TimePoint GetRedirectEnd() {
return redirect_end_;
}

inline TimePoint GetFetchStart() {
return fetch_start_;
}

inline TimePoint GetDomainLookupStart() {
return domain_lookup_start_;
}

inline TimePoint GetDomainLookupEnd() {
return domain_lookup_end_;
}

inline TimePoint GetConnectStart() {
return connect_start_;
}

inline TimePoint GetConnectEnd() {
return connect_end_;
}

inline TimePoint GetSecureConnectionStart() {
return secure_connection_start_;
}

inline TimePoint GetRequestStart() {
return request_start_;
}

inline TimePoint GetResponseStart() {
return response_start_;
}

inline TimePoint GetResponseEnd() {
return response_end_;
}

inline uint64_t GetTransferSize() {
return transfer_size_;
}

inline uint64_t GetEncodedBodySize() {
return encoded_body_size_;
}

inline uint64_t GetDecodedBodySize() {
return decoded_body_size_;
#define DEFINE_SET_AND_GET_METHOD(method_name, member_type, member) \
void Set##method_name(member_type t) { \
member = t; \
} \
inline auto Get##method_name() const { \
return member; \
}
DEFINE_SET_AND_GET_METHOD(InitiatorType, InitiatorType, initiator_type_)
DEFINE_SET_AND_GET_METHOD(LoadSourceStart, TimePoint, load_source_start_)
DEFINE_SET_AND_GET_METHOD(LoadSourceEnd, TimePoint, load_source_end_)
#undef DEFINE_SET_AND_GET_METHOD

virtual string_view ToJSON() override;

static string_view GetInitiatorString(InitiatorType type);

private:
InitiatorType initiator_type_;
string_view next_hop_protocol_;
TimePoint worker_start_;
TimePoint redirect_start_;
TimePoint redirect_end_;
TimePoint fetch_start_;
TimePoint domain_lookup_start_;
TimePoint domain_lookup_end_;
TimePoint connect_start_;
TimePoint connect_end_;
TimePoint secure_connection_start_;
TimePoint request_start_;
TimePoint response_start_;
TimePoint response_end_;
uint64_t transfer_size_;
uint64_t encoded_body_size_;
uint64_t decoded_body_size_;
// std::vector<> server_timing_{};
InitiatorType initiator_type_ = InitiatorType::OTHER;
TimePoint load_source_start_;
TimePoint load_source_end_;
};

}
Expand Down
18 changes: 18 additions & 0 deletions driver/js/include/driver/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Scope : public std::enable_shared_from_this<Scope> {
using Encoding = hippy::napi::Encoding;
using TaskRunner = footstone::runner::TaskRunner;
using Task = footstone::Task;
using TimePoint = footstone::TimePoint;

#ifdef ENABLE_INSPECTOR
using DevtoolsDataSource = hippy::devtools::DevtoolsDataSource;
Expand Down Expand Up @@ -241,6 +242,7 @@ class Scope : public std::enable_shared_from_this<Scope> {
uint64_t GetListenerId(const EventListenerInfo& event_listener_info);

void RunJS(const string_view& js,
const string_view& uri,
const string_view& name,
bool is_copy = true);

Expand Down Expand Up @@ -270,6 +272,22 @@ class Scope : public std::enable_shared_from_this<Scope> {

inline void SetUriLoader(std::weak_ptr<UriLoader> loader) {
loader_ = loader;
auto the_loader = loader_.lock();
if (the_loader) {
the_loader->SetRequestTimePerformanceCallback([WEAK_THIS](const string_view& uri, const TimePoint& start, const TimePoint& end) {
DEFINE_AND_CHECK_SELF(Scope)
auto runner = self->GetTaskRunner();
if (runner) {
auto task = [weak_this, uri, start, end]() {
DEFINE_AND_CHECK_SELF(Scope)
auto entry = self->GetPerformance()->PerformanceResource(uri);
entry->SetLoadSourceStart(start);
entry->SetLoadSourceEnd(end);
};
runner->PostTask(std::move(task));
}
});
}
}

inline std::weak_ptr<UriLoader> GetUriLoader() { return loader_; }
Expand Down
9 changes: 9 additions & 0 deletions driver/js/src/js_driver_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
<< ", script content empty, uri = " << uri;
return false;
}

// perfromance start time
auto entry = scope->GetPerformance()->PerformanceNavigation("hippyInit");
entry->BundleInfoOfUrl(uri).execute_source_start_ = footstone::TimePoint::SystemNow();

#ifdef JS_V8
auto ret = std::static_pointer_cast<V8Ctx>(scope->GetContext())->RunScript(
script_content, file_name, is_use_code_cache,&code_cache_content, true);
Expand Down Expand Up @@ -357,8 +362,12 @@ bool JsDriverUtils::RunScript(const std::shared_ptr<Scope>& scope,
auto ret = scope->GetContext()->RunScript(script_content, file_name);
#endif

// perfromance end time
entry->BundleInfoOfUrl(uri).execute_source_end_ = footstone::TimePoint::SystemNow();

auto flag = (ret != nullptr);
FOOTSTONE_LOG(INFO) << "runScript end, flag = " << flag;

return flag;
}

Expand Down
2 changes: 1 addition & 1 deletion driver/js/src/modules/contextify_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void ContextifyModule::LoadUntrustedContent(CallbackInfo& info, void* data) {
auto try_catch = CreateTryCatchScope(true, scope->GetContext());
try_catch->SetVerbose(true);
string_view view_code(reinterpret_cast<const string_view::char8_t_ *>(move_code.c_str()), move_code.length());
scope->RunJS(view_code, file_name);
scope->RunJS(view_code, uri, file_name);
ctx->SetProperty(global_object, cur_dir_key, last_dir_str_obj, hippy::napi::PropertyAttribute::ReadOnly);
if (try_catch->HasCaught()) {
error = try_catch->Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ std::shared_ptr<ClassTemplate<PerformanceEntry>> RegisterPerformanceEntry(const
return nullptr;
}

auto entry = scope->GetPerformance()->GetEntriesByName(name, static_cast<PerformanceEntry::Type>(type));
if (!entry) {
auto entries = scope->GetPerformance()->GetEntriesByName(name, static_cast<PerformanceEntry::Type>(type));
if (entries.empty()) {
exception = context->CreateException("entry not found");
return nullptr;
}
return entry;
return entries.back();
};
return std::make_shared<ClassTemplate<PerformanceEntry>>(std::move(class_template));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ std::shared_ptr<ClassTemplate<PerformanceFrameTiming>> RegisterPerformanceFrameT
return nullptr;
}

auto entry = scope->GetPerformance()->GetEntriesByName(name, static_cast<PerformanceEntry::Type>(type));
if (!entry) {
auto entries = scope->GetPerformance()->GetEntriesByName(name, static_cast<PerformanceEntry::Type>(type));
if (entries.empty()) {
exception = context->CreateException("entry not found");
return nullptr;
}
return std::static_pointer_cast<PerformanceFrameTiming>(entry);
return std::static_pointer_cast<PerformanceFrameTiming>(entries.back());
};

return std::make_shared<ClassTemplate<PerformanceFrameTiming>>(std::move(class_template));
Expand Down
Loading
Loading