summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2014-06-17 23:07:29 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-17 23:07:29 +0000
commitef2ec0beea13ae7de6ec2050e535fc360b4105be (patch)
tree198a894838a9a122a132c2353f56c48f154a121e
parent6d8d16e5fe2c94cae49798c7efbeaf53c783a994 (diff)
parent53ea786b38f0e394b0b57e5deb0f8f262cea7819 (diff)
downloadextras-ef2ec0beea13ae7de6ec2050e535fc360b4105be.tar.gz
am 53ea786b: Merge changes Ic686b4cb,Ie4b6c7ef
* commit '53ea786b38f0e394b0b57e5deb0f8f262cea7819': procrank: support >4GB of memory from 32-bit procrank libpagemap: support 64-bit kernel from 32-bit libpagemap
-rw-r--r--libpagemap/include/pagemap/pagemap.h12
-rw-r--r--libpagemap/pm_kernel.c12
-rw-r--r--libpagemap/pm_process.c12
-rw-r--r--procrank/procrank.c28
4 files changed, 34 insertions, 30 deletions
diff --git a/libpagemap/include/pagemap/pagemap.h b/libpagemap/include/pagemap/pagemap.h
index 210bc815..9063b1e1 100644
--- a/libpagemap/include/pagemap/pagemap.h
+++ b/libpagemap/include/pagemap/pagemap.h
@@ -71,9 +71,9 @@ struct pm_process {
struct pm_map {
pm_process_t *proc;
- unsigned long start;
- unsigned long end;
- unsigned long offset;
+ uint64_t start;
+ uint64_t end;
+ uint64_t offset;
int flags;
char *name;
@@ -91,11 +91,11 @@ int pm_kernel_pids(pm_kernel_t *ker, pid_t **pids_out, size_t *len);
/* Get the map count (from /proc/kpagecount) of a physical frame.
* The count is returned through *count_out. */
-int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out);
+int pm_kernel_count(pm_kernel_t *ker, uint64_t pfn, uint64_t *count_out);
/* Get the page flags (from /proc/kpageflags) of a physical frame.
* The count is returned through *flags_out. */
-int pm_kernel_flags(pm_kernel_t *ker, unsigned long pfn, uint64_t *flags_out);
+int pm_kernel_flags(pm_kernel_t *ker, uint64_t pfn, uint64_t *flags_out);
#define PM_PAGE_LOCKED (1 << 0)
#define PM_PAGE_ERROR (1 << 1)
@@ -153,7 +153,7 @@ int pm_process_workingset(pm_process_t *proc, pm_memusage_t *ws_out, int reset);
* The array of PFNs is returned through *range_out, and the caller has the
* responsibility to free it. */
int pm_process_pagemap_range(pm_process_t *proc,
- unsigned long low, unsigned long hi,
+ uint64_t low, uint64_t hi,
uint64_t **range_out, size_t *len);
#define _BITS(x, offset, bits) (((x) >> offset) & ((1LL << (bits)) - 1))
diff --git a/libpagemap/pm_kernel.c b/libpagemap/pm_kernel.c
index 3615f1ac..b9e4e698 100644
--- a/libpagemap/pm_kernel.c
+++ b/libpagemap/pm_kernel.c
@@ -113,13 +113,13 @@ int pm_kernel_pids(pm_kernel_t *ker, pid_t **pids_out, size_t *len) {
return 0;
}
-int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out) {
- off_t off;
+int pm_kernel_count(pm_kernel_t *ker, uint64_t pfn, uint64_t *count_out) {
+ off64_t off;
if (!ker || !count_out)
return -1;
- off = lseek(ker->kpagecount_fd, pfn * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(ker->kpagecount_fd, pfn * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1)
return errno;
if (read(ker->kpagecount_fd, count_out, sizeof(uint64_t)) <
@@ -129,13 +129,13 @@ int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out) {
return 0;
}
-int pm_kernel_flags(pm_kernel_t *ker, unsigned long pfn, uint64_t *flags_out) {
- off_t off;
+int pm_kernel_flags(pm_kernel_t *ker, uint64_t pfn, uint64_t *flags_out) {
+ off64_t off;
if (!ker || !flags_out)
return -1;
- off = lseek(ker->kpageflags_fd, pfn * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(ker->kpageflags_fd, pfn * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1)
return errno;
if (read(ker->kpageflags_fd, flags_out, sizeof(uint64_t)) <
diff --git a/libpagemap/pm_process.c b/libpagemap/pm_process.c
index e68263c6..50791ef9 100644
--- a/libpagemap/pm_process.c
+++ b/libpagemap/pm_process.c
@@ -16,6 +16,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -100,11 +101,12 @@ int pm_process_usage(pm_process_t *proc, pm_memusage_t *usage_out) {
}
int pm_process_pagemap_range(pm_process_t *proc,
- unsigned long low, unsigned long high,
+ uint64_t low, uint64_t high,
uint64_t **range_out, size_t *len) {
- unsigned long firstpage, numpages;
+ uint64_t firstpage;
+ uint64_t numpages;
uint64_t *range;
- off_t off;
+ off64_t off;
int error;
if (!proc || (low > high) || !range_out || !len)
@@ -123,7 +125,7 @@ int pm_process_pagemap_range(pm_process_t *proc,
if (!range)
return errno;
- off = lseek(proc->pagemap_fd, firstpage * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(proc->pagemap_fd, firstpage * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1) {
error = errno;
free(range);
@@ -281,7 +283,7 @@ static int read_maps(pm_process_t *proc) {
map->proc = proc;
name[0] = '\0';
- sscanf(line, "%lx-%lx %s %lx %*s %*d %" S(MAX_LINE) "s",
+ sscanf(line, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %*s %*d %" S(MAX_LINE) "s",
&map->start, &map->end, perms, &map->offset, name);
map->name = malloc(strlen(name) + 1);
diff --git a/procrank/procrank.c b/procrank/procrank.c
index 945e9402..de26cd13 100644
--- a/procrank/procrank.c
+++ b/procrank/procrank.c
@@ -16,24 +16,25 @@
#include <dirent.h>
#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
#include <pagemap/pagemap.h>
struct proc_info {
pid_t pid;
pm_memusage_t usage;
- unsigned long wss;
+ uint64_t wss;
};
static void usage(char *myname);
static int getprocname(pid_t pid, char *buf, int len);
-static int numcmp(long long a, long long b);
+static int numcmp(uint64_t a, uint64_t b);
#define declare_sort(field) \
static int sort_by_ ## field (const void *a, const void *b)
@@ -85,7 +86,7 @@ void print_mem_info() {
5,
0
};
- long mem[] = { 0, 0, 0, 0, 0, 0 };
+ uint64_t mem[] = { 0, 0, 0, 0, 0, 0 };
char* p = buffer;
while (*p && numFound < 6) {
@@ -112,7 +113,8 @@ void print_mem_info() {
if (*p) p++;
}
- printf("RAM: %ldK total, %ldK free, %ldK buffers, %ldK cached, %ldK shmem, %ldK slab\n",
+ printf("RAM: %" PRIu64 "K total, %" PRIu64 "K free, %" PRIu64 "K buffers, "
+ "%" PRIu64 "K cached, %" PRIu64 "K shmem, %" PRIu64 "K slab\n",
mem[0], mem[1], mem[2], mem[3], mem[4], mem[5]);
}
@@ -122,9 +124,9 @@ int main(int argc, char *argv[]) {
pid_t *pids;
struct proc_info **procs;
size_t num_procs;
- unsigned long total_pss;
- unsigned long total_uss;
- unsigned long total_swap;
+ uint64_t total_pss;
+ uint64_t total_uss;
+ uint64_t total_swap;
char cmdline[256]; // this must be within the range of int
int error;
bool has_swap = false;
@@ -314,15 +316,15 @@ int main(int argc, char *argv[]) {
/* Print the total line */
printf("%5s ", "");
if (ws) {
- printf("%7s %6ldK %6ldK ",
+ printf("%7s %6" PRIu64 "K %" PRIu64 "K ",
"", total_pss / 1024, total_uss / 1024);
} else {
- printf("%8s %7s %6ldK %6ldK ",
+ printf("%8s %7s %6" PRIu64 "K %6" PRIu64 "K ",
"", "", total_pss / 1024, total_uss / 1024);
}
if (has_swap) {
- printf("%6ldK ", total_swap);
+ printf("%6" PRIu64 "K ", total_swap);
}
printf("TOTAL\n");
@@ -410,7 +412,7 @@ exit:
return rc;
}
-static int numcmp(long long a, long long b) {
+static int numcmp(uint64_t a, uint64_t b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;