)]}'
{"/PATCHSET_LEVEL":[{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"95a5464c5876f96842b04f85c73b0ec2638b7880","unresolved":false,"context_lines":[],"source_content_type":"","patch_set":2,"id":"3e57ac57_02a220ae","updated":"2025-02-07 04:10:23.000000000","message":"Valgrind reports no memory errors, and no additional leaks.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"22c9bc345bf415e6fb71be9639dabfee10cac8e5","unresolved":true,"context_lines":[],"source_content_type":"","patch_set":5,"id":"4d06ad21_5b9498d2","updated":"2025-08-08 09:36:52.000000000","message":"Hi Richard, are you aware of any remaining issues with this patch series?\n\nIt all looks good to me now, though the UINT16_MAX limit for buckets is very easily reached with the fast sampling on xtensa esp targets. The missing samples can then significantly skew gprof report. But it seems gprof does not support overlapping histograms so I dont see any way around this without some kind of information loss in the report.\n\nMaybe there could be an option to set divider for the number of samples? In any case that can be solved in a separate patch later.","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"4b98132c53643a5b240875a939da16a5f963c6ca","unresolved":false,"context_lines":[],"source_content_type":"","patch_set":5,"id":"dce353e4_b89082f4","in_reply_to":"140f77f7_c819510e","updated":"2025-08-11 07:00:10.000000000","message":"thanks, it still shows the \"Merge Conflict\" label for me, but I can apply the patches locally without any issue so maybe theres some glitch with that?","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"ee600feb812c42d2fb5d13453ed9113f3aec0696","unresolved":false,"context_lines":[],"source_content_type":"","patch_set":5,"id":"140f77f7_c819510e","in_reply_to":"27ba936f_fabb6460","updated":"2025-08-11 03:42:44.000000000","message":"\u003e Seems there are merge conflicts with master now, could you rebase?\n\nI\u0027ve rebased the patch-stack.","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"e8b75b68631a076d50217706525be9ff03c325d6","unresolved":true,"context_lines":[],"source_content_type":"","patch_set":5,"id":"ce640aa2_7d6de8e3","in_reply_to":"4d06ad21_5b9498d2","updated":"2025-08-09 02:34:28.000000000","message":"\u003e Hi Richard, are you aware of any remaining issues with this patch series?\n\nI\u0027m aware of two, but I think they\u0027re both best addressed later:\n\n1. gprof truncates all program counters to even addresses. See patch: https://sourceware.org/pipermail/binutils/2025-July/142972.html\n2. OpenOCD\u0027s buckets are still limited to UINT16_MAX, as you mention.\n2A. Reducing the JTAG link speed reduces profiling rate if needed.\n2B. gprof supports encoding \u003eUINT16_MAX sample counts by placing multiple single-bucket UINT16_MAX histograms into the file. But this will be simpler to do after #1 is addressed.\n\nDo we need to request a reviewer, or will they come when they have time?","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"3d6cd27e0739a40b2b4236852feed43bb99b5c69","unresolved":true,"context_lines":[],"source_content_type":"","patch_set":5,"id":"fb3ce6b6_9d9d25ae","in_reply_to":"ce640aa2_7d6de8e3","updated":"2025-08-09 16:53:20.000000000","message":"Ah, I dont know why I thought it wouldnt work with multiple histograms, thats good news!\n\nSeems there are merge conflicts with master now, could you rebase? And yes, probably need to request reviewers","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"6020f4b2961b887667168ffbdbbb6fc11b8d0d75","unresolved":false,"context_lines":[],"source_content_type":"","patch_set":5,"id":"996c4ea1_2ba12535","in_reply_to":"dce353e4_b89082f4","updated":"2025-08-11 23:41:58.000000000","message":"It shows \"Merge Conflict\" because this patch-stack needs each commit merged sequentially. When the one before this is merged, it\u0027ll no longer conflict.","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"642d812af555777a2a7a761cffc9d31b0c3583db","unresolved":false,"context_lines":[],"source_content_type":"","patch_set":5,"id":"27ba936f_fabb6460","in_reply_to":"fb3ce6b6_9d9d25ae","updated":"2025-08-10 03:15:31.000000000","message":"\u003e Ah, I don\u0027t know why I thought it wouldn\u0027t work with multiple histograms, that\u0027s good news!\n\nJust has to be done a little carefully. Each overlapping histogram must have the same start and end addresses.","commit_id":"3a70e3edc2a39bf469bd112d22e374838682b729"}],"src/target/target.c":[{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"e7b796736550068052b35d9bc2a1a56845d19037","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"1161c846_72621309","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"updated":"2025-02-11 14:44:08.000000000","message":"Hi Richard, it doesnt seem to work correctly for me with this patch. I only get a handful of functions in the gprof report, each with \u003c0.1% of the total runtime, so something is missing.\n\nCould you please recheck whether it works correctly for you?\n\nI didnt figure out whats causing the issue yet, but it seems that if I increase MAX_GAP to only get around 3 histograms, the generated gmon file is significantly (around 4x) larger than without this patch. Maybe thats useful for you to tell whats wrong?","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002278,"name":"bryghtlabs-richard","display_name":"Richard Allen","username":"bryghtlabs-richard","status":"Firmware at BryghtLabs. Also rsaxvc at home."},"change_message_id":"f8b4ce7117969cd9af675dcff024ddeae2dcd04e","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"e39c395c_1850c884","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"1161c846_72621309","updated":"2025-02-11 17:05:06.000000000","message":"Thanks Samuel - I will recheck. One thing I have had trouble with is when my CPU spends time running ROM or IRAM code, since gprof only parses one section, any samples in the other sections are not displayed.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"2fab181c712d458ec35a0f7ed6092ec671bf63e2","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"8da4845e_ee3bbe61","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"2f8015a4_e845950e","updated":"2025-02-13 15:12:20.000000000","message":"Thanks for the update, now increasing MAX_GAP doesnt seem to affect the results anymore.\n\nOn the other hand, I still seem to get different results with this patch than without it - now I have only 1 function with \u003e99%, plus some with \u003c0.1% of total runtime. Without this patch I got 4 functions with \u003e10% of runtime, plus many others (looks more likely to be correct to me).\n\nDo you see something similar? For reference, I am using esp32s3 with our test application, which should just be looping forever somewhere in FreeRTOS internals (https://github.com/espressif/openocd-esp32/blob/master/testing/esp/test_apps/gen_ut_app/main/gen_ut_app.c#L456)","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"645a0b37acceffc722a17bb9d0d032d3f1742333","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"fd7fccaa_599354b4","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"39400e93_c65615bc","updated":"2025-02-14 16:54:23.000000000","message":"Ah, yes, you are right. I also did not check carefully enough, because it still increases the file size with increased MAX_GAP, just not as much. THe max_buckets setting sounds like good explanation for this, I will check how it behaves with the increased value.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"001120577055d08cb0a7f872d4a69ffa367c4243","unresolved":false,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"ddeeadca_8b6ea251","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"52358884_6f39a267","updated":"2025-02-17 15:21:35.000000000","message":"\u003e Often the new approach is smaller too though.\n\nSignificantly smaller, in my case ~4KB with MAX_GAP\u003d32 instead of the ~256KB (thats why I am checking carefully whether something is not missing 😄 ). But this makes sense when only cycling somewhere, yet still running code from different memory regions.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002278,"name":"bryghtlabs-richard","display_name":"Richard Allen","username":"bryghtlabs-richard","status":"Firmware at BryghtLabs. Also rsaxvc at home."},"change_message_id":"cf7a46b9b8a58809693e61c9170ccc4ccd147e7a","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"39400e93_c65615bc","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"60f67910_adcf88c5","updated":"2025-02-14 14:42:53.000000000","message":"Another thing to check: before this patch, if your gmon.out was a little over 256KB, it is likely your recording was limited by the available resolution. If you increase max_buckets to 256*1024*1024, it will make a large histogram with good resolution, and gprof output of big histogram file should then match the results of gprof output from this patch.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"8d76593f6c315f68704343a8ccc05e657c056501","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"60f67910_adcf88c5","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"8da4845e_ee3bbe61","updated":"2025-02-14 03:12:08.000000000","message":"I did see something similar Samuel. Before this patch, our firmware idling at home screen showed most samples in two functions, but neither function was esp_cpu_wait_for_intr(), and one was not even called on the home screen. After this patch, with our device idling, 90+% time is spent doing esp_cpu_wait_for_intr().\n\n\u003e For reference, I am using esp32s3 with our test application, which should just be looping forever somewhere in FreeRTOS internals\n\nI\u0027m on the same chip, but large application. With most tasks looping forever in FreeRTOS, I believe most samples should point to the WAITI instruction in esp_cpu_wait_for_intr(). Before this patch, do most samples point to esp_cpu_wait_for_intr()? After this patch, do most samples point to esp_cpu_wait_for_intr()?","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002306,"name":"Richard Allen","display_name":"Richard Allen","email":"rsaxvc@rsaxvc.net"},"change_message_id":"8b3c5b516e42bdaba1cd6c9737d20adcd989f7df","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"2f8015a4_e845950e","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"a780cbfb_c6532529","updated":"2025-02-12 22:04:59.000000000","message":"Limiting to 2B/bin fixes this for me - could you please give it another try?","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002306,"name":"Richard Allen","display_name":"Richard Allen","email":"rsaxvc@rsaxvc.net"},"change_message_id":"5e86a1173735b2c920ad08a553bb5e3538525559","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"a780cbfb_c6532529","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"e39c395c_1850c884","updated":"2025-02-12 20:59:34.000000000","message":"Seems like another scaling issue in gprof. For now, I\u0027m going to try limiting histogram resolution to 2B/bin.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002278,"name":"bryghtlabs-richard","display_name":"Richard Allen","username":"bryghtlabs-richard","status":"Firmware at BryghtLabs. Also rsaxvc at home."},"change_message_id":"4d96944fc9ecd6ca2f8317fa415185e9a69a9c3e","unresolved":true,"context_lines":[{"line_number":4228,"context_line":""},{"line_number":4229,"context_line":"\twhile (sample_num) {"},{"line_number":4230,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4231,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4232,"context_line":""},{"line_number":4233,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4234,"context_line":"\t\tuint32_t min \u003d samples[0];"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"52358884_6f39a267","line":4231,"range":{"start_line":4231,"start_character":0,"end_line":4231,"end_character":3},"in_reply_to":"fd7fccaa_599354b4","updated":"2025-02-14 18:38:01.000000000","message":"\u003e because it still increases the file size with increased MAX_GAP, just not as much.\n\nMAX_GAP is the number of zero bins where we decide to emit a new histogram instead of extending the current one, so there\u0027s a trade-off between MAX_GAP, number of histograms per file, and size of file. I think 32 is an OK value to start with, but it\u0027s not critical, 16 and 64 work too.\n\nIf MAX_GAP is small, we\u0027ll make more histograms, and each has a little header overhead so the file might be larger than necessary, and gprof can run a little slower.\n\nIf MAX_GAP is large, it\u0027ll increase the filesize without much benefit, since each histogram will encode a lot of zero-bins.\n\nNote: GMON produced by this patch isn\u0027t always smaller, but I believe this patch\u0027s output is still better. Without this patch, when OpenOCD saves ~256KB GMON I know that the histogram bins are rounded, sometimes like ~250Bytes/bin for my product. If the samples are spread out through the executable address space, the same samples saved with this patch may produce a larger file, but the histogram bins are rounded to 2B/bin. Often the new approach is smaller too though.\n\nThank you for your help Samuel 😊","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002278,"name":"bryghtlabs-richard","display_name":"Richard Allen","username":"bryghtlabs-richard","status":"Firmware at BryghtLabs. Also rsaxvc at home."},"change_message_id":"d29a15b07cb93d6f4d8f2b46d99c821f057e72ee","unresolved":true,"context_lines":[{"line_number":4243,"context_line":""},{"line_number":4244,"context_line":"\t\t/* The ratio ((double)((max - min) / 2) / address_space) must match across"},{"line_number":4245,"context_line":"\t\t * all histograms in this file. To do so, we should have an even number of bins."},{"line_number":4246,"context_line":"\t\t * Refer to binutils/gprof/hist.c (rounding in calculation of n_hist_scale) */"},{"line_number":4247,"context_line":"\t\tif ((max - min) % 2)"},{"line_number":4248,"context_line":"\t\t\tmax++;"},{"line_number":4249,"context_line":"\t\tuint32_t address_space \u003d max - min;"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"4db945ac_3b64931c","line":4246,"updated":"2025-02-10 20:58:35.000000000","message":"TODO: update to mention that this is fixed in binutils at some point after 2.44.","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1002306,"name":"Richard Allen","display_name":"Richard Allen","email":"rsaxvc@rsaxvc.net"},"change_message_id":"8b3c5b516e42bdaba1cd6c9737d20adcd989f7df","unresolved":false,"context_lines":[{"line_number":4243,"context_line":""},{"line_number":4244,"context_line":"\t\t/* The ratio ((double)((max - min) / 2) / address_space) must match across"},{"line_number":4245,"context_line":"\t\t * all histograms in this file. To do so, we should have an even number of bins."},{"line_number":4246,"context_line":"\t\t * Refer to binutils/gprof/hist.c (rounding in calculation of n_hist_scale) */"},{"line_number":4247,"context_line":"\t\tif ((max - min) % 2)"},{"line_number":4248,"context_line":"\t\t\tmax++;"},{"line_number":4249,"context_line":"\t\tuint32_t address_space \u003d max - min;"}],"source_content_type":"text/x-csrc","patch_set":2,"id":"b18d371e_ad525391","line":4246,"in_reply_to":"4db945ac_3b64931c","updated":"2025-02-12 22:04:59.000000000","message":"Done","commit_id":"c3789f26103478fcea855b3aeb65f981f0a63e26"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"001120577055d08cb0a7f872d4a69ffa367c4243","unresolved":true,"context_lines":[{"line_number":4254,"context_line":"\t\tfor (; i \u003c sample_num \u0026\u0026 samples[i] \u003c bmax; ++i)"},{"line_number":4255,"context_line":"\t\t\tval++;"},{"line_number":4256,"context_line":"\t\tif (val \u003e UINT16_MAX) {"},{"line_number":4257,"context_line":"\t\t\tLOG_WARNING(\"profiler bucket saturated, will read as 65535\");"},{"line_number":4258,"context_line":"\t\t\tval \u003d UINT16_MAX;"},{"line_number":4259,"context_line":"\t\t}"},{"line_number":4260,"context_line":""}],"source_content_type":"text/x-csrc","patch_set":4,"id":"57a12b9f_0ab11f6c","side":"PARENT","line":4257,"range":{"start_line":4257,"start_character":3,"end_line":4257,"end_character":64},"updated":"2025-02-17 15:21:35.000000000","message":"This warning seems to be missing now","commit_id":"a78c5c6577e059960643daf8b17882ff7fa02193"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"25072b2e5f47d1d8a79ac988888ff6f656af219b","unresolved":false,"context_lines":[{"line_number":4254,"context_line":"\t\tfor (; i \u003c sample_num \u0026\u0026 samples[i] \u003c bmax; ++i)"},{"line_number":4255,"context_line":"\t\t\tval++;"},{"line_number":4256,"context_line":"\t\tif (val \u003e UINT16_MAX) {"},{"line_number":4257,"context_line":"\t\t\tLOG_WARNING(\"profiler bucket saturated, will read as 65535\");"},{"line_number":4258,"context_line":"\t\t\tval \u003d UINT16_MAX;"},{"line_number":4259,"context_line":"\t\t}"},{"line_number":4260,"context_line":""}],"source_content_type":"text/x-csrc","patch_set":4,"id":"ee20cd88_31152901","side":"PARENT","line":4257,"range":{"start_line":4257,"start_character":3,"end_line":4257,"end_character":64},"in_reply_to":"57a12b9f_0ab11f6c","updated":"2025-02-18 14:25:52.000000000","message":"Oops - lost while rebasing. It\u0027s back.","commit_id":"a78c5c6577e059960643daf8b17882ff7fa02193"},{"author":{"_account_id":1001803,"name":"Samuel Obuch","email":"samuel.obuch@espressif.com","username":"sobuch"},"change_message_id":"001120577055d08cb0a7f872d4a69ffa367c4243","unresolved":true,"context_lines":[{"line_number":4220,"context_line":"\twrite_long(f, 0, target); /* padding */"},{"line_number":4221,"context_line":"\twrite_long(f, 0, target); /* padding */"},{"line_number":4222,"context_line":""},{"line_number":4223,"context_line":"\twhile (sample_num) {"},{"line_number":4224,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4225,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4226,"context_line":""},{"line_number":4227,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4228,"context_line":"\t\tuint32_t min \u003d samples[0];"},{"line_number":4229,"context_line":"\t\tuint32_t max \u003d samples[0];"},{"line_number":4230,"context_line":"\t\tuint32_t this_pass \u003d 1;"},{"line_number":4231,"context_line":"\t\twhile (this_pass \u003c sample_num \u0026\u0026 samples[this_pass] - max \u003c MAX_GAP)"},{"line_number":4232,"context_line":"\t\t\tmax \u003d samples[this_pass++];"},{"line_number":4233,"context_line":""},{"line_number":4234,"context_line":"\t\t/* max should be (largest sample + 1)"},{"line_number":4235,"context_line":"\t\t * Refer to binutils/gprof/hist.c (find_histogram_for_pc) */"},{"line_number":4236,"context_line":"\t\tmax++;"},{"line_number":4237,"context_line":""},{"line_number":4238,"context_line":"\t\t/* The ratio ((double)((max - min) / 2) / num_buckets) must match across"},{"line_number":4239,"context_line":"\t\t * all histograms in this file. To avoid trunction in the /2, we must have"},{"line_number":4240,"context_line":"\t\t * an even length address space for compatibility with binutils \u003c\u003d2.44."},{"line_number":4241,"context_line":"\t\t * Refer to binutils/gprof/hist.c (calculation of n_hist_scale)*/"},{"line_number":4242,"context_line":"\t\tif ((max - min) % 2)"},{"line_number":4243,"context_line":"\t\t\tmax++;"},{"line_number":4244,"context_line":"\t\tuint32_t address_space \u003d max - min;"},{"line_number":4245,"context_line":""},{"line_number":4246,"context_line":"\t\tuint8_t zero \u003d 0;  /* GMON_TAG_TIME_HIST */"},{"line_number":4247,"context_line":"\t\twrite_data(f, \u0026zero, 1);"},{"line_number":4248,"context_line":""},{"line_number":4249,"context_line":"\t\t/* append binary memory gmon.out \u0026profile_hist_hdr ((char*)\u0026profile_hist_hdr + sizeof(struct gmon_hist_hdr)) */"},{"line_number":4250,"context_line":"\t\twrite_long(f, min, target);\t\t\t/* low_pc */"},{"line_number":4251,"context_line":"\t\twrite_long(f, max, target);\t\t\t/* high_pc */"},{"line_number":4252,"context_line":"\t\twrite_long(f, address_space / sizeof(UNIT), target);\t/* # of buckets */"},{"line_number":4253,"context_line":"\t\twrite_long(f, sample_rate, target);"},{"line_number":4254,"context_line":"\t\twrite_string(f, \"seconds\");"},{"line_number":4255,"context_line":"\t\tfor (uint32_t i \u003d 0; i \u003c (15 - strlen(\"seconds\")); i++)"},{"line_number":4256,"context_line":"\t\t\twrite_data(f, \u0026zero, 1);"},{"line_number":4257,"context_line":"\t\twrite_string(f, \"s\");"},{"line_number":4258,"context_line":""},{"line_number":4259,"context_line":"\t\t/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */"},{"line_number":4260,"context_line":"\t\tfor (uint32_t i \u003d 0, bidx \u003d 0; bidx \u003c address_space; bidx +\u003d sizeof(UNIT)) {"},{"line_number":4261,"context_line":"\t\t\tuint32_t val \u003d 0;"},{"line_number":4262,"context_line":"\t\t\tlong long bmax \u003d min + bidx;"},{"line_number":4263,"context_line":"\t\t\tfor ( ; i \u003c this_pass \u0026\u0026 samples[i] \u003c\u003d bmax; ++i)"},{"line_number":4264,"context_line":"\t\t\t\tval++;"},{"line_number":4265,"context_line":"\t\t\tif (val \u003e UINT16_MAX)"},{"line_number":4266,"context_line":"\t\t\t\tval \u003d UINT16_MAX;"},{"line_number":4267,"context_line":""},{"line_number":4268,"context_line":"\t\t\tuint8_t data[2];"},{"line_number":4269,"context_line":"\t\t\tdata[0] \u003d val \u0026 0xff;"},{"line_number":4270,"context_line":"\t\t\tdata[1] \u003d (val \u003e\u003e 8) \u0026 0xff;"},{"line_number":4271,"context_line":"\t\t\twrite_data(f, data, 2);"},{"line_number":4272,"context_line":"\t\t}"},{"line_number":4273,"context_line":""},{"line_number":4274,"context_line":"\t\tsamples +\u003d this_pass;"},{"line_number":4275,"context_line":"\t\tsample_num -\u003d this_pass;"},{"line_number":4276,"context_line":"\t}"},{"line_number":4277,"context_line":""},{"line_number":4278,"context_line":"\tfclose(f);"},{"line_number":4279,"context_line":"}"}],"source_content_type":"text/x-csrc","patch_set":4,"id":"d3fa7a79_27ded871","line":4276,"range":{"start_line":4223,"start_character":1,"end_line":4276,"end_character":2},"updated":"2025-02-17 15:21:35.000000000","message":"I would suggest splitting off the body of this cycle into a separate function, that way we can keep this simple:\n\n```\nwhile (sample_num) {\n\t/* if address gap exceeds this, make another histogram */\n\tconst uint32_t MAX_GAP \u003d 32;\n\n\t/* figure out bucket size */\n\tuint32_t max \u003d samples[0];\n\tuint32_t this_pass \u003d 1;\n\twhile (this_pass \u003c sample_num \u0026\u0026 samples[this_pass] - max \u003c MAX_GAP)\n\t\tmax \u003d samples[this_pass++];\n\n\twrite_hist(samples, this_pass, f, target, duration_ms);\n\n\tsamples +\u003d this_pass;\n\tsample_num -\u003d this_pass;\n}\n```","commit_id":"9d28c59e9ef28b500c15c0d31d57586313be7f5f"},{"author":{"_account_id":1002273,"name":"Richard Allen","email":"rsaxvc@gmail.com","username":"rsaxvc","status":"@BryghtLabs, @rsaxvc.net"},"change_message_id":"25072b2e5f47d1d8a79ac988888ff6f656af219b","unresolved":false,"context_lines":[{"line_number":4220,"context_line":"\twrite_long(f, 0, target); /* padding */"},{"line_number":4221,"context_line":"\twrite_long(f, 0, target); /* padding */"},{"line_number":4222,"context_line":""},{"line_number":4223,"context_line":"\twhile (sample_num) {"},{"line_number":4224,"context_line":"\t\t/* if address gap exceeds this, make another histogram */"},{"line_number":4225,"context_line":"\t\tconst uint32_t MAX_GAP \u003d 32;"},{"line_number":4226,"context_line":""},{"line_number":4227,"context_line":"\t\t/* figure out bucket size */"},{"line_number":4228,"context_line":"\t\tuint32_t min \u003d samples[0];"},{"line_number":4229,"context_line":"\t\tuint32_t max \u003d samples[0];"},{"line_number":4230,"context_line":"\t\tuint32_t this_pass \u003d 1;"},{"line_number":4231,"context_line":"\t\twhile (this_pass \u003c sample_num \u0026\u0026 samples[this_pass] - max \u003c MAX_GAP)"},{"line_number":4232,"context_line":"\t\t\tmax \u003d samples[this_pass++];"},{"line_number":4233,"context_line":""},{"line_number":4234,"context_line":"\t\t/* max should be (largest sample + 1)"},{"line_number":4235,"context_line":"\t\t * Refer to binutils/gprof/hist.c (find_histogram_for_pc) */"},{"line_number":4236,"context_line":"\t\tmax++;"},{"line_number":4237,"context_line":""},{"line_number":4238,"context_line":"\t\t/* The ratio ((double)((max - min) / 2) / num_buckets) must match across"},{"line_number":4239,"context_line":"\t\t * all histograms in this file. To avoid trunction in the /2, we must have"},{"line_number":4240,"context_line":"\t\t * an even length address space for compatibility with binutils \u003c\u003d2.44."},{"line_number":4241,"context_line":"\t\t * Refer to binutils/gprof/hist.c (calculation of n_hist_scale)*/"},{"line_number":4242,"context_line":"\t\tif ((max - min) % 2)"},{"line_number":4243,"context_line":"\t\t\tmax++;"},{"line_number":4244,"context_line":"\t\tuint32_t address_space \u003d max - min;"},{"line_number":4245,"context_line":""},{"line_number":4246,"context_line":"\t\tuint8_t zero \u003d 0;  /* GMON_TAG_TIME_HIST */"},{"line_number":4247,"context_line":"\t\twrite_data(f, \u0026zero, 1);"},{"line_number":4248,"context_line":""},{"line_number":4249,"context_line":"\t\t/* append binary memory gmon.out \u0026profile_hist_hdr ((char*)\u0026profile_hist_hdr + sizeof(struct gmon_hist_hdr)) */"},{"line_number":4250,"context_line":"\t\twrite_long(f, min, target);\t\t\t/* low_pc */"},{"line_number":4251,"context_line":"\t\twrite_long(f, max, target);\t\t\t/* high_pc */"},{"line_number":4252,"context_line":"\t\twrite_long(f, address_space / sizeof(UNIT), target);\t/* # of buckets */"},{"line_number":4253,"context_line":"\t\twrite_long(f, sample_rate, target);"},{"line_number":4254,"context_line":"\t\twrite_string(f, \"seconds\");"},{"line_number":4255,"context_line":"\t\tfor (uint32_t i \u003d 0; i \u003c (15 - strlen(\"seconds\")); i++)"},{"line_number":4256,"context_line":"\t\t\twrite_data(f, \u0026zero, 1);"},{"line_number":4257,"context_line":"\t\twrite_string(f, \"s\");"},{"line_number":4258,"context_line":""},{"line_number":4259,"context_line":"\t\t/*append binary memory gmon.out profile_hist_data (profile_hist_data + profile_hist_hdr.hist_size) */"},{"line_number":4260,"context_line":"\t\tfor (uint32_t i \u003d 0, bidx \u003d 0; bidx \u003c address_space; bidx +\u003d sizeof(UNIT)) {"},{"line_number":4261,"context_line":"\t\t\tuint32_t val \u003d 0;"},{"line_number":4262,"context_line":"\t\t\tlong long bmax \u003d min + bidx;"},{"line_number":4263,"context_line":"\t\t\tfor ( ; i \u003c this_pass \u0026\u0026 samples[i] \u003c\u003d bmax; ++i)"},{"line_number":4264,"context_line":"\t\t\t\tval++;"},{"line_number":4265,"context_line":"\t\t\tif (val \u003e UINT16_MAX)"},{"line_number":4266,"context_line":"\t\t\t\tval \u003d UINT16_MAX;"},{"line_number":4267,"context_line":""},{"line_number":4268,"context_line":"\t\t\tuint8_t data[2];"},{"line_number":4269,"context_line":"\t\t\tdata[0] \u003d val \u0026 0xff;"},{"line_number":4270,"context_line":"\t\t\tdata[1] \u003d (val \u003e\u003e 8) \u0026 0xff;"},{"line_number":4271,"context_line":"\t\t\twrite_data(f, data, 2);"},{"line_number":4272,"context_line":"\t\t}"},{"line_number":4273,"context_line":""},{"line_number":4274,"context_line":"\t\tsamples +\u003d this_pass;"},{"line_number":4275,"context_line":"\t\tsample_num -\u003d this_pass;"},{"line_number":4276,"context_line":"\t}"},{"line_number":4277,"context_line":""},{"line_number":4278,"context_line":"\tfclose(f);"},{"line_number":4279,"context_line":"}"}],"source_content_type":"text/x-csrc","patch_set":4,"id":"48b57094_3540deed","line":4276,"range":{"start_line":4223,"start_character":1,"end_line":4276,"end_character":2},"in_reply_to":"d3fa7a79_27ded871","updated":"2025-02-18 14:25:52.000000000","message":"Done","commit_id":"9d28c59e9ef28b500c15c0d31d57586313be7f5f"}]}
