int main (int argc, char * const * const argv) { NVQRConnection connection; NVQRQueryDataBuffer data; pid_t pid = 0; GLenum queryType; nvqrReturn_t result; result = parse_commandline(argc, argv, &pid, &queryType); if (result != NVQR_SUCCESS) { fprintf(stderr, "%s: invalid command line\n", argv[0]); return result; } result = nvqr_connect(&connection, pid); if (result != NVQR_SUCCESS) { if (result == NVQR_ERROR_NOT_SUPPORTED && connection.process_name) { printf("Resource query not supported for '%s' (pid %ld)\n", connection.process_name, (long) connection.pid); } else { fprintf(stderr, "Error: failed to open connection to pid %ld\n", (long) connection.pid); } return result; } result = nvqr_request_meminfo(connection, queryType, &data); if (result == NVQR_SUCCESS) { int version = nvqr_get_data_format_version(data.data); if (version < NVQR_MIN_DATA_FORMAT_VERSION || version > NVQR_MAX_DATA_FORMAT_VERSION) { fprintf(stderr, "Error: unrecognized data format version '%d'. " "(Minimum supported: %d; Maximum supported: %d)\n", version, NVQR_MIN_DATA_FORMAT_VERSION, NVQR_MAX_DATA_FORMAT_VERSION); } if (connection.process_name) { printf("%s, pid = %ld, data format version %d\n", connection.process_name, (long) connection.pid, version); } print_memory_info(queryType, data.data); } else { fprintf(stderr, "Error: failed to query resource usage information " "for pid %ld.\n", (long) connection.pid); } result = nvqr_disconnect(&connection); return result; }
int WinPmem::write_coredump() { // Somewhere to store the info from the driver; struct PmemMemoryInfo info; DWORD size; int status = -1; if (out_fd_ == INVALID_HANDLE_VALUE) { dprintf("[WINPMEM] Must open an output file first."); goto exit; }; RtlZeroMemory(&info, sizeof(info)); // Get the memory ranges. if (!DeviceIoControl(fd_, PMEM_INFO_IOCTRL, NULL, 0, (char *)&info, sizeof(info), &size, NULL)) { dprintf("[WINPMEM] Failed to get memory geometry,"); status = -1; goto exit; }; dprintf("[WINPMEM] Will write an elf coredump."); print_memory_info(); if (!write_coredump_header_(&info)) { goto exit; }; for (int64_t i = 0; i < info.NumberOfRuns.QuadPart; i++) { copy_memory((size_t)info.Run[i].start, (size_t)(info.Run[i].start + info.Run[i].length)); }; // Remember where we wrote the last metadata header. last_header_offset_ = out_offset; if (!WriteFile(out_fd_, metadata_, metadata_len_, &metadata_len_, NULL)) { dprintf("[WINPMEM] Can not write metadata."); } out_offset += metadata_len_; if (pagefile_path_) { write_page_file(); }; exit: CloseHandle(out_fd_); out_fd_ = INVALID_HANDLE_VALUE; return status; };
__int64 WinPmem::write_raw_image() { // Somewhere to store the info from the driver; struct PmemMemoryInfo info; DWORD size; __int64 i; __int64 status = -1; if(out_fd_==INVALID_HANDLE_VALUE) { LogError(TEXT("Must open an output file first.")); goto exit; }; RtlZeroMemory(&info, sizeof(info)); // Get the memory ranges. if(!DeviceIoControl(fd_, PMEM_INFO_IOCTRL, NULL, 0, (char *)&info, sizeof(info), &size, NULL)) { LogError(TEXT("Failed to get memory geometry,")); status = -1; goto exit; }; Log(TEXT("Will generate a RAW image\n")); print_memory_info(); __int64 offset = 0; for(i=0; i < info.NumberOfRuns.QuadPart; i++) { if(info.Run[i].start > offset) { Log(TEXT("Padding from 0x%08llX to 0x%08llX\n"), offset, info.Run[i].start); if(!pad(info.Run[i].start - offset)) { goto exit; } }; copy_memory(info.Run[i].start, info.Run[i].start + info.Run[i].length); offset = info.Run[i].start + info.Run[i].length; }; // All is well. status = 1; exit: CloseHandle(out_fd_); out_fd_ = INVALID_HANDLE_VALUE; return status; };
__int64 WinPmem::write_crashdump() { // Somewhere to store the info from the driver; struct PmemMemoryInfo info; DWORD size; __int64 i; __int64 status = -1; if(out_fd_==INVALID_HANDLE_VALUE) { LogError(TEXT("Must open an output file first.")); goto exit; }; RtlZeroMemory(&info, sizeof(info)); // Get the memory ranges. if(!DeviceIoControl(fd_, PMEM_INFO_IOCTRL, NULL, 0, (char *)&info, sizeof(info), &size, NULL)) { LogError(TEXT("Failed to get memory geometry,")); status = -1; goto exit; }; Log(TEXT("Will write a crash dump file\n")); print_memory_info(); if(!write_crashdump_header_(&info)) { goto exit; }; __int64 offset = 0; for(i=0; i < info.NumberOfRuns.QuadPart; i++) { copy_memory(info.Run[i].start, info.Run[i].start + info.Run[i].length); offset = info.Run[i].start + info.Run[i].length; }; exit: CloseHandle(out_fd_); out_fd_ = INVALID_HANDLE_VALUE; return status; };
// main function loaded through loader.asm int kmain(multiboot_info_t* mbi, uint32_t magic) { (void)magic; /* TODO: check if multiboot loader magic number is correct */ gdt_init(); idt_init(); pic_init(); pic_set_mask(PIC1_KBD_IRQ, PIC_NO_IRQ); asm volatile("sti"); fb_enable_cursor(); clrscr(); printk(PRINTK_FB, "Cursor position: %u\n", fb_get_cursor()); printk(PRINTK_FB, "Cursor start: %h\n", (unsigned int)(fb_get_cursor_start())); printk(PRINTK_FB, "Cursor end: %h\n", (unsigned int)(fb_get_cursor_end())); printk(PRINTK_FB, "Frame buffer address: %h\n", fb_get_start_address()); print_memory_info(mbi); printk(PRINTK_FB, "bitsize - char: %u\n", sizeof(char)*8); printk(PRINTK_FB, "bitsize - short: %u\n", sizeof(short)*8); printk(PRINTK_FB, "bitsize - int: %u\n", sizeof(int)*8); printk(PRINTK_FB, "bitsize - long: %u\n", sizeof(long)*8); printk(PRINTK_FB, "sizeof page_entry_t: %u\n", sizeof(page_entry_t)); for (;;) { asm volatile("hlt"); } return 0; }
int main() { #if defined(CRT_LFH) ::wprintf(L"crt lfh\n"); set_lfh(); #elif defined(TBBMALLOC) ::wprintf(L"tbbmalloc\n"); #elif defined(TCMALLOC) ::wprintf(L"tcmalloc\n"); #elif defined(JEMALLOC) ::wprintf(L"jemalloc\n"); set_jemalloc(); #elif defined(MS_CONCURRENCY) ::wprintf(L"ms concurrency\n"); #elif defined(MY_ALLOCATOR) ::wprintf(L"my allocator\n"); if (allocator.create(true, 0) == false) { ::wprintf(L"allocator.create() failed.\n"); return 0; } #endif // for crt tbb tcmalloc char* dummy = new char[10]; SecureZeroMemory(dummy, 10); ::wprintf(L"start memory info\n"); print_memory_info(); HANDLE thread_handle[thread_count] = { nullptr, }; ULONGLONG start = ::GetTickCount64(); for (std::size_t i = 0; i < thread_count; ++i) { unsigned int id = 0; thread_handle[i] = reinterpret_cast< HANDLE >(::_beginthreadex(nullptr, 0, memory_alloc_test_thread_func, nullptr, 0, &id)); if (thread_handle[i] == nullptr) { ::wprintf(L"%llu: _beginthreadex failed.\n", i); } } ::WaitForMultipleObjects(thread_count, thread_handle, TRUE, INFINITE); ULONGLONG run_time = ::GetTickCount64() - start; ::wprintf(L"run time: %llu\n", run_time); for (std::size_t i = 0; i < thread_count; ++i) { if (thread_handle[i] != nullptr) { ::CloseHandle(thread_handle[i]); thread_handle[i] = nullptr; } } delete[] dummy; dummy = nullptr; ::wprintf(L"end memory info\n"); print_memory_info(); #if defined(MY_ALLOCATOR) print_allocator_stat(allocator.get_statistics()); allocator.destroy(); #elif defined(JEMALLOC) { //je_malloc_stats_print(nullptr, nullptr, nullptr); size_t sz = sizeof(jemalloc_post_allocated); je_mallctl("stats.active", &jemalloc_post_allocated, &sz, nullptr, 0); size_t leaked = jemalloc_post_allocated - jemalloc_pre_allocated; ::wprintf(L"\nDone. Leaked: %zd bytes\n", leaked); bool failed = leaked > 65536; // in case C++ runtime allocated something (e.g. iostream locale or facet) ::wprintf(L"\nTest %s!\n", (failed ? L"FAILED" : L"successful")); } #endif return 0; }
int main(void) { zfs_footprint_stats_t *footprint; size_t buflen = 8192; struct vfsconf vfc; int name[3]; int i; if (getvfsbyname("zfs", &vfc) < 0) errx(1, "ZFS not loaded into kernel"); footprint = (zfs_footprint_stats_t *) malloc(buflen); name[0] = CTL_VFS; name[1] = vfc.vfc_typenum; name[2] = ZFS_SYSCTL_FOOTPRINT; if (sysctl(name, 3, footprint, &buflen, (void *)0, (size_t)0) < 0) err(1, "sysctl"); if (footprint->version != ZFS_FOOTPRINT_VERSION) errx(1, "ZFS footprint sysctl version mismatch"); (void) initscr(); while (1) { kmem_cache_total = kmem_cache_inuse = 0; row = 0; name[0] = CTL_VFS; name[1] = vfc.vfc_typenum; name[2] = ZFS_SYSCTL_FOOTPRINT; if (sysctl(name, 3, footprint, &buflen, (void *)0, (size_t)0) < 0) err(1, "sysctl"); clear(); print_memory_info("ZFS footprint", &footprint->memory_stats); print_memory_info("ARC footprint", &footprint->arc_stats); row++; sprintf(linebuf, "%3d threads", footprint->thread_count); mvaddstr(0, 65, linebuf); sprintf(linebuf, "%9s %9s %9s %9s %9s %8s", "obj", "slab", "active", "total", "peak", "total"); mvaddstr(row++, 18, linebuf); sprintf(linebuf, " kmem_cache name"); mvaddstr(row, 0, linebuf); sprintf(linebuf, "%9s %9s %9s %9s %9s %8s", "size", "size", "objs", "objs", "objs", "mem"); mvaddstr(row++, 18, linebuf); sprintf(linebuf, "-----------------------------------------------------------------------------"); mvaddstr(row++, 0, linebuf); for (i = 0; i < footprint->caches_count; ++i) { print_cache_info(&footprint->cache_stats[i]); } sprintf(linebuf, "-----------------------------------------------------------------------------"); mvaddstr(row++, 0, linebuf); sprintf(linebuf, " kmem_cache total: %6dM %6dM", kmem_cache_inuse / ONEMEGABYTE, kmem_cache_total / ONEMEGABYTE); mvaddstr(row++, 0, linebuf); move(row, 0); // clrtobot(); refresh(); sleep(1); } endwin(); exit(0); }