Example #1
0
void LockStats<CounterType>::report(BSONObjBuilder* builder) const {
    // All indexing below starts from offset 1, because we do not want to report/account
    // position 0, which is a sentinel value for invalid resource/no lock.
    for (int i = 1; i < ResourceTypesCount; i++) {
        _report(builder, resourceTypeName(static_cast<ResourceType>(i)), _stats[i]);
    }

    _report(builder, "oplog", _oplogStats);
}
    string ResourceId::toString() const {
        StringBuilder ss;
        ss << "{" << _fullHash << ": " << resourceTypeName(static_cast<ResourceType>(_type))
           << ", " << _hashId;

#ifdef _DEBUG
        ss << ", " << _nsCopy;
#endif

        ss << "}";

        return ss.str();
    }
Example #3
0
static void dumpResource(FILE *fp, int type, int index, const ResourceEntry *re) {
	fprintf(stdout, "Resource size %d flags 0x%x id 0x%x type 0x%x\n", re->size, re->flags, re->id, type);
	FILE *out;

	char name[32];
	snprintf(name, sizeof(name), "%s%d", resourceTypeName(type), index);

	const int pos = ftell(fp);
	fseek(fp, re->offset, SEEK_SET);

	uint8_t *buf = (uint8_t *)malloc(re->size);
	if (buf) {
		fread(buf, 1, re->size, fp);

		switch (type) {
		case kResTypeIcon:
			out = fopen(name, "wb");
			if (out) {
					// icons are stored with DIB header
				uint8_t header[BITMAPFILEHEADER_SIZE];

				header[0] = 'B'; header[1] = 'M';
				TO_LE32(header + 2, BITMAPFILEHEADER_SIZE + re->size);
				TO_LE16(header + 6, 0);
				TO_LE16(header + 8, 0);
				TO_LE32(header + 10, BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE + 16 * 4);

				fwrite(header, 1, sizeof(header), out);

				// Fixup dimensions to 32x32, the lower 32 rows contain garbage
				if (buf[0] == 40 && buf[4] == 32 && buf[8] == 64) {
					fprintf(stdout, "Fixing up dimensions to 32x32\n");
					buf[8] = 32;
				}

				fwrite(buf, 1, re->size, out);
				fclose(out);
			}
			break;
		case kResTypeData:
			out = fopen(name, "wb");
			if (out) {
				fwrite(buf, 1, re->size, out);
				fclose(out);
			}
			break;
		}
		free(buf);
	}
	fseek(fp, pos, SEEK_SET);
}
Example #4
0
    void fillLockerInfo(const Locker::LockerInfo& lockerInfo, BSONObjBuilder& infoBuilder) {
        // "locks" section
        BSONObjBuilder locks(infoBuilder.subobjStart("locks"));
        const size_t locksSize = lockerInfo.locks.size();

        // Only add the last lock of each type, and use the largest mode encountered
        LockMode modeForType[ResourceTypesCount] = { }; // default initialize to zero (min value)
        for (size_t i = 0; i < locksSize; i++) {
            const Locker::OneLock& lock = lockerInfo.locks[i];
            const ResourceType lockType = lock.resourceId.getType();
            const LockMode lockMode =  std::max(lock.mode, modeForType[lockType]);

            // Check that lockerInfo is sorted on resource type
            invariant(i == 0 || lockType >= lockerInfo.locks[i - 1].resourceId.getType());

            if (lock.resourceId == resourceIdLocalDB) {
                locks.append("local", legacyModeName(lock.mode));
                continue;
            }

            modeForType[lockType] = lockMode;

            if (i + 1 < locksSize && lockerInfo.locks[i + 1].resourceId.getType() == lockType) {
                continue; // skip this lock as it is not the last one of its type
            }
            else {
                locks.append(resourceTypeName(lockType), legacyModeName(lockMode));
            }
        }
        locks.done();

        // "waitingForLock" section
        infoBuilder.append("waitingForLock", lockerInfo.waitingResource.isValid());

        // "lockStats" section
        {
            BSONObjBuilder lockStats(infoBuilder.subobjStart("lockStats"));
            lockerInfo.stats.report(&lockStats);
            lockStats.done();
        }
    }
Example #5
0
static void decodeResourceTable(FILE *fp) {
	const int align = 1 << freadUint16LE(fp);
	int type = freadUint16LE(fp);
	while (type != 0) {
		assert((type & 0x8000) != 0);

		// DW Number of resources for this type
		int count = freadUint16LE(fp);
		fprintf(stdout, "Resource type 0x%x '%s' count %d\n", type, resourceTypeName(type), count);

		// DD Reserved.
		fseek(fp, 4, SEEK_CUR);

		for (int i = 0; i < count; ++i) {
			ResourceEntry re;

			// DW File offset to the contents of the resource data
			re.offset = freadUint16LE(fp) * align;

			// DW Length of resource in the file
			re.size = freadUint16LE(fp) * align;

			// DW Flag word.
			re.flags = freadUint16LE(fp);

			// DW Resource ID
			re.id = freadUint16LE(fp);

			// DD Reserved.
			fseek(fp, 4, SEEK_CUR);

			dumpResource(fp, type, i, &re);
		}

		type = freadUint16LE(fp);
	}
}
Example #6
0
	virtual util::Str8 getResourceTypeName() const { return resourceTypeName(); }