|
| 1 | +#include <kernel/os.hpp> |
| 2 | +#include <liveupdate> |
| 3 | +using namespace liu; |
| 4 | + |
| 5 | +static std::vector<int64_t> timestamps; |
| 6 | +static buffer_t bloberino; |
| 7 | + |
| 8 | +static void boot_save(Storage& storage, const buffer_t* blob) |
| 9 | +{ |
| 10 | + timestamps.push_back(OS::micros_since_boot()); |
| 11 | + storage.add_vector(0, timestamps); |
| 12 | + assert(blob != nullptr); |
| 13 | + storage.add_buffer(2, *blob); |
| 14 | +} |
| 15 | +static void boot_resume_all(Restore& thing) |
| 16 | +{ |
| 17 | + timestamps = thing.as_vector<int64_t>(); thing.go_next(); |
| 18 | + // calculate time spent |
| 19 | + auto t1 = timestamps.back(); |
| 20 | + auto t2 = OS::micros_since_boot(); |
| 21 | + // set final time |
| 22 | + timestamps.back() = t2 - t1; |
| 23 | + // retrieve old blob |
| 24 | + bloberino = thing.as_buffer(); thing.go_next(); |
| 25 | + |
| 26 | + thing.pop_marker(); |
| 27 | +} |
| 28 | + |
| 29 | +LiveUpdate::storage_func begin_test_boot() |
| 30 | +{ |
| 31 | + try { |
| 32 | + LiveUpdate::resume("test", boot_resume_all); |
| 33 | + // if we are here, |
| 34 | + // resume() must have succeeded |
| 35 | + if (timestamps.size() >= 30) |
| 36 | + { |
| 37 | + // calculate median by sorting |
| 38 | + std::sort(timestamps.begin(), timestamps.end()); |
| 39 | + auto median = timestamps[timestamps.size()/2]; |
| 40 | + // show information |
| 41 | + printf("Median boot time over %lu samples: %llu micros\n", |
| 42 | + timestamps.size(), median); |
| 43 | + /* |
| 44 | + for (auto& stamp : timestamps) { |
| 45 | + printf("%lld\n", stamp); |
| 46 | + } |
| 47 | + */ |
| 48 | + printf("SUCCESS\n"); |
| 49 | + OS::shutdown(); |
| 50 | + } |
| 51 | + else { |
| 52 | + // immediately liveupdate |
| 53 | + LiveUpdate::exec(bloberino, "test", boot_save); |
| 54 | + } |
| 55 | + } |
| 56 | + catch (std::exception& e) { |
| 57 | + printf("Ready to receive binary blob\n"); |
| 58 | + } |
| 59 | + // wait for update |
| 60 | + return boot_save; |
| 61 | +} |
0 commit comments