| 819 | |
| 820 | |
| 821 | Future<http::Response> MemoryProfiler::downloadSymbolizedProfile( |
| 822 | const http::Request& request, |
| 823 | const Option<http::authentication::Principal>&) |
| 824 | { |
| 825 | Result<time_t> requestedId = extractIdFromRequest(request); |
| 826 | |
| 827 | // Verify that `id` has the correct version if it was explicitly passed. |
| 828 | if (requestedId.isError()) { |
| 829 | return http::BadRequest( |
| 830 | "Invalid parameter 'id': " + requestedId.error() + ".\n"); |
| 831 | } |
| 832 | |
| 833 | if (currentRun.isSome() && !requestedId.isSome()) { |
| 834 | return http::BadRequest( |
| 835 | "A profiling run is currently in progress. To download results of the" |
| 836 | " previous run, please pass an 'id' explicitly.\n"); |
| 837 | } |
| 838 | |
| 839 | if (rawProfile.isError()) { |
| 840 | return http::BadRequest( |
| 841 | "No source profile exists: " + rawProfile.error() + ".\n"); |
| 842 | } |
| 843 | |
| 844 | const string rawProfilePath = rawProfile->getPath(); |
| 845 | const time_t rawProfileId = rawProfile->getId(); |
| 846 | |
| 847 | // Only requests for the latest available version are allowed. |
| 848 | if (requestedId.isSome() && (requestedId.get() != rawProfileId)) { |
| 849 | return http::BadRequest( |
| 850 | "Cannot serve requested id #" + stringify(requestedId.get()) + ".\n"); |
| 851 | } |
| 852 | |
| 853 | // Generate the profile for the latest available version |
| 854 | // or return the cached file on disk. |
| 855 | if (symbolizedProfile.isError() || |
| 856 | (symbolizedProfile->getId() != rawProfileId)) { |
| 857 | symbolizedProfile = DiskArtifact::create( |
| 858 | SYMBOLIZED_PROFILE_FILENAME, |
| 859 | rawProfileId, |
| 860 | [rawProfilePath](const string& outputPath) -> Try<Nothing> { |
| 861 | return generateJeprofFile( |
| 862 | rawProfilePath, |
| 863 | "--text", |
| 864 | outputPath); |
| 865 | }); |
| 866 | } |
| 867 | |
| 868 | if (symbolizedProfile.isSome()) { |
| 869 | return symbolizedProfile->asHttp(); |
| 870 | } else { |
| 871 | const string message = "Cannot generate file: " + symbolizedProfile.error(); |
| 872 | LOG(WARNING) << message; |
| 873 | return http::BadRequest(message + ".\n"); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | |
| 878 | Future<http::Response> MemoryProfiler::downloadGraphProfile( |
nothing calls this directly
no test coverage detected