Skip to content

Commit 762f80d

Browse files
Formatting (git-clang-format)
1 parent 673562d commit 762f80d

3 files changed

Lines changed: 28 additions & 29 deletions

File tree

examples/cpp/pyperf/PyPerfNativeStackTrace.cc

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
#include "PyPerfNativeStackTrace.h"
77

8-
#include <sys/uio.h>
8+
#include <cxxabi.h>
99
#include <errno.h>
10+
#include <sys/uio.h>
11+
#include <time.h>
1012
#include <unistd.h>
11-
#include <cxxabi.h>
13+
#include <chrono>
1214
#include <cstdio>
1315
#include <cstring>
1416
#include <sstream>
15-
#include <time.h>
16-
#include <chrono>
1717
#include <thread>
1818

1919
#include "PyPerfLoggingHelper.h"
@@ -31,8 +31,6 @@ uintptr_t NativeStackTrace::ip = 0;
3131
time_t NativeStackTrace::now;
3232
UnwindCache NativeStackTrace::cache;
3333

34-
35-
3634
NativeStackTrace::NativeStackTrace(uint32_t pid, const unsigned char *raw_stack,
3735
size_t stack_len, uintptr_t ip, uintptr_t sp) : error_occurred(false) {
3836
NativeStackTrace::stack = raw_stack;
@@ -238,26 +236,29 @@ bool NativeStackTrace::error_occured() const {
238236

239237
bool NativeStackTrace::is_cached(const uint32_t &key) {
240238
try {
241-
cache.at(key);
242-
return true;
239+
cache.at(key);
240+
return true;
243241
}
244242
catch (const std::out_of_range&) {
245-
logInfo(3, "is_cached: no entry for pid %d\n", key);
243+
logInfo(3, "is_cached: no entry for pid %d\n", key);
246244
}
247245
return false;
248246
}
249247

250248
UnwindCacheEntry NativeStackTrace::cache_get(const uint32_t &key) {
251-
const UnwindCacheEntry & entry = cache.at(key);
249+
const UnwindCacheEntry &entry = cache.at(key);
252250
return entry;
253251
}
254252

255253
// cache_put adds a new entry to the unwind cache if its capacity allows
256-
void NativeStackTrace::cache_put(const uint32_t &key, const unw_cursor_t cursor, const unw_addr_space_t as, void *upt) {
254+
void NativeStackTrace::cache_put(const uint32_t &key, const unw_cursor_t cursor,
255+
const unw_addr_space_t as, void *upt) {
257256
// Check available capacity
258-
if (cache_size() > NativeStackTrace::CacheMaxSizeMB*1024*1024 - cache_single_entry_size()) {
259-
logInfo(2, "Skipping caching entry for pid %d due to the current cache usage equals to %.2f MB is close to the limit (%d MB)\n",
260-
key, cache_size_KB()/1024, NativeStackTrace::CacheMaxSizeMB);
257+
if (cache_size() > NativeStackTrace::CacheMaxSizeMB*1024*1024 - cache_single_entry_size()) {
258+
logInfo(2,
259+
"Skipping caching entry for pid %d due to the current cache usage "
260+
"equals to %.2f MB is close to the limit (%d MB)\n",
261+
key, cache_size_KB() / 1024, NativeStackTrace::CacheMaxSizeMB);
261262
return;
262263
}
263264

@@ -285,27 +286,25 @@ bool NativeStackTrace::cache_delete_key(const uint32_t &key) {
285286
}
286287

287288
// cache_single_entry_size returns the number of bytes taken by single entry
288-
uint32_t NativeStackTrace::cache_single_entry_size() {
289+
uint32_t NativeStackTrace::cache_single_entry_size() {
289290
return sizeof(decltype(cache)::key_type) + sizeof(decltype(cache)::mapped_type);
290291
}
291292

292293
// cache_size returns the number of bytes currently in use by the cache
293-
uint32_t NativeStackTrace::cache_size() {
294+
uint32_t NativeStackTrace::cache_size() {
294295
return sizeof(cache) + cache.size()*cache_single_entry_size();
295296
}
296297

297298
// cache_size_KB returns the number of kilobytes currently in use by the cache
298-
float NativeStackTrace::cache_size_KB() {
299-
return cache_size()/1024;
300-
}
299+
float NativeStackTrace::cache_size_KB() { return cache_size() / 1024; }
301300

302301
// cache_eviction removes elements older than 5 minutes (CacheMaxTTL=300)
303302
void NativeStackTrace::cache_eviction() {
304303
std::vector<uint32_t> keys_to_delete;
305304
float _prev_cache_size = cache_size_KB();
306305

307-
for(std::map<uint32_t, UnwindCacheEntry>::iterator iter = cache.begin(); iter != cache.end(); ++iter)
308-
{
306+
for (std::map<uint32_t, UnwindCacheEntry>::iterator iter = cache.begin();
307+
iter != cache.end(); ++iter) {
309308
uint32_t k = iter->first;
310309
const UnwindCacheEntry & e = iter->second;
311310
if (std::abs(difftime(e.timestamp, NativeStackTrace::now)) > NativeStackTrace::CacheMaxTTL) {
@@ -316,7 +315,7 @@ void NativeStackTrace::cache_eviction() {
316315

317316
// Delete expired entries
318317
for( size_t i = 0; i < keys_to_delete.size(); i++ ) {
319-
cache_delete_key(keys_to_delete[i]);
318+
cache_delete_key(keys_to_delete[i]);
320319
}
321320

322321
if (keys_to_delete.size() > 0) {

examples/cpp/pyperf/PyPerfNativeStackTrace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typedef struct {
2222

2323
typedef std::map<uint32_t, UnwindCacheEntry> UnwindCache;
2424

25-
2625
class NativeStackTrace {
2726
public:
2827
explicit NativeStackTrace(uint32_t pid, const uint8_t *raw_stack,
@@ -45,10 +44,10 @@ class NativeStackTrace {
4544
static const uint16_t CacheMaxSizeMB;
4645
static const uint16_t CacheMaxTTL;
4746

48-
static uint32_t cache_size();
47+
static uint32_t cache_size();
4948
static uint32_t cache_single_entry_size();
50-
static float cache_size_KB();
51-
49+
static float cache_size_KB();
50+
5251
static int access_reg(unw_addr_space_t as, unw_regnum_t regnum,
5352
unw_word_t *valp, int write, void *arg);
5453

@@ -58,7 +57,8 @@ class NativeStackTrace {
5857
static void cleanup(void *upt, unw_addr_space_t as);
5958

6059
bool is_cached(const uint32_t &key);
61-
void cache_put(const uint32_t &key, const unw_cursor_t cursor, const unw_addr_space_t as, void *upt);
60+
void cache_put(const uint32_t &key, const unw_cursor_t cursor,
61+
const unw_addr_space_t as, void *upt);
6262
static UnwindCacheEntry cache_get(const uint32_t &key);
6363
static bool cache_delete_key(const uint32_t &key);
6464
static void cache_eviction();

examples/cpp/pyperf/PyPerfProfiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
#include <thread>
2828

2929
#include "PyPerfLoggingHelper.h"
30-
#include "PyPerfVersion.h"
31-
#include "PyPerfProc.h"
3230
#include "PyPerfNativeStackTrace.h"
31+
#include "PyPerfProc.h"
32+
#include "PyPerfVersion.h"
3333
#include "bcc_elf.h"
3434
#include "bcc_proc.h"
3535
#include "bcc_syms.h"

0 commit comments

Comments
 (0)