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

optimize: take action #198

Merged
merged 1 commit into from
Oct 8, 2022
Merged

optimize: take action #198

merged 1 commit into from
Oct 8, 2022

Conversation

hyj1991
Copy link
Member

@hyj1991 hyj1991 commented Oct 8, 2022

背景

早期 1.x 版本在尚未实现 worker_threads 监控时,开发者的采样操作会通过 requestInterrupt & uv_async_send 同时通知js 主线程 —— 这意味着 HandleAction 在早期实现中会执行两次。

因此旧版实现中在 HandleAction 执行前校验了 TransactionDone 这个函数,通过 ${uuid}::${action} 的唯一 key 设置状态判断当前的 action 是否已经由 requestInterrupt or uv_async_send 执行过了,如果已经执行过,则清理 data 然后返回。

而在最新的实现中,将 HandleAction 放置到一个 lambda 回调中:

static void NotifyJsThread(EnvironmentData* env_data, void* data) {
  env_data->RequestInterrupt(
      [data](EnvironmentData* env_data, InterruptKind kind) {
        HandleAction(env_data->isolate(), data,
                     kind == InterruptKind::kBusy ? "v8_request_interrupt" : "uv_async_send");
      });
}

并且这个回调函数会放入每一个 EnvData 对应的 std:list 中,这样 requestInterrupt & uv_async_send 先触发的那一个会通过 std::list::swap 执行回调,后触发拿到的 std::list 为空不会再触发。

这样 HandleAction 只会执行一次,旧版本中设计的 TransactionDone 逻辑不再需要。

优化

移除当前实现中为 HandleAction 执行两次所做的冗余设计逻辑

@hyj1991 hyj1991 requested a review from legendecas October 8, 2022 10:09
@codecov
Copy link

codecov bot commented Oct 8, 2022

Codecov Report

Merging #198 (9c9d333) into master (27f95d0) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master      #198   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          296       296           
=========================================
  Hits           296       296           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

#define CLEAR_DATA \
DebugT(module_type, env_data->thread_id(), "<%s> %s dump_data cleared.", \
notify_type.c_str(), unique_key.c_str()); \
delete dump_data;
Copy link
Member

Choose a reason for hiding this comment

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

得看看怎么把这个变成智能指针 -。-

Copy link
Member Author

@hyj1991 hyj1991 Oct 8, 2022

Choose a reason for hiding this comment

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

我也想过这里用智能指针,不过我不太熟悉怕反而写出来 bug,要不合并后你来看看是否可以重构成智能指针?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

这个 pr 主要目的还是清理掉已经无用的旧逻辑

@legendecas legendecas merged commit 7d3fbb2 into X-Profiler:master Oct 8, 2022
@hyj1991 hyj1991 mentioned this pull request Oct 22, 2022
hyj1991 added a commit that referenced this pull request Oct 22, 2022
Commits:

  - [2f700fd] docs: update readme (#207)
  - [f4eb960] feat: support node-v19.x (#206)
  - [333593e] chore: make test more reliable (#205)
  - [c574ca2] feat: save Elf BuildId in corefile. (#204)
  - [b779aa2] feat: support finish profiling before process exit (#203)
  - [6a1701f] refactor: replace dump actions static storages with EnvironmentData (#202)
  - [7608a86] fix: ignore clean error (#200)
  - [2a6eaba] chore: static dispatch on dumpaction (#199)
  - [7d3fbb2] optimize: take action (#198)
    
PR-URL: #208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants