<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>10886</bug_id>
          
          <creation_ts>2017-01-06 11:13:15 +0000</creation_ts>
          <short_desc>Improve event documentation</short_desc>
          <delta_ts>2017-01-24 00:10:07 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>9</classification_id>
          <classification>Documentation</classification>
          <product>BitBake User Manual</product>
          <component>bitbake-manual</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>23 Jan 2017: RESOLVED</status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.3 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Richard Purdie">richard.purdie</reporter>
          <assigned_to name="Scott Rifenbark">srifenbark</assigned_to>
          <cc>patrick.ohly</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Done (doc changes complete)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>69565</commentid>
    <comment_count>0</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-01-06 11:13:15 +0000</bug_when>
    <thetext>The current &quot;Events&quot; section of the bitbake manual is a bit weak and ambiguous and the example is actually buggy. I&apos;d propose we revise it to read as follows: 

&quot;&quot;&quot;
BitBake allows installation of event handlers within recipe and class files. Events are triggered at certain points during operation, such as the beginning of operation against a given .bb, the start of a given task, task failure, task success, and so forth. The intent is to make it easy to do things like email notification on build failure.

Following is an example event handler that prints the name of the event and the content of the FILE variable:

     addhandler myclass_eventhandler
     python myclass_eventhandler() {
         from bb.event import getName
         from bb import data
         print(&quot;The name of the Event is %s&quot; % getName(e))
         print(&quot;The file we run for is %s&quot; % d.getVar(&apos;FILE&apos;))
     }
     myclass_eventhandler[eventmask] = &quot;bb.event.BuildStarted bb.event.BuildCompleted&quot;
            
In this example, an eventmask has been set so that the handler only sees &quot;BuildStarted&quot; and &quot;BuildCompleted&quot; events. This event handler gets called every time an event matching the eventmask is triggered. A global variable &quot;e&quot; is defined which represents the current event. With the getName(e) method, one can get the name of the triggered event. The global datastore is available as &quot;d&quot;. In old code, &quot;e.data&quot; may be used but it is deprecated and &quot;d&quot; should be used going forward.

The context of the datastore will be appropriate to the event in question. For example, &quot;BuildStarted&quot; and &quot;BuildCompleted&quot; events run before any tasks are executed so would be in the global configuration datastore namespace, there will be no recipe specific metadata there. They also run in the main cooker/server process rather than any worker so changes made to the datastore would be seen by other cooker/server events within the current build but not outside of that build or in the workers. Task events run in the actual tasks in question so have recipe and task specific contents. These are run in the worker context and are discarded at the end of task execution.


During a standard build, the following common events might occur:

    bb.event.ConfigParsed()

    bb.event.ParseStarted()

    bb.event.ParseProgress()

    bb.event.ParseCompleted()

    bb.event.BuildStarted()

    bb.build.TaskStarted()

    bb.build.TaskInvalid()

    bb.build.TaskFailedSilent()

    bb.build.TaskFailed()

    bb.build.TaskSucceeded()

    bb.event.BuildCompleted()

    bb.cooker.CookerExit() 

These events are the most common kinds of events that most metadata might have an interest in viewing.

There are also events that occur based on specific requests to the server, some common examples are:

    bb.event.TreeDataPreparationStarted()

    bb.event.TreeDataPreparationProgress()

    bb.event.TreeDataPreparationCompleted()

    bb.event.DepTreeGenerated()

    bb.event.CoreBaseFilesFound()

    bb.event.ConfigFilePathFound()

    bb.event.FilesMatchingFound()

    bb.event.ConfigFilesFound()

    bb.event.TargetsTreeGenerated()

These are often used to communicate larger pieces of information from the bitbake server to other parts of bitbake such as UIs.
&quot;&quot;&quot;

This still isn&apos;t perfect but it documents event scope, the eventmask and fixes the example.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69566</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-01-06 11:41:47 +0000</bug_when>
    <thetext>Updated event descriptions:     
bb.event.ConfigParsed() - Fired when the base configuration has been parsed, bitbake.conf, base.bbclass and any global INHERITs. You can see multiple such events, when each of the workers parse the base configuration of if the server changes configuration and reparses. Any given datastore will only have one such event executed agaisnt it however. If BB_INVALIDCONF is set in the datastore by the event handler, the configuration will be reparsed and a new event triggered, allowing the metadata to update configuration.

    bb.event.ParseStarted() - Fired when bitbake is about to start parsing recipes, has a &apos;total&apos; attribute which represents the number of recipes bitbake plans to parse.

    bb.event.ParseProgress() - Fired as parsing progresses, has a &apos;current&apos; attribute of the number of recipes parsed as well as a &apos;total&apos; attribute.

    bb.event.ParseCompleted() - Fired when parsing is complete, has &apos;cached&apos;, &apos;parsed&apos;, &apos;skipped&apos;, &apos;virtuals&apos;, &apos;masked&apos;, and &apos;errors&apos; attributes giving statistics about the parsing results.

    bb.event.BuildStarted() - Fired when a new build is started

    bb.build.TaskStarted() - Fired when a task starts, has a &apos;taskfile&apos; attribute which points to the recipe the task is from, a &apos;taskname&apos; attribute for the task&apos;s name (including the &apos;do_&apos; prefix), a &apos;logfile&apos; attribute pointing to where the task&apos;s output is stored and a &apos;time&apos; attribute for the task execution start time.

    bb.build.TaskInvalid() - Fired if bitbake tries to execute a task which does not exist.

    bb.build.TaskFailedSilent() - Fired for setscene tasks which fail and shouldn&apos;t be presented to the user verbosely 

    bb.build.TaskFailed() - Fired for normal tasks which fail

    bb.build.TaskSucceeded() - Fired when a task completes successfully

    bb.event.BuildCompleted() - Fired when a build has finished

    bb.cooker.CookerExit() - Fired when the bitbake server/cooker shuts down. Usually only seen by the UIs as a sign they should shutdown too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69567</commentid>
    <comment_count>2</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-01-06 12:05:02 +0000</bug_when>
    <thetext>Do all of these events fire in the same process?

When working on system statistics sampling, it wasn&apos;t clear whether writing into the shared files had to be protected against concurrent writes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69568</commentid>
    <comment_count>3</comment_count>
    <who name="Patrick Ohly">patrick.ohly</who>
    <bug_when>2017-01-06 12:13:50 +0000</bug_when>
    <thetext>(In reply to comment #0)
&gt; During a standard build, the following common events might occur:
&gt; 
&gt;     bb.event.ConfigParsed()

Add here:
      bb.event.HeartbeatEvent()

And as description:

bb.event.BuildStarted() - Fires at regular time intervals of 1 second, with the interval configurable with BB_HEARTBEAT_EVENT. Has a &apos;time&apos; attribute which is the time.time() value when the event was triggered. Useful for activities like system state monitoring.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69661</commentid>
    <comment_count>4</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-01-10 17:29:23 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; Do all of these events fire in the same process?
&gt; 
&gt; When working on system statistics sampling, it wasn&apos;t clear whether writing
&gt; into the shared files had to be protected against concurrent writes.

I was trying to explain that with:

&quot;&quot;&quot;
The context of the datastore will be appropriate to the event in question. For example, &quot;BuildStarted&quot; and &quot;BuildCompleted&quot; events run before any tasks are executed so would be in the global configuration datastore namespace, there will be no recipe specific metadata there. They also run in the main cooker/server process rather than any worker so changes made to the datastore would be seen by other cooker/server events within the current build but not outside of that build or in the workers. Task events run in the actual tasks in question so have recipe and task specific contents. These are run in the worker context and are discarded at the end of task execution.
&quot;&quot;&quot;

not sure if that answers your question or not. If not, suggestions on how to make it clearer would likely help Scott.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69663</commentid>
    <comment_count>5</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2017-01-10 18:10:32 +0000</bug_when>
    <thetext>Hi, 

Here is the link to the updated &quot;Events&quot; section - https://bugzilla.yoctoproject.org/show_bug.cgi?id=10886.  Please look it over and let me know of any corrections. 

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69961</commentid>
    <comment_count>6</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2017-01-20 13:50:37 +0000</bug_when>
    <thetext>Ooops.. bad link in Comment 5 for the section to review.  Here is the right link: http://www.yoctoproject.org/docs/temp/bitbake-user-manual/bitbake-user-manual.html#events

Sorry, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69962</commentid>
    <comment_count>7</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2017-01-20 14:06:32 +0000</bug_when>
    <thetext>Looks good. Some quick tweaks:

You can drop the &quot;from bb import data&quot; line from the example.

 &quot;For legacy code, you can use &quot;e.data&quot; to get the name of the triggered event&quot; -&gt; &quot;In legacy code, you may see &quot;e.data&quot; used to get the datastore&quot;.

&quot; The &quot;taskname&quot; attribute, which includes the do_ prefix,&quot; -&gt;  &quot;The &quot;taskname&quot; attribute, which is the task&apos;s name, includes the do_ prefix,&quot;

Otherwise looks good to go thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70070</commentid>
    <comment_count>8</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2017-01-24 00:10:07 +0000</bug_when>
    <thetext>After Richard reviewed these chanages, all is good once a stray quote character was removed.  Setting the status to RESOLVED and putting the doc flag to &quot;done.&quot;

Scott</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>