MCPcopy Create free account
hub / github.com/apache/mesos / _usage

Function _usage

src/slave/containerizer/mesos/containerizer.cpp:2467–2563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2465
2466
2467Future<ResourceStatistics> _usage(
2468 const ContainerID& containerId,
2469 const Option<Resources>& resourceRequests,
2470 const Option<google::protobuf::Map<string, Value::Scalar>>& resourceLimits,
2471 bool enableCfsQuota,
2472 const vector<Future<ResourceStatistics>>& statistics)
2473{
2474 ResourceStatistics result;
2475
2476 // Set the timestamp now we have all statistics.
2477 result.set_timestamp(Clock::now().secs());
2478
2479 foreach (const Future<ResourceStatistics>& statistic, statistics) {
2480 if (statistic.isReady()) {
2481 result.MergeFrom(statistic.get());
2482 } else {
2483 LOG(WARNING) << "Skipping resource statistic for container "
2484 << containerId << " because: "
2485 << (statistic.isFailed() ? statistic.failure()
2486 : "discarded");
2487 }
2488 }
2489
2490 Option<double> cpuRequest, cpuLimit, memLimit;
2491 Option<Bytes> memRequest;
2492
2493 if (resourceRequests.isSome()) {
2494 cpuRequest = resourceRequests->cpus();
2495 memRequest = resourceRequests->mem();
2496 }
2497
2498 if (resourceLimits.isSome()) {
2499 foreach (auto&& limit, resourceLimits.get()) {
2500 if (limit.first == "cpus") {
2501 cpuLimit = limit.second.value();
2502 } else if (limit.first == "mem") {
2503 memLimit = limit.second.value();
2504 }
2505 }
2506 }
2507
2508 if (cpuRequest.isSome()) {
2509 result.set_cpus_soft_limit(cpuRequest.get());
2510 }
2511
2512 if (cpuLimit.isSome()) {
2513 // Get the total CPU numbers of this node, we will use it to set container's
2514 // hard CPU limit if the CPU limit specified by framework is infinity.
2515 static Option<long> totalCPUs;
2516 if (totalCPUs.isNone()) {
2517 Try<long> cpus = os::cpus();
2518 if (cpus.isError()) {
2519 return Failure(
2520 "Failed to auto-detect the number of cpus: " + cpus.error());
2521 }
2522
2523 totalCPUs = cpus.get();
2524 }

Callers

nothing calls this directly

Calls 15

FailureClass · 0.85
MegabytesFunction · 0.85
foreachFunction · 0.70
errorMethod · 0.65
cpusFunction · 0.50
memoryFunction · 0.50
secsMethod · 0.45
isSomeMethod · 0.45
cpusMethod · 0.45
memMethod · 0.45
getMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected