Skip to content

Implement console log reporting for workers #6866

Closed

Description

@jdm

There's a TODO about workers in propagate_console_msg. The easiest way forward is:

  • modify the SendConsoleMsg enum to include an Option<WorkerId> field
  • add a worker_id field to WorkerGlobalScope that is passed in as an argument in the constructor (new and new_inherited)
  • add a worker_id method to GlobalRef that returns None for a non-worker and the new field for a worker
  • modify propagate_console_msg to use the required GlobalRef methods instead of matching on the specific type

After these changes, it should be possible to connect to a worker from the devtools, execute a console.log("hi") and see it appear in the devtools console log.

Activity

  1. added
    E-more-complex
    on Jul 31, 2015
  2. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    @jdm I'd like to give this a shot, but I might need some help if you don't mind.

  3. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    @HarryLovesCode of course! Note that you won't be able to test changes until #6829 merges.

  4. added
    C-assigned
    on Jul 31, 2015
  5. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    @jdm As a clarification, do you mean "anything except a worker" for the third point? Or do you mean a "non-worker" as in a window?

  6. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    Well, there are only Workers and Windows in GlobalRef, so the difference is only a semantic one :)

  7. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    Oh, the other part of this work is to modify handle_console_message (http://mxr.mozilla.org/servo/source/components/devtools/lib.rs#256) to use the new WorkerId information to find the appropriate ConsoleActor that is associated with a worker.

    For that, I recommend:

    • adding a console_actor field to WorkerActor and filling it appropriately in handle_new_global
    • in handle_console_msg, pass in the actor_workers hashmap and use it to find the WorkerActor for the given WorkerId and PipelineId, and fetch the console actor based on the field added in the previous step
  8. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    @jdm Just making sure :). Also I don't see WorkerGlobalScope::new() only WorkerGlobalScope::new_inherited(). Did you mean DedicatedWorkerGlobalScope?

  9. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    I did and I didn't. The field should be added to WorkerGlobalScope, which is inherited by DedicatedWorkerGlobalScope (for all practical purposes), so it should be passed in through the constructor of both DedicatedWorkerGlobalScope and WorkerGlobalScope.

    Also, if you need to do any testing of the devtools stuff, https://github.com/servo/servo/wiki/Devtools should have you covered.

  10. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    @jdm I appreciate you helping me out as I'm new to Rust. Two more things:

    1. Should the propagate_console_msg behave any differently if it matches to a worker?
    2. Do you mind to explain your second point? I see what you're talking about, but I don't understand when we should find the WorkerActor unless we check for that and then get its ConsoleActor accordingly.
  11. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor
    1. The code in propagate_console_msg should not behave any differently; there should be no match at all and it should get the values it requires directly from the GlobalRef methods.
    2. in handle_console_message, if there's a non-None value for the worker id then we should search for a WorkerActor instead of a TabActor (using the worker id and pipeline id present in the message we received), and get the name of the appropriate ConsoleActor from this result. Does that make sense?
  12. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    It makes sense, but I'm not sure how to pattern match that... Sorry :/ Mind to lend a hand?

  13. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    Assuming something like

         fn find_console_actor(actors: Arc<Mutex<ActorRegistry>>,
                               id: PipelineId,
                               worker_id: Option<WorkerId>,
                               worker_actors: &HashMap<(PipelineId, WorkerId), String>,
                               actor_pipelines: &HashMap<PipelineId, String>) -> Option<String> {

    We can do this:

    if let Some(worker_id) = worker_id {
        let worker_actor_name = match worker_actors.get(&(id, worker_id)) {
            Some(name) => name,
            None => return,
        };
        // find the worker actor, fetch the console_actor name from it, return the name
    }

    Is that more clear?

  14. 2 remaining items

  15. jdm commented on Jul 31, 2015

    @jdm
    MemberAuthor

    In theory there should be a backtrace of the failure showing up when that happens, and it should show who's calling unwrap.

  16. HarryLovesCode commented on Jul 31, 2015

    @HarryLovesCode
    Contributor

    @jdm Got it. Logging works from web workers (at least to the console), but devtools causes a crash. I assume #6829 will fix the issue with devtools?

  17. jdm commented on Aug 1, 2015

    @jdm
    MemberAuthor

    It might! We should be able to find out soon.

  18. jdm commented on Aug 1, 2015

    @jdm
    MemberAuthor

    It merged, so it should be possible to test this manually by connecting to a page with a worker (<script>new Worker('worker.js')</script>) and executing console.log('hi') in the web console that appears.

  19. HarryLovesCode commented on Aug 1, 2015

    @HarryLovesCode
    Contributor

    @jdm I'm trying to use the web console, but no logging appears at all (even a simple console.log("TEST") from outside of a worker).

  20. HarryLovesCode commented on Aug 1, 2015

    @HarryLovesCode
    Contributor

    @Wafflespeanut Oh! I see. My bad. I didn't notice you said it would appear in the "JSON-like stuff."

    To answer the second part, I've done everything, but handle_console_message.

  21. HarryLovesCode commented on Aug 1, 2015

    @HarryLovesCode
    Contributor

    @Wafflespeanut That helps a lot. I'll commit the changes in a few minutes. I've got it working properly now. Sorry about the confusion.

  22. added a commit that references this issue on Aug 2, 2015
  23. frewsxcv commented on Aug 3, 2015

    @frewsxcv
    Contributor

    We should probably create a regression test for this before closing

    EDIT: or close this and open a new issue

  24. jdm commented on Aug 3, 2015

    @jdm
    MemberAuthor

    We can't without #5971, unfortunately.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-devtoolsC-assignedE-more-complex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions