Exemple #1
0
Status PerfCounterCollector::collect(BSONObjBuilder* builder) {
    // Ask PDH to collect the counters
    PDH_STATUS status = PdhCollectQueryData(_query);
    if (status != ERROR_SUCCESS) {
        return {ErrorCodes::WindowsPdhError,
                formatFunctionCallError("PdhCollectQueryData", status)};
    }

    // Output timebase
    // Counters that are based on time either use 100NS or System Ticks Per Second.
    // We only need to output system ticks per second once if any counter depends on it.
    // This is typically 3320310.
    if (_timeBaseTicksCounter) {
        int64_t timebase;

        status = PdhGetCounterTimeBase(_timeBaseTicksCounter->handle, &timebase);
        if (status != ERROR_SUCCESS) {
            return {ErrorCodes::WindowsPdhError,
                    formatFunctionCallError("PdhGetCounterTimeBase", status)};
        }

        builder->append("timebase", timebase);
    }

    // Retrieve all the values that PDH collected for us.
    for (const auto& counterGroup : _counters) {
        BSONObjBuilder subObjBuilder(builder->subobjStart(counterGroup.name));

        Status s = collectCounters(counterGroup.counters, &subObjBuilder);
        if (!s.isOK()) {
            return s;
        }

        subObjBuilder.doneFast();
    }

    for (const auto& counterGroup : _nestedCounters) {
        BSONObjBuilder subObjBuilder(builder->subobjStart(counterGroup.name));

        for (const auto& instanceNamePair : counterGroup.counters) {
            BSONObjBuilder instSubObjBuilder(builder->subobjStart(instanceNamePair.first));

            Status s = collectCounters(instanceNamePair.second, &instSubObjBuilder);
            if (!s.isOK()) {
                return s;
            }

            instSubObjBuilder.doneFast();
        }

        subObjBuilder.doneFast();
    }

    return Status::OK();
}
Exemple #2
0
    void collect(OperationContext* txn, BSONObjBuilder& builder) final {
        _state = State::kStarted;
        ++_counter;

        generateDocument(builder, _counter);

        {
            BSONObjBuilder b2;
            BSONObjBuilder subObjBuilder(b2.subobjStart(name()));

            subObjBuilder.appendDate(kFTDCCollectStartField,
                                     getGlobalServiceContext()->getClockSource()->now());

            generateDocument(subObjBuilder, _counter);

            subObjBuilder.appendDate(kFTDCCollectEndField,
                                     getGlobalServiceContext()->getClockSource()->now());

            subObjBuilder.done();

            _docs.emplace_back(b2.obj());
        }

        if (_counter == _wait) {
            _condvar.notify_all();
        }
    }
Exemple #3
0
BSONObj FTDCCollectorCollection::collect(Client* client) {
    BSONObjBuilder builder;

    for (auto& collector : _collectors) {
        BSONObjBuilder subObjBuilder(builder.subobjStart(collector->name()));

        // Add a Date_t before and after each BSON is collected so that we can track timing of the
        // collector.
        subObjBuilder.appendDate(kFTDCCollectStartField,
                                 client->getServiceContext()->getClockSource()->now());

        {
            // Create a operation context per command so that we do not share operation contexts
            // across multiple command invocations.
            auto txn = client->makeOperationContext();

            collector->collect(txn.get(), subObjBuilder);
        }

        subObjBuilder.appendDate(kFTDCCollectEndField,
                                 client->getServiceContext()->getClockSource()->now());
    }

    return builder.obj();
}
Exemple #4
0
Status ClientMetadata::serializePrivate(StringData driverName,
                                        StringData driverVersion,
                                        StringData osType,
                                        StringData osName,
                                        StringData osArchitecture,
                                        StringData osVersion,
                                        StringData appName,
                                        BSONObjBuilder* builder) {
    if (appName.size() > kMaxApplicationNameByteLength) {
        return Status(ErrorCodes::ClientMetadataAppNameTooLarge,
                      str::stream() << "The '" << kApplication << "." << kName
                                    << "' field must be less then or equal to "
                                    << kMaxApplicationNameByteLength
                                    << " bytes in the client metadata document");
    }

    {
        BSONObjBuilder metaObjBuilder(builder->subobjStart(kMetadataDocumentName));

        if (!appName.empty()) {
            BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kApplication));
            subObjBuilder.append(kName, appName);
        }

        {
            BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kDriver));
            subObjBuilder.append(kName, driverName);
            subObjBuilder.append(kVersion, driverVersion);
        }

        {
            BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kOperatingSystem));
            subObjBuilder.append(kType, osType);
            subObjBuilder.append(kName, osName);
            subObjBuilder.append(kArchitecture, osArchitecture);
            subObjBuilder.append(kVersion, osVersion);
        }
    }

    return Status::OK();
}
Exemple #5
0
void ClientMetadata::serializePrivate(StringData driverName,
                                      StringData driverVersion,
                                      StringData osType,
                                      StringData osName,
                                      StringData osArchitecture,
                                      StringData osVersion,
                                      BSONObjBuilder* builder) {
    BSONObjBuilder metaObjBuilder(builder->subobjStart(kMetadataDocumentName));

    {
        BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kDriver));
        subObjBuilder.append(kName, driverName);
        subObjBuilder.append(kVersion, driverVersion);
    }

    {
        BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kOperatingSystem));
        subObjBuilder.append(kType, osType);
        subObjBuilder.append(kName, osName);
        subObjBuilder.append(kArchitecture, osArchitecture);
        subObjBuilder.append(kVersion, osVersion);
    }
}
void LogicalTimeMetadata::writeToMetadata(BSONObjBuilder* metadataBuilder) const {
    BSONObjBuilder subObjBuilder(metadataBuilder->subobjStart(fieldName()));
    _clusterTime.getTime().asTimestamp().append(subObjBuilder.bb(), kClusterTimeFieldName);

    BSONObjBuilder signatureObjBuilder(subObjBuilder.subobjStart(kSignatureFieldName));
    // Logical time metadata is only written when the LogicalTimeValidator is set, which
    // means the cluster time should always have a proof.
    invariant(_clusterTime.getProof());
    _clusterTime.getProof()->appendAsBinData(signatureObjBuilder, kSignatureHashFieldName);
    signatureObjBuilder.append(kSignatureKeyIdFieldName, _clusterTime.getKeyId());
    signatureObjBuilder.doneFast();

    subObjBuilder.doneFast();
}