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

add todict function #139

Merged
merged 2 commits into from
Dec 14, 2021
Merged

Conversation

ericphanson
Copy link
Contributor

This allows serialization with JSON3:

julia> to
 ──────────────────────────────────────────────────────────────────────
                               Time                   Allocations      
                       ──────────────────────   ───────────────────────
   Tot / % measured:         222s / 0.52%           1.19GiB / 0.04%    

 Section       ncalls     time   %tot     avg     alloc   %tot      avg
 ──────────────────────────────────────────────────────────────────────
 nest 2             1    705ms  61.6%   705ms   2.09KiB  0.42%  2.09KiB
   level 2.2        1    401ms  35.1%   401ms      176B  0.03%     176B
   level 2.1        1    303ms  26.5%   303ms      176B  0.03%     176B
 nest 1             1    439ms  38.4%   439ms    498KiB  100%    498KiB
   level 2.2        1    207ms  18.1%   207ms      176B  0.03%     176B
   level 2.1        3    117ms  10.3%  39.2ms   8.73KiB  1.75%  2.91KiB
 ──────────────────────────────────────────────────────────────────────

julia> JSON3.write(to)
"{\"total_time_ns\":1144369999,\"total_allocated_bytes\":512511,\"time_ns\":0,\"n_calls\":0,\"allocated_bytes\":0,\"inner_timers\":{\"nest 1\":{\"total_time_ns\":324575583,\"total_allocated_bytes\":9120,\"time_ns\":439140583,\"n_calls\":1,\"allocated_bytes\":510367,\"inner_timers\":{\"level 2.1\":{\"total_time_ns\":0,\"total_allocated_bytes\":0,\"time_ns\":117488250,\"n_calls\":3,\"allocated_bytes\":8944,\"inner_timers\":{}},\"level 2.2\":{\"total_time_ns\":0,\"total_allocated_bytes\":0,\"time_ns\":207087333,\"n_calls\":1,\"allocated_bytes\":176,\"inner_timers\":{}}}},\"nest 2\":{\"total_time_ns\":704607667,\"total_allocated_bytes\":352,\"time_ns\":705229416,\"n_calls\":1,\"allocated_bytes\":2144,\"inner_timers\":{\"level 2.1\":{\"total_time_ns\":0,\"total_allocated_bytes\":0,\"time_ns\":303114542,\"n_calls\":1,\"allocated_bytes\":176,\"inner_timers\":{}},\"level 2.2\":{\"total_time_ns\":0,\"total_allocated_bytes\":0,\"time_ns\":401493125,\"n_calls\":1,\"allocated_bytes\":176,\"inner_timers\":{}}}}}}"

julia> JSON3.pretty(to)
{
           "total_time_ns": 1144369999,
   "total_allocated_bytes": 512511,
                 "time_ns": 0,
                 "n_calls": 0,
         "allocated_bytes": 0,
            "inner_timers": {
                               "nest 1": {
                                                    "total_time_ns": 324575583,
                                            "total_allocated_bytes": 9120,
                                                          "time_ns": 439140583,
                                                          "n_calls": 1,
                                                  "allocated_bytes": 510367,
                                                     "inner_timers": {
                                                                        "level 2.1": {
                                                                                                "total_time_ns": 0,
                                                                                        "total_allocated_bytes": 0,
                                                                                                      "time_ns": 117488250,
                                                                                                      "n_calls": 3,
                                                                                              "allocated_bytes": 8944,
                                                                                                 "inner_timers": {}
                                                                                     },
                                                                        "level 2.2": {
                                                                                                "total_time_ns": 0,
                                                                                        "total_allocated_bytes": 0,
                                                                                                      "time_ns": 207087333,
                                                                                                      "n_calls": 1,
                                                                                              "allocated_bytes": 176,
                                                                                                 "inner_timers": {}
                                                                                     }
                                                                     }
                                         },
                               "nest 2": {
                                                    "total_time_ns": 704607667,
                                            "total_allocated_bytes": 352,
                                                          "time_ns": 705229416,
                                                          "n_calls": 1,
                                                  "allocated_bytes": 2144,
                                                     "inner_timers": {
                                                                        "level 2.1": {
                                                                                                "total_time_ns": 0,
                                                                                        "total_allocated_bytes": 0,
                                                                                                      "time_ns": 303114542,
                                                                                                      "n_calls": 1,
                                                                                              "allocated_bytes": 176,
                                                                                                 "inner_timers": {}
                                                                                     },
                                                                        "level 2.2": {
                                                                                                "total_time_ns": 0,
                                                                                        "total_allocated_bytes": 0,
                                                                                                      "time_ns": 401493125,
                                                                                                      "n_calls": 1,
                                                                                              "allocated_bytes": 176,
                                                                                                 "inner_timers": {}
                                                                                     }
                                                                     }
                                         }
                            }
}

This is not enough to be able to de-serialize back into a TimerOutput object, but for my purposes (logging out timers), it's sufficient.

@KristofferC
Copy link
Owner

I would rather just add a todict function that just creates the dictionary. And then people can serialize it using JSON or whatever.

@ericphanson ericphanson changed the title add StructTypes methods for JSON3 serialization add todict function Nov 18, 2021
@ericphanson
Copy link
Contributor Author

bump

1 similar comment
@ericphanson
Copy link
Contributor Author

bump

@KristofferC
Copy link
Owner

Thanks for the bump!

@KristofferC KristofferC merged commit b0295a0 into KristofferC:master Dec 14, 2021
@KristofferC
Copy link
Owner

This will need some docs in the README so that people can use it.

@ericphanson ericphanson deleted the eph/structtypes branch December 14, 2021 14:41
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