| 876 | |
| 877 | |
| 878 | Future<http::Response> MemoryProfiler::downloadGraphProfile( |
| 879 | const http::Request& request, |
| 880 | const Option<http::authentication::Principal>&) |
| 881 | { |
| 882 | Result<time_t> requestedId = extractIdFromRequest(request); |
| 883 | |
| 884 | // Verify that `id` has the correct version if it was explicitly passed. |
| 885 | if (requestedId.isError()) { |
| 886 | return http::BadRequest( |
| 887 | "Invalid parameter 'id': " + requestedId.error() + ".\n"); |
| 888 | } |
| 889 | |
| 890 | if (currentRun.isSome() && !requestedId.isSome()) { |
| 891 | return http::BadRequest( |
| 892 | "A profiling run is currently in progress. To download results of the" |
| 893 | " previous run, please pass an 'id' explicitly.\n"); |
| 894 | } |
| 895 | |
| 896 | if (rawProfile.isError()) { |
| 897 | return http::BadRequest( |
| 898 | "No source profile exists: " + rawProfile.error() + ".\n"); |
| 899 | } |
| 900 | |
| 901 | const string rawProfilePath = rawProfile->getPath(); |
| 902 | const time_t rawProfileId = rawProfile->getId(); |
| 903 | |
| 904 | // Only requests for the latest available version are allowed. |
| 905 | if (requestedId.isSome() && (requestedId.get() != rawProfileId)) { |
| 906 | return http::BadRequest( |
| 907 | "Cannot serve requested id #" + stringify(requestedId.get()) + ".\n"); |
| 908 | } |
| 909 | |
| 910 | // Generate the profile for the latest available version |
| 911 | // or return the cached file on disk. |
| 912 | if (graphProfile.isError() || (graphProfile->getId() != rawProfileId)) { |
| 913 | graphProfile = DiskArtifact::create( |
| 914 | GRAPH_FILENAME, |
| 915 | rawProfileId, |
| 916 | [rawProfilePath](const string& outputPath) -> Try<Nothing> { |
| 917 | return generateJeprofFile( |
| 918 | rawProfilePath, |
| 919 | "--svg", |
| 920 | outputPath); |
| 921 | }); |
| 922 | } |
| 923 | |
| 924 | if (graphProfile.isSome()) { |
| 925 | return graphProfile->asHttp(); |
| 926 | } else { |
| 927 | const string message = "Cannot generate file: " + graphProfile.error(); |
| 928 | LOG(WARNING) << message; |
| 929 | return http::BadRequest(message + ".\n"); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | |
| 934 | // TODO(bevers): Allow passing custom options via query parameters. |
nothing calls this directly
no test coverage detected