-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1281 from bugsnag/nickdowell/kscrash-write-buffer
[PLAT-7804] Improve crash report writing performance with buffered output
- Loading branch information
Showing
12 changed files
with
241 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// BSG_KSFile.c | ||
// Bugsnag | ||
// | ||
// Created by Nick Dowell on 12/01/2022. | ||
// Copyright © 2022 Bugsnag Inc. All rights reserved. | ||
// | ||
|
||
#include "BSG_KSFile.h" | ||
|
||
#include "BSG_KSFileUtils.h" | ||
|
||
#include <string.h> | ||
#include <sys/param.h> | ||
|
||
static inline bool bsg_write(const int fd, const char *bytes, size_t length) { | ||
return bsg_ksfuwriteBytesToFD(fd, bytes, (ssize_t)length); | ||
} | ||
|
||
void BSG_KSFileInit(BSG_KSFile *file, int fd, char *buffer, size_t length) { | ||
file->fd = fd; | ||
file->buffer = buffer; | ||
file->bufferSize = length; | ||
file->bufferUsed = 0; | ||
} | ||
|
||
bool BSG_KSFileWrite(BSG_KSFile *file, const char *data, size_t length) { | ||
const size_t bytesCopied = MIN(file->bufferSize - file->bufferUsed, length); | ||
memcpy(file->buffer + file->bufferUsed, data, bytesCopied); | ||
file->bufferUsed += bytesCopied; | ||
data += bytesCopied; | ||
length -= bytesCopied; | ||
|
||
if (file->bufferUsed == file->bufferSize) { | ||
if (!BSG_KSFileFlush(file)) { | ||
return false; | ||
} | ||
} | ||
|
||
if (!length) { | ||
return true; | ||
} | ||
|
||
if (length >= file->bufferSize) { | ||
return bsg_write(file->fd, data, length); | ||
} | ||
|
||
memcpy(file->buffer, data, length); | ||
file->bufferUsed = length; | ||
return true; | ||
} | ||
|
||
bool BSG_KSFileFlush(BSG_KSFile *file) { | ||
if (!bsg_write(file->fd, file->buffer, file->bufferUsed)) { | ||
return false; | ||
} | ||
file->bufferUsed = 0; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// BSG_KSFile.h | ||
// Bugsnag | ||
// | ||
// Created by Nick Dowell on 12/01/2022. | ||
// Copyright © 2022 Bugsnag Inc. All rights reserved. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include <stddef.h> | ||
|
||
typedef struct { | ||
int fd; | ||
char *buffer; | ||
size_t bufferSize; | ||
size_t bufferUsed; | ||
} BSG_KSFile; | ||
|
||
void BSG_KSFileInit(BSG_KSFile *file, int fd, char *buffer, size_t length); | ||
|
||
bool BSG_KSFileWrite(BSG_KSFile *file, const char *data, size_t length); | ||
|
||
bool BSG_KSFileFlush(BSG_KSFile *file); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.