mirror of
https://github.com/clearlinux/psstop.git
synced 2026-04-28 10:53:54 +00:00
Clean with Clang Format
Fixing Clang format and valgrind memory leaks: ==1721== definitely lost: 0 bytes in 0 blocks ==1721== indirectly lost: 0 bytes in 0 blocks ==1721== possibly lost: 0 bytes in 0 blocks Signed-off-by: Victor Rodriguez <victor.rodriguez.bahena@intel.com>
This commit is contained in:
85
.clang-format
Normal file
85
.clang-format
Normal file
@@ -0,0 +1,85 @@
|
||||
---
|
||||
AccessModifierOffset: 0
|
||||
AlignAfterOpenBracket: true
|
||||
AlignConsecutiveAssignments: false
|
||||
#uncomment for clang 3.9
|
||||
#AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
# AlwaysBreakAfterDefinitionReturnType: None
|
||||
#uncomment for clang 3.9
|
||||
#AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: false
|
||||
BinPackParameters: true
|
||||
# BraceWrapping: (not set since BreakBeforeBraces is not Custom)
|
||||
BreakBeforeBinaryOperators: None
|
||||
# BreakAfterJavaFieldAnnotations: (not java)
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
#uncomment for clang 3.9
|
||||
#BreakStringLiterals: false
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: '\*\<'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
ForEachMacros: [ NC_LIST_FOREACH ]
|
||||
#Uncomment for clang 3.9
|
||||
#IncludeCategories:
|
||||
# - Regex: '^"'
|
||||
# Priority: 1
|
||||
# IncludeIsMainRegex: (project doesn't use a main includes that can add other includes via regex)
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: false
|
||||
# JavaScriptQuotes: (not javascript)
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
Language: Cpp
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
# ObjCBlockIndentWidth: (not objc)
|
||||
# ObjCSpaceAfterProperty: (not objc)
|
||||
# ObjCSpaceBeforeProtocolList: (not objc)
|
||||
PenaltyBreakBeforeFirstCallParameter: 400
|
||||
PenaltyBreakComment: 0
|
||||
# PenaltyBreakFirstLessLess: (not cpp)
|
||||
PenaltyBreakString: 500
|
||||
PenaltyExcessCharacter: 10000
|
||||
PenaltyReturnTypeOnItsOwnLine: 600
|
||||
PointerAlignment: Right
|
||||
#uncomment for clang 3.9
|
||||
#ReflowComments: true
|
||||
#uncomment for clang 3.9
|
||||
#SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
# SpacesInContainerLiterals: (not objc or javascript)
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
152
src/main.c
152
src/main.c
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Clear Linux Project for Intel Architecture Power tweaks
|
||||
* Clear Linux Project for Intel Architecture Power tweaks
|
||||
*
|
||||
* Copyright (C) 2014 Intel Corporation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 2 or later of the License.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
@@ -21,100 +21,98 @@
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
|
||||
char *searchkey;
|
||||
uint64_t total_PSS;
|
||||
int total_proc;
|
||||
|
||||
struct process {
|
||||
int pid;
|
||||
char *name;
|
||||
uint64_t PSS_kb;
|
||||
int pid;
|
||||
char *name;
|
||||
uint64_t PSS_kb;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void do_one_process(int pid)
|
||||
{
|
||||
FILE *file;
|
||||
char buffer[4096];
|
||||
char filename[4096];
|
||||
struct process process;
|
||||
if (!pid)
|
||||
return;
|
||||
|
||||
memset(&process, 0, sizeof(struct process));
|
||||
|
||||
sprintf(filename, "/proc/%i/comm", pid);
|
||||
file = fopen(filename, "r");
|
||||
if (file) {
|
||||
char *c;
|
||||
buffer[0] = 0;
|
||||
if (fgets(buffer, 4096, file)!=NULL){
|
||||
c = strchr(buffer, '\n');
|
||||
if (c)
|
||||
*c = 0;
|
||||
process.name = strdup(buffer);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
if (process.name && searchkey && strstr(process.name, searchkey) == NULL)
|
||||
return;
|
||||
FILE *file;
|
||||
char buffer[4096];
|
||||
char filename[4096];
|
||||
struct process process;
|
||||
if (!pid)
|
||||
return;
|
||||
|
||||
sprintf(filename, "/proc/%i/smaps", pid);
|
||||
file = fopen(filename, "r");
|
||||
if (file) {
|
||||
while (!feof(file)) {
|
||||
buffer[0] = 0;
|
||||
if (fgets(buffer, 4096, file)!=NULL){
|
||||
if (strlen(buffer) == 0)
|
||||
break;
|
||||
if (strstr(buffer, "Pss:") == NULL)
|
||||
continue;
|
||||
process.PSS_kb += strtoull(buffer+4, NULL, 10);
|
||||
memset(&process, 0, sizeof(struct process));
|
||||
|
||||
sprintf(filename, "/proc/%i/comm", pid);
|
||||
file = fopen(filename, "r");
|
||||
if (file) {
|
||||
char *c;
|
||||
buffer[0] = 0;
|
||||
if (fgets(buffer, 4096, file) != NULL) {
|
||||
c = strchr(buffer, '\n');
|
||||
if (c)
|
||||
*c = 0;
|
||||
process.name = strdup(buffer);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
printf("%" PRIu64 " Kb: %s (%i) \n", process.PSS_kb, process.name, pid);
|
||||
total_PSS += process.PSS_kb;
|
||||
total_proc++;
|
||||
if (process.name && searchkey && strstr(process.name, searchkey) == NULL)
|
||||
return;
|
||||
|
||||
sprintf(filename, "/proc/%i/smaps", pid);
|
||||
file = fopen(filename, "r");
|
||||
if (file) {
|
||||
while (!feof(file)) {
|
||||
buffer[0] = 0;
|
||||
if (fgets(buffer, 4096, file) != NULL) {
|
||||
if (strlen(buffer) == 0)
|
||||
break;
|
||||
if (strstr(buffer, "Pss:") == NULL)
|
||||
continue;
|
||||
process.PSS_kb += strtoull(buffer + 4, NULL, 10);
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
printf("%" PRIu64 " Kb: %s (%i) \n", process.PSS_kb, process.name, pid);
|
||||
total_PSS += process.PSS_kb;
|
||||
total_proc++;
|
||||
free(process.name);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
if (argc > 1) {
|
||||
searchkey = strdup(argv[1]);
|
||||
}
|
||||
|
||||
dir = opendir("/proc");
|
||||
while (dir) {
|
||||
int pid;
|
||||
entry = readdir(dir);
|
||||
if (!entry)
|
||||
break;
|
||||
if (entry->d_name[0] == '.')
|
||||
continue;
|
||||
pid = strtoull(entry->d_name, NULL, 10);
|
||||
do_one_process(pid);
|
||||
}
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
printf("Total is %" PRIu64 "Kb (%i processes)\n", total_PSS, total_proc);
|
||||
closedir(dir);
|
||||
return EXIT_SUCCESS;
|
||||
if (argc > 1) {
|
||||
searchkey = strdup(argv[1]);
|
||||
}
|
||||
|
||||
dir = opendir("/proc");
|
||||
while (dir) {
|
||||
int pid;
|
||||
entry = readdir(dir);
|
||||
if (!entry)
|
||||
break;
|
||||
if (entry->d_name[0] == '.')
|
||||
continue;
|
||||
pid = strtoull(entry->d_name, NULL, 10);
|
||||
do_one_process(pid);
|
||||
}
|
||||
|
||||
printf("Total is %" PRIu64 "Kb (%i processes)\n", total_PSS, total_proc);
|
||||
closedir(dir);
|
||||
free(searchkey);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user