{"id":1017,"date":"2015-04-20T13:45:41","date_gmt":"2015-04-20T17:45:41","guid":{"rendered":"http:\/\/benjamin.smedbergs.us\/blog\/?p=1017"},"modified":"2019-12-19T11:03:39","modified_gmt":"2019-12-19T15:03:39","slug":"using-crash-stats-api-magic","status":"publish","type":"post","link":"https:\/\/benjamin.smedbergs.us\/blog\/2015-04-20\/using-crash-stats-api-magic\/","title":{"rendered":"Using crash-stats-api-magic"},"content":{"rendered":"<p>A while back, I wrote the tool <a href=\"http:\/\/bsmedberg.github.io\/crash-stats-api-magic\/analyze-crash.html\">crash-stats-api-magic<\/a> which allows custom processing of results from the crash-stats API. This tool is not user-friendly, but it can be used to answer some pretty complicated questions.<\/p>\n<p>As an example and demonstration, see <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1156172\">a bug<\/a> that <a href=\"http:\/\/blog.mjg.im\/\">Matthew Gregan<\/a> filed this morning asking for a custom report from crash-stats:<\/p>\n<blockquote><p>In trying to debug bug 1135562, it&#8217;s hard to guess the severity of the problem or look for any type of version\/etc. correlation because there are many types of hangs caught under the same mozilla::MediaShutdownManager::Shutdown stack.  I&#8217;d like a report that contains only those with mozilla::MediaShutdownManager::Shutdown in the hung (main thread) stack *and* has wasapi_stream_init on one of the other threads, please.<\/p><\/blockquote>\n<p>To build this report, start with a basic query and then refine it in the tool:<\/p>\n<ol>\n<li>Construct a <a href=\"https:\/\/crash-stats.mozilla.com\/search\/?signature=~MediaShutdownManager%3A%3AShutdown&#038;_facets=signature&#038;_columns=date&#038;_columns=signature&#038;_columns=product&#038;_columns=version&#038;_columns=build_id&#038;_columns=platform\">supersearch query<\/a> to select the crashes we&#8217;re interested in. The only criteria for this query was &#8220;signature contains &#8216;MediaShutdownManager::Shutdown`. When possible, filter on channel, OS, and version to reduce noise.\n<li>After the supersearch query is constructed, choose &#8220;More Options&#8221; from the results page and copy the &#8220;Public API URL&#8221; link.\n<li>Load <a href=\"http:\/\/bsmedberg.github.io\/crash-stats-api-magic\/analyze-crash.html\">crash-stats-api-magic<\/a> and paste the query URL. Choose &#8220;Fetch&#8221; to fetch the results. Look through the raw data to get a sense for its structure. <a href=\"http:\/\/bsmedberg.github.io\/crash-stats-api-magic\/analyze-crash.html?url=https%3A%2F%2Fcrash-stats.mozilla.com%2Fapi%2FSuperSearch%2F%3Fsignature%3D~mozilla%253A%253AMediaShutdownManager%253A%253AShutdown%26_columns%3Ddate%26_columns%3Dsignature%26_columns%3Dproduct%26_columns%3Dversion%26_columns%3Dbuild_id%26_columns%3Dplatform&#038;rulecount=0\">Link<\/a>\n<li>The meat of this function is to filter out the crashes that don&#8217;t have &#8220;wasapi_stream_init&#8221; on a thread. Choose &#8220;New Rule&#8221; and create a filter rule:\n<pre>function(d) {\r\n  var ok = false;\r\n  d.json_dump.threads.forEach(function(thread) {\r\n    thread.frames.forEach(function(frame) {\r\n      if (frame.function && frame.function.indexOf(\"wasapi_stream_init\") != -1) {\r\n        ok = true;\r\n      }\r\n    });\r\n  });\r\n  return ok;\r\n}<\/pre>\n<p>Choose &#8220;Execute&#8221; to run the filter. <a href=\"http:\/\/bsmedberg.github.io\/crash-stats-api-magic\/analyze-crash.html?url=https%3A%2F%2Fcrash-stats.mozilla.com%2Fapi%2FSuperSearch%2F%3Fsignature%3D~mozilla%253A%253AMediaShutdownManager%253A%253AShutdown%26_columns%3Ddate%26_columns%3Dsignature%26_columns%3Dproduct%26_columns%3Dversion%26_columns%3Dbuild_id%26_columns%3Dplatform&#038;rulecount=1&#038;rule0_action=filter&#038;rule0_fn=function%28d%29%20%7B%0A%20%20var%20ok%20%3D%20false%3B%0A%20%20d.json_dump.threads.forEach%28function%28thread%29%20%7B%0A%20%20%20%20thread.frames.forEach%28function%28frame%29%20%7B%0A%20%20%20%20%20%20if%20%28frame.function%20%26%26%20frame.function.indexOf%28%22wasapi_stream_init%22%29%20!%3D%20-1%29%20%7B%0A%20%20%20%20%20%20%20%20ok%20%3D%20true%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%29%3B%0A%20%20%7D%29%3B%0A%20%20return%20ok%3B%0A%7D\">Link<\/a><\/p>\n<li>To get the final report we output only the signature and the crash ID for each result. Choose &#8220;New Rule&#8221; again and create a mapping rule:\n<pre>function(d) {\r\n  return [d.uuid, d.signature];\r\n}<\/pre>\n<p> <a href=\"http:\/\/bsmedberg.github.io\/crash-stats-api-magic\/analyze-crash.html?url=https%3A%2F%2Fcrash-stats.mozilla.com%2Fapi%2FSuperSearch%2F%3Fsignature%3D~mozilla%253A%253AMediaShutdownManager%253A%253AShutdown%26_columns%3Ddate%26_columns%3Dsignature%26_columns%3Dproduct%26_columns%3Dversion%26_columns%3Dbuild_id%26_columns%3Dplatform&#038;rulecount=2&#038;rule0_action=filter&#038;rule0_fn=function%28d%29%20%7B%0A%20%20var%20ok%20%3D%20false%3B%0A%20%20d.json_dump.threads.forEach%28function%28thread%29%20%7B%0A%20%20%20%20thread.frames.forEach%28function%28frame%29%20%7B%0A%20%20%20%20%20%20if%20%28frame.function%20%26%26%20frame.function.indexOf%28%22wasapi_stream_init%22%29%20!%3D%20-1%29%20%7B%0A%20%20%20%20%20%20%20%20ok%20%3D%20true%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%29%3B%0A%20%20%7D%29%3B%0A%20%20return%20ok%3B%0A%7D&#038;rule1_action=map&#038;rule1_fn=function%28d%29%20%7B%0A%20%20return%20%5Bd.uuid%2C%20d.signature%5D%3B%0A%7D\">Link<\/a>\n<\/ol>\n<p>One of the advantages of this tool is that it is possible to iterate quickly on the data without constantly re-querying, but at the end it should be possible to permalink to the results in bugzilla or email exchanges.<\/p>\n<p>If you need to do complex crash-stats analysis, please try it out! email me if you have questions, and <a href=\"https:\/\/github.com\/bsmedberg\/crash-stats-api-magic\">pull requests<\/a> are welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while back, I wrote the tool crash-stats-api-magic which allows custom processing of results from the crash-stats API. This tool is not user-friendly, but it can be used to answer some pretty complicated questions. As an example and demonstration, see a bug that Matthew Gregan filed this morning asking for a custom report from crash-stats: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[303,50],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-mozilla","tag-crash-stats-api-magic","tag-socorro"],"_links":{"self":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":10,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts\/1017\/revisions"}],"predecessor-version":[{"id":1027,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts\/1017\/revisions\/1027"}],"wp:attachment":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/categories?post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/tags?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}